前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android Gradle 2.3.3 升级 3.0.1 小记录

Android Gradle 2.3.3 升级 3.0.1 小记录

作者头像
阿策小和尚
发布2019-12-30 15:19:37
5660
发布2019-12-30 15:19:37
举报
文章被收录于专栏:阿策小和尚阿策小和尚

和尚因为种种原因需要升级 Android GradleGradle > 3.0 时默认支持 Java 8;每次大版本升级都会涉及很多内容,和尚尽可能慎重,但还是简单记录一下升级过程中遇到的问题;

升级 classpath 'com.android.tools.build:gradle:3.0.1'

和尚从 2.3.3 升级到 3.0.1 同步之后会有很多问题;

Q1:
代码语言:javascript
复制
Unable to resolve dependency for ':testsdk@debug/compileClasspath': Could not resolve project :testlibrary.

Unable to resolve dependency for ':testsdk@debugAndroidTest/compileClasspath': Could not resolve project :testlibrary.

...
A1:

Gradle 3.0.0 以后不能用 debugCompile project / debugCompile project 方式替换为 implementation project 即可;

代码语言:javascript
复制
debugCompile project(path: ':testlibrary', configuration: 'debug')
releaseCompile project(path: ':testlibrary', configuration: 'release')

替换为
implementation project(':testlibrary')
Q2:
代码语言:javascript
复制
All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
A3:

所有类型都必须属于一个指定的类型维度,即一个产品特性组。必须将所有类型分配给类型维度;在需要修改的 Module.build 添加 flavorDimensions "versionCode" 即可;

代码语言:javascript
复制
defaultConfig {
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    flavorDimensions "versionCode"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

目前同步完之后没有异常,但是 debug 运行又会有新的问题;

Q3:
代码语言:javascript
复制
Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
A3:

和尚在项目中应用到 ButterKnife,需要添加注解处理器,使用 annotationProcessor 配置依赖项;

代码语言:javascript
复制
compile "com.jakewharton:butterknife:7.0.1"

替换为
implementation "com.jakewharton:butterknife:7.0.1"
annotationProcessor "com.jakewharton:butterknife:7.0.1"
Q4:
代码语言:javascript
复制
Execution failed for task ':test:javaPreCompileDebug'.
> Annotation processors must be explicitly declared now.  The following dependencies on the compile classpath are found to contain annotation processor.  Please add them to the annotationProcessor configuration.
    - compiler-1.1.0.jar (android.arch.lifecycle:compiler:1.1.0)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.  Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.
A4:

和尚在项目中使用了 Lifecycle,需要添加 Lifecycle 依赖项,删除以前 compile lifecycle 方式,将 Google Maven 代码库添加到项目中即可;和尚未使用 AndroidX 可以按需要自定义添加;

代码语言:javascript
复制
def lifecycle_version = "1.1.1"
// 包含ViewModel和LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
// 仅仅包含ViewModel
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
// 仅仅包含LiveData
implementation "android.arch.lifecycle:livedata:$lifecycle_version"
// 仅仅包含Lifecycles
implementation "android.arch.lifecycle:runtime:$lifecycle_version"

annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version" // For Kotlin use kapt instead of annotationProcessor
// 如果用Java8, 用于替代compiler
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
// 可选,ReactiveStreams对LiveData的支持
implementation "android.arch.lifecycle:reactivestreams:$lifecycle_version"
// 可选,LiveData的测试
testImplementation "android.arch.core:core-testing:$lifecycle_version"
Q5:

和尚目前运行打包都正常,但是同样的代码在其他开发同事上运行异常;

代码语言:javascript
复制
Type def recipe not found: /Users/gitspace/SogouNovel/commonlib/build/intermediates/typedefs.txt
A5:

和尚尝试之后发现,升级到 Gradle 3.0 之后,lamba 的版本也需要更新,将 lamba 的版本更新到 3.7.0 即可;

代码语言:javascript
复制
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'
    classpath 'com.sogou.compress:compress-plugin:1.0.1'
    classpath 'me.tatarka:gradle-retrolambda:3.7.0' //retrolambda
}
Tips:

和尚建议在升级过程中注意混淆文件的处理,尤其是借助三方 SDK 时,注意官网混淆文件的添加;


至此,和尚在升级过程中遇到的小问题基本解决,大部分都可以在官网或参考各路大神的博客,但和尚还是记录尝试一下,对以后遇到的问题进行扩展整理;如有问题,请多多指导!

来源: 阿策小和尚

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-12-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 阿策小和尚 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 升级 classpath 'com.android.tools.build:gradle:3.0.1'
    • Q1:
      • A1:
        • Q2:
          • A3:
            • Q3:
              • A3:
                • Q4:
                  • A4:
                    • Q5:
                      • A5:
                        • Tips:
                        领券
                        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档