如何根据buildtype更改apk的后缀

时间:2016-03-16 09:00:25

标签: android gradle android-gradle filenames android-build-type

我想在build gradle中更改.apk文件的生成名称。根据我选择的构建类型。它会自动附加" -release"或" -debug"。 我怎么能改变这个?

构建gradle文件

android {
signingConfigs {
    testapp {
        storeFile file("itsASecret")
        storePassword "itsASecret"
        keyAlias "itsASecret"
        keyPassword "itsASecret"
    }
}

compileSdkVersion 22
buildToolsVersion "22.0.1"

def versionPropertiesFile = file('version.properties')
if (versionPropertiesFile.canRead()) {
    def Properties versionProps = new Properties()
    versionProps.load(new FileInputStream(versionPropertiesFile))
    def code = versionProps['VERSION_CODE'].toInteger() + 1
    versionProps['VERSION_CODE'] = code.toString()
    versionProps.store(versionPropertiesFile.newWriter(), null)

    defaultConfig
            {
                applicationId "com.testapp.app"
                minSdkVersion 19
                targetSdkVersion 22
                versionCode code
                versionName "1.02.00"
                multiDexEnabled true
                setProperty("archivesBaseName", "TestApp_" + "$versionName" + "_" + "$versionCode")
            }

} else {
    throw new GradleException("Could not read version.properties!")
}

buildTypes
        {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                signingConfig signingConfigs.testapp 
            }
            debug {
                debuggable true
                signingConfig signingConfigs.testapp 
            }
        }

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
}

defaultConfig {
    signingConfig signingConfigs.railway
}

}

我试过像

这样的东西
applicationIdSuffix "_DEBUGTEST"

versionNameSuffix "_DEBUGTEST"

文件名:

TestApp_1.02.00_458-release.apk

TestApp_1.02.00_458-debug.apk

但这不起作用: - (

修改

我有一个带有另一个构建gradle的公共库:

apply plugin: 'com.android.library'

android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    }
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'de.greenrobot:greendao:1.3.7'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.commons:commons-lang3:3.3.2'
compile 'commons-codec:commons-codec:1.10'
compile 'de.mindpipe.android:android-logging-log4j:1.0.3'
compile 'log4j:log4j:1.2.16'
compile 'org.slf4j:slf4j-api:1.6.4'
compile 'org.slf4j:slf4j-log4j12:1.6.4'
compile 'com.google.android.gms:play-services-maps:8.3.0'
compile 'com.google.android.gms:play-services-location:8.3.0'
compile 'commons-net:commons-net:3.3'
compile 'net.lingala.zip4j:zip4j:1.3.2'
compile 'com.jjoe64:graphview:4.0.1'
}

0 个答案:

没有答案