最近将新项目导入3.0遇到了各种问题,一片爆红,终于运行起来了!!!现在总结下,以便记录:
1.首先修改 gradle 版本号:我的是 4.1 对应的项目中 build.gradle 中gradle为3.0.0
2.Error:Failed to find Build Tools revision 26.0.3
这时你可以根据提示下载对应的版本,你也可以将项目中所依赖的
com.android.support: V7 或者 V4 design 等统一成一个版本,我统一成了28.0.0
记得修改 compileSdkVersion 以及 targetSdkVersion
有人会问 你怎么没有 buildToolsVersion呢 因为不需要了 删了就可以了! 重新编译!
3.修改project的build.gradle 添加 google()
4. apt插件问题 android-apt plugin is incompatible with the Android Gradle plugin.Please use 'annotationProcessor'
解决方法:
(1).在project的build.gradle中删除
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath 'me.tatarka:gradle-retrolambda:3.2.1'
(2).在module的build.gradle中删除
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
(3).将module的build.gradle文件中的dependency
apt 'com.jakewharton:butterknife-compiler:8.0.1'
改为
annotationProcessor 'com.jakewharton:butterknife-compiler:8.0.1'
其他使用apt的依赖,也要这样更改
5. Error:Cannot choose between the following configurations of project :library
解决方法:
在module 的 build.gradle ——> dependencies 中,添加依赖
compile 要用 implementation 或 api 替换
testCompile 要用 testImplementation 或 testApi 替换
androidTestCompile 要用 androidTestImplementation 或 androidTestApi 替换
但是这儿要注意了,区分implementation 和 api 的区别 避免导致主工程引用不到依赖工程的的依赖包:
1. api是complie的替代品,他俩是没有区别。implementation代替 compile,所依赖的只能在本module中使用!implementation 会使AS编译速度更快
2. implementation声明的依赖包只限于模块内部使用,不允许其他模块使用。
api声明的依赖包时, 此模块使用api声明的依赖包是可以被其他模块使用
3.如果主工程引用依赖工程的的依赖包,一定要将 implementation 修改成 api!!
6.Warning:The `android.dexOptions.incremental` property is deprecated and it has no effect on the build process.
android.dexOptions.incremental
属性已被弃用,它对构建过程没有影响。
解决方法:
将module 的 build.gradle 中 dexOptions删掉!
/*dexOptions {
incremental true
javaMaxHeapSize "4g"
}*/
7.Error:All flavors must now belong to a named flavor dimension.
解决方法:
在 module 的 build.gradle 中 defaultConfig 添加一句话
flavorDimensions "versionCode对应值"
defaultConfig {
applicationId "cn.jstyle.app"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0.1"
//版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了
flavorDimensions "1"
}
8.多渠道打包导致的:Error:Unable to resolve dependency for ':voxryJstyle1@meizuSigningConfigs/compileClasspath': Could not resolve project :library.
解决方法:
(1)将signingConfigs{...}从buildTypes{...}提出放在android {}下
(2)将productFlavors{...}和productFlavors.all{...}从defaultConfig{...}提出放在android {}下;如下:
完整代码如下:
android {
compileSdkVersion 28
defaultConfig {
applicationId "cn.demo.app"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0.1"
//版本名后面添加一句话,意思就是flavor dimension 它的维度就是该版本号,这样维度就是都是统一的了
flavorDimensions "1"
}
//多渠道打包
productFlavors {
lenovo {}
leshi {}
meizu {}
oppo {}
}
productFlavors.all {
flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name]
}
//签名配置
signingConfigs {
debug {
storeFile file('1.keystore')
storePassword "XXX"
keyAlias "XXX"
keyPassword "XXX"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
9.最小minSdkVersion问题:
Error:Execution failed for task ':processDebugAndroidTestManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 9 cannot be smaller than version 14 declared in library
解决方法:
在API28下,支持最小SDK版本号是14,而我依赖的module中最小是9,最好是依赖的module 和主module一样;我的都是15,我就把这个改为了15;
10.解决关于com.android.support:support的依赖冲突问题
解决方法:
方法一:将项目中所依赖的V7 或者 V4 包统一成一个,我统一成了28.0.0
方法二:
在app下build.gradle里加上
configurations.all {
resolutionStrategy.force 'com.android.support:support-v7:28.0.0'
}
11.禁用AAPT2: Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exceptiom:AAPT2 error:check logs for details
解决方法
方法一:只需在工程的gradle.properties文件最后一行添加:
android.enableAapt2=false
方法二:在电脑中找gradle.properties.ftl文件,此文件在AS的安装目录下
编辑这个文件,在最后添加 android.enableAapt2=false
这个方法对应所有的项目!