Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

archiveBaseName applied to all build types

I've the following app 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-"
        }
    }
}

When I execute ./gradlew assembleRelease assembleDebug

The output .apk are:
- anecdote-DEBUGDEBUGDEBUG-debug-unaligned.apk
- anecdote-DEBUGDEBUGDEBUG-debug.apk
- anecdote-DEBUGDEBUGDEBUG-release-unaligned.apk
- anecdote-DEBUGDEBUGDEBUG-release.apk

What I wanted:
- anecdote-DEBUGDEBUGDEBUG-debug-unaligned.apk
- anecdote-DEBUGDEBUGDEBUG-debug.apk
- anecdote-1.0.0-release-unaligned.apk
- anecdote-1.0.0-release.apk

Is there any way to apply the archiveBaseName to a specific build types or is it a bug?

Thanks,

like image 919
Hugo Gresse Avatar asked Jun 28 '16 19:06

Hugo Gresse


1 Answers

As you may notice, this question is a mess around SO.

Related answer here and here.

Here is what worked for me. I wanted to keep the simple archiveBaseName but it seems deprecated and that it apply to all 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'
        }
    }
}
like image 186
Hugo Gresse Avatar answered Oct 10 '22 06:10

Hugo Gresse