Android Studio 一键迁移
Refactor-->Migrate to AndroidX...
老项目中遇到的报错提示:
1、修改com.android.tools.build:gradle版本
The gradle plugin version in your project build.gradle file needs to be set
to at least com.android.tools.build:gradle:3.2.0
修改build.gradle文件,com.android.tools.build:gradle版本至少是3.2.0或更高。
eg:新项目中使用的版本
classpath "com.android.tools.build:gradle:4.0.1"
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
2、修改 android.enableAapt2=true或注释/删除
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.internal.application']
> The option 'android.enableAapt2' is deprecated.
The current default is 'true'.
It has been removed from the current version of the Android Gradle plugin.
This property has no effect, AAPT2 is now always used.
3、butterknife为support包下的不适用:
Execution failed for task ':app:javaPreCompileDebug'.
> Could not resolve all files for configuration ':app:debugAnnotationProcessorClasspath'.
> Failed to transform butterknife-compiler-8.8.1.jar (com.jakewharton:butterknife-compiler:8.8.1) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: /home/pateo/.gradle/caches/modules-2/files-2.1/com.jakewharton/butterknife-compiler/8.8.1/b2f4505a1babb7b7c11abbbf8ea4c90b18c3aeac/butterknife-compiler-8.8.1.jar.
修改butterknife版本为:
implementation "com.jakewharton:butterknife:10.0.0"
annotationProcessor "com.jakewharton:butterknife-compiler:10.0.0"
4、AndroidManifest.xml 中的minSdkVersion不适用:
The minSdk version should not be declared in the android manifest file. You can move
the version from the manifest to the defaultConfig in the build.gradle file.
删除AndroidManifest.xml 中的minSdkVersion:
5、Lint检查,build.gradle文件,增加如下代码(检查发现错误仍然继续构建):
Execution failed for task ':app:lintVitalRelease'.
> Lint found fatal errors while assembling a release target.
To proceed, either fix the issues identified by lint, or modify your build script as follows:
...
android {
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}
}