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

本文介绍了如何在Android Studio中修改生成的APK文件名,并确保调试版本也能使用自定义名称。针对不同版本的IDE提供了两种不同的实现方式。

修改生成的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 新功能解析和旧项目适配

 

转载于:https://www.cnblogs.com/Alvinyk/p/7641705.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值