Android Studio多渠道打包问题汇总(持续更新中)
0X01、Error:Removing unused resources requires unused code shrinking to be turned on.
修改build.gradle文件中buildTypes的:
minifyEnabled值为true
debuggable值为 true
buildTypes {
debug {
signingConfig signingConfigs.release
buildConfigField "boolean", "ISDEBUG", "true"
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
signingConfig signingConfigs.release
minifyEnabled true
zipAlignEnabled true
debuggable true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
0X02、WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getPackageApplication(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
修改build.gradle文件中buildTypes的:
//输出的为渠道包的名字,例如 xiaomi.apk
applicationVariants.all { variant ->
variant.outputs.each { output ->
def outFile = output.outputFile
if (outFile != null && outFile.name.endsWith(".apk")) {
def fileName = "${variant.productFlavors[0].name}" + ".apk"
output.outputFile = new File(outFile.parent, fileName)
}
}
}
修改后:
//输出的为渠道包的名字,例如 xiaomi.apk
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName="${variant.productFlavors[0].name}_${variant.versionCode}
-${variant.versionName}-${releaseTime()}.apk"
}
}
0X03、GC overhead limit exceeded
修改项目目录下的gradle.properties
org.gradle.jvmargs=-Xmx1024m