android gradle 2.2.3 升级 到 3.2.0
1. 首先检查 build.gradle 有没有 引用
报错
One of the plugins you are using supports Java 8 language features. To try the support built into the Android plugin, remove the following from your build.gradle:
apply plugin: 'me.tatarka.retrolambda'
To learn more, go to https://d.android.com/r/tools/java-8-support-message.html
classpath 'me.tatarka:gradle-retrolambda:3.2.5' gradle 2.0 不支持 lambda 表达式 3.0 支持 需要把它删除就好了
报错
Could not get unknown property 'apkVariantData' for object of type com.android.build.gradle.internal.api.ApplicationVariantImpl.
gradle插件3.0.0版本 升级了gradle的api,导致有些api不能用。恰好AndResGuard 1.2.3版本插件用到了这个过期的api 需要升级到最新 的,最新的是支持的
classpath 'com.tencent.mm:AndResGuard-gradle-plugin:1.2.16' 资源混淆 用最新的 之前不支持3.0 现在支持
2.修改 app build.gradle
compile 改成implementation
androidTestCompile改成androidTestImplementation
testCompile 改成testImplementation
implementation:该依赖方式所依赖的库不会传递,只会在当前module中生效。
api:该依赖方式会传递所依赖的库,当其他module依赖了该module时,可以使用该module下使用api依赖的库。
[api 指令] 完全等同于compile指令,没区别,你将所有的compile改成api,完全没有错。
[implementation指令] 这个指令的特点就是,对于使用了该命令编译的依赖,对该项目有依赖的项目将无法访问到使用该命令编译的依赖中的任何程序,也就是将该依赖隐藏在内部,而不对外部公开。简单的说,就是使用implementation指令的依赖不会传递。
报错
Error: java.lang.RuntimeException: java.lang.RuntimeException:
Error while processing D:\work2019.05.10\totalqualitymanagementwork\app\src\main\res\drawable\ic_vector_check.xml :
Can't process attribute android:fillColor="@color/ip_color_accent": references to other resources are not supported by build-time PNG generation.
See http://developer.android.com/tools/help/vector-asset-studio.html for details.
在你的app的build.gradle的defaultConfig中添加如下的代码就可以了:
defaultConfig{
vectorDrawables.useSupportLibrary = true
}
2.打包需要修改
def releaseTime() {
return new Date().format("yyyy.MM.dd", TimeZone.getTimeZone("UTC"))
}
applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile=output.outputFile
if(outputFile!=null && outputFile.name.endsWith('.apk')) {
def fileName
if(variant.buildType.name=="release"){
fileName = "APP_NAME v${defaultConfig.versionName}-${releaseTime()}.apk"
}else {
fileName = "APP_NAME v${variant.versionName}_debug.apk"
}
outputFileName = fileName
}
}
}
在Module的build.gradle的android领域中使用如下代码
3.0以前
applicationVariants.all{ variant ->
variant.outputs.each{ output ->
def outputFile=output.outputFile
if(outputFile!=null && outputFile.name.endsWith('.apk')) {
def fileName="APP_NAME v${defaultConfig.versionName}-${releaseTime()}.apk"
output.outputFile=new File(outputFile.parent,fileName)
}
}
}
3.
运行时报错
InvocationTargetException 反射异常。
解决完 运行 就没问题了 。