archiveBaseName应用于所有构建类型

时间:2016-06-28 19:25:22

标签: android gradle android-gradle

我有以下应用build.gradle

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "io.gresse.hugo.anecdote"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 12
        versionName "1.0.0"
    }

    buildTypes {
        release {
            archivesBaseName = "anecdote-" + defaultConfig.versionName
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

        }
        debug {
            archivesBaseName = "anecdote-DEBUGDEBUGDEBUG-"
        }
    }
}

执行./gradlew assembleRelease assembleDebug

输出.apk是:
  - anecdote-DEBUGDEBUGDEBUG-debug-unaligned.apk
  - anecdote-DEBUGDEBUGDEBUG-debug.apk
  - anecdote-DEBUGDEBUGDEBUG-release-unaligned.apk
  - anecdote-DEBUGDEBUGDEBUG-release.apk

我想要的是什么:
  - anecdote-DEBUGDEBUGDEBUG-debug-unaligned.apk
  - anecdote-DEBUGDEBUGDEBUG-debug.apk
  - anecdote-1.0.0-release-unaligned.apk
  - anecdote-1.0.0-release.apk

有没有办法将 archiveBaseName 应用于特定的构建类型,还是一个错误?

谢谢,

1 个答案:

答案 0 :(得分:2)

正如您可能已经注意到的那样,这个问题很糟糕。

相关回答herehere

这对我有用。我想保留简单的archiveBaseName,但它似乎已被弃用,并且它适用于所有buildTypes。

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "io.gresse.hugo.anecdote"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 12
        versionName "1.0.0"
    }

    project.ext.set("archivesBaseName", "Anecdote");

    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            if(variant.buildType.name == "release"){
                output.outputFile = new File(
                        output.outputFile.parent,
                        output.outputFile.name.replace(".apk", "-"+variant.versionName + ".apk"))
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}