android studio 3.0 修改release生成的apk名称

在网上找了很久,都无法使用,都报错;然后使用bing搜索结果,pass掉几个之后在一个博客上找到了对应的解决方案,经过测试还真行了,下面分享一下使用方法:

在android studio 3.0 的 Gradle Script 中打开 Module:app的 build.gradle,找到android 节点中的buildType节点,在buildType节点下添加代码。

 

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.xxx.android.xxx"
        minSdkVersion 22
        targetSdkVersion 25
//        versionCode 1
//        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    //自动生成指定名称的release发布版的 apk文件
    android.applicationVariants.all { variant ->
        def appName
        if (project.hasProperty("applicationName")){
            appName = applicationName
        }else{
            appName = parent.name
        }
        variant.outputs.all { output ->
            outputFileName = "你的release版apk的名称.apk"
        }
    }
}

为了让遇到困难的人看清,我把整个android节点的代码都贴上来了。

再修改下,喝水不忘挖井人。国外此解决方案的博客连接:https://medium.com/@AndreSand/android-studio-3-0-fix-apk-naming-issue-when-updating-to-gradle-4-0-639da9d863cd

 

 

广告:开发技术交流群:88390778

.NET技术交流与招聘

posted @ 2017-12-26 09:33  异次元代码  阅读(2271)  评论(0编辑  收藏  举报