Android Studio3.0打包速度大幅提升,但升级之后还需要解决一些配置问题和报错。
使用方法:
build.gradle修改为3.0.0
在gradle->wrapper->gradle-wrapper.properties:中修改
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
关于一些报错:打开已经存在的项目报错:
Gradle sync failed: Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=richinfoDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
Consult IDE log for more details (Help | Show Log) (2s 329ms)
outputFile不允许再赋予可变值了,估计是跟增量编译有关。
修改为固定即可,打包速度确实提升非常明显
android.applicationVariants.all { variant->
variant.outputs.all {
outputFileName ="${variant.name}-${variant.versionName}.apk"
}
}
另外一个报错:
Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com/r/tools/flavorDimensions-missing-error-message.html
Android 3.0需要强制指定Flaovers,如果对你来说没有什么必要性可以直接添加:
android {
.......
flavorDimensions "default"
.....
}
网友评论
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
android {
buildTypes {
// ...
}
android.applicationVariants.all { variant ->
variant.outputs.all { output ->
def outputFile = output.outputFile
if (outputFile != null && outputFile.name.endsWith('.apk')) {
def fileName = outputFile.name.replace("app",
"${defaultConfig.applicationId}_${defaultConfig.versionName}_${releaseTime()}")
outputFileName = fileName
}
}
}
}