【问题标题】:Gradle - how to specify different Android *.apk build location for each flavor?Gradle - 如何为每种风味指定不同的 Android *.apk 构建位置?
【发布时间】:2014-04-24 21:01:49
【问题描述】:

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

我正在使用 Android Studio。

【问题讨论】:

    标签: android build gradle


    【解决方案1】:

    这对我有用:

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

    但是“clean”任务不会删除那个apk,所以你应该像下面这样扩展clean任务:

    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)
    

    【讨论】:

    • 谢谢,我明天去看看。如果可行,我会接受您的回复:)
    猜你喜欢
    • 1970-01-01
    • 2018-01-22
    • 1970-01-01
    • 2017-10-19
    • 2018-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多