Android Studio 中修改Apk名稱(新增Android studio 3.*設置)


修改生成的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 新功能解析和舊項目適配

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM