android - 应用于所有构建类型的 archiveBaseName

标签 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-"
        }
    }
}

当我执行./gradlew assembleRelease assembleDebug

输出的 .apk 是:
- 轶事-DEBUGDEBUGDEBUG-debug-unaligned.apk
- 轶事-DEBUGDEBUGDEBUG-debug.apk
- 轶事-DEBUGDEBUGDEBUG-release-unaligned.apk
- 轶事-DEBUGDEBUGDEBUG-release.apk

我想要的:
- 轶事-DEBUGDEBUGDEBUG-debug-unaligned.apk
- 轶事-DEBUGDEBUGDEBUG-debug.apk
- anecdote-1.0.0-release-unaligned.apk
- anecdote-1.0.0-release.apk

有什么方法可以将 archiveBaseName 应用到特定的构建类型 还是一个错误?

谢谢,

最佳答案

您可能会注意到,这个问题围绕着 SO 一团糟。

相关回答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'
        }
    }
}

关于android - 应用于所有构建类型的 archiveBaseName,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38084675/

相关文章:

java - RecyclerView 滚动时扩展项目之间的空间

Android studio - 如何使用 gradle 中的可执行 jar 文件

rest - 在另一个 build.gradle 项目中执行测试

android - 如何在我的 gradle 项目中添加 JAR?

android-studio - 如何在 Gradle 中添加 Android Studio 插件作为依赖项?

java - 使用最新的 BaseGameUtils 的 Google Play 游戏服务 LibGDX 项目设置

java - 在 GraphView 中的图形和刻度标签之间添加空格?

ImageButton "onClick"未调用

java - gradle 在 android studio 中实际是如何工作的?

android - 使用 "resValue"本地化通过 build.gradle 添加的字符串资源