应用于所有构建类型的 archiveBaseName

Hug*_*sse 5 android gradle android-gradle-plugin

我有以下应用程序 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-"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我执行 ./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应用于特定的构建类型还是一个错误?

谢谢,

Hug*_*sse 4

正如您可能注意到的,这个问题很混乱。

相关答案在这里这里

这对我有用。我想保持简单archiveBaseName,但它似乎已被弃用,并且它适用于所有构建类型。

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'
        }
    }
}
Run Code Online (Sandbox Code Playgroud)