Android Gradle 2.3.3 upgrade 3.0.1 small record

For various reasons, Android Gradle needs to be upgraded. When gradle > 3.0, Java 8 is supported by default. Each large version upgrade involves a lot of content, so you should be as careful as possible, but you should simply record the problems encountered in the upgrade process;

Upgrade classpath 'com.android.tools.build:gradle:3.0.1'

After upgrading from 2.3.3 to 3.0.1, there will be many problems;

Q1:

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:

After Gradle 3.0.0, it can't be replaced with implementation project by debugCompile project / debugCompile project;

debugCompile project(path: ':testlibrary', configuration: 'debug')
releaseCompile project(path: ':testlibrary', configuration: 'release')

//Replace with
implementation project(':testlibrary')

Q2:

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:

All types must belong to a specified type dimension, that is, a product feature group. All types must be assigned to type dimensions; add flavorDimensions "versionCode" to the Module.build to be modified;

defaultConfig {
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode 1
    versionName "1.0"
    flavorDimensions "versionCode"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

At present, there is no exception after synchronization, but there will be new problems in debug running;

Q3:

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:

When applying the "small dish" to ButterKnife in the project, you need to add annotation processor and use annotation processor to configure dependencies;

compile "com.jakewharton:butterknife:7.0.1"

//Replace with
implementation "com.jakewharton:butterknife:7.0.1"
annotationProcessor "com.jakewharton:butterknife:7.0.1"

Q4:

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:

If you use Lifecycle in a project, you need to add Lifecycle dependencies, delete the previous compile lifecycle method, and add Google Maven code base to the project; if you don't use Android x, you can add it as needed;


def lifecycle_version = "1.1.1"
// Contains ViewModel and LiveData
implementation "android.arch.lifecycle:extensions:$lifecycle_version"
// ViewModel only
implementation "android.arch.lifecycle:viewmodel:$lifecycle_version"
// LiveData only
implementation "android.arch.lifecycle:livedata:$lifecycle_version"
// Lifecycle only
implementation "android.arch.lifecycle:runtime:$lifecycle_version"

annotationProcessor "android.arch.lifecycle:compiler:$lifecycle_version" // For Kotlin use kapt instead of annotationProcessor
// If Java 8 is used instead of compiler
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
// Optional, ReactiveStreams support for LiveData
implementation "android.arch.lifecycle:reactivestreams:$lifecycle_version"
// Optional, LiveData test
testImplementation "android.arch.core:core-testing:$lifecycle_version"

Q5:

At present, the running and packing of the small dishes are normal, but the same code runs abnormally on other development colleagues;

Type def recipe not found: /Users/gitspace/SogouNovel/commonlib/build/intermediates/typedefs.txt

A5:

After the trial, we found that after upgrading to Gradle 3.0, the version of lamba also needs to be updated, just update the version of lamba to 3.7.0;

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:

It is recommended to pay attention to the processing of obfuscated files during the upgrade process, especially the addition of obfuscated files on the official website with the help of the three-party SDK;

So far, the small problems encountered in the process of small dish upgrading have been basically solved. Most of them can be found on the official website or refer to the blogs of all kinds of gods, but it's better to record and try to expand and sort out the problems encountered in the future. If there are any problems, please give more guidance!

Source: little monk aze

Tags: Android Gradle ButterKnife Java

Posted on Sun, 15 Dec 2019 06:36:48 -0500 by Kinneh