Gradle - 如何为每种口味指定不同的Android * .apk构建位置?

时间:2014-04-24 21:01:50

标签: android build gradle

有没有办法指定除../build/apk/之外的Android * .apk文件构建位置?是否可以为每种口味指定不同的位置?

我正在使用Android Studio。

1 个答案:

答案 0 :(得分:0)

这对我有用:

android.applicationVariants.all { variant ->
    def outputName = // filename
    variant.outputFile = file(path_to_filename)
}

但"清洁"任务不会删除该apk,因此您应该扩展干净任务,如下所示:

task cleanExtra(type: Delete) {
    delete outputPathName
}

clean.dependsOn(cleanExtra)

完整样本:

apply plugin: 'android'

def outputPathName = "D:\\some.apk"

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    applicationVariants.all { variant ->
        variant.outputFile = file(outputPathName)
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

task cleanExtra(type: Delete) {
    delete outputPathName
}

clean.dependsOn(cleanExtra)