修改生成的apk名稱,並且使調試時也可以使用。
在app->build.gradle 中增加以下內容:
android.applicationVariants.all { variant->
variant.outputs.each { output->
def oldFile = output.outputFile
if(variant.buildType.name.equals('release')){
def releaseApkName = "alvin"+defaultConfig.versionName+"-release-"+defaultConfig.versionCode+".apk"
output.outputFile = new File(oldFile.parent,releaseApkName)
}
}
}
修改Android studio 升級到3.*
使用上面的設置在 3.0 以下的IDE中沒有問題,當IDE升級到3.0 以上時,編輯工程會報
Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=release, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.
這是因為3.0以上修改了部分編譯配置API。
現在使用一下的方式即可:
1 android.applicationVariants.all { variant -> 2 variant.outputs.all { 3 outputFileName = rootProject.getName() +"-v"+defaultConfig.versionName +"-"+defaultConfig.versionCode +".apk" 4 } 5 }
3.0的更多信息參考:Android Studio 3.0 新功能解析和舊項目適配