简体   繁体   English

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

[英]Gradle - how to specify different Android *.apk build location for each flavor?

Is there a way to specify Android *.apk files build location other than ../build/apk/ ? 是否可以指定../build/apk/以外的Android * .apk文件的生成位置? Is it possible to specify different location for each flavour? 是否可以为每种口味指定不同的位置?

I am using Android Studio. 我正在使用Android Studio。

thats work for me: 多数民众赞成在我的工作:

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

but "clean" task will not drop that apk, so you should extend clean task as below: 但是“清理”任务不会删除该apk,因此您应该按以下方式扩展清理任务:

task cleanExtra(type: Delete) {
    delete outputPathName
}

clean.dependsOn(cleanExtra)

full sample: 完整样本:

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM