错误的构建变体

时间:2016-06-10 09:46:25

标签: android android-studio android-gradle android-studio-2.2

我的应用程序中有2个模块,一个用于API,一个用于应用程序。 在API模块中,我定义了2个API端点,具体取决于API是以debug还是release模式编译的:

buildTypes {
    all {
        buildConfigField "String", "API_DEVICE_TYPE", "\"android-phone\""
    }

    debug {
        buildConfigField "String", "API_ENDPOINT", "\"https://beta-api.company.com/\""
    }

    release {
        buildConfigField "String", "API_ENDPOINT", "\"https://api.company.com/\""
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

在Android Studio的Build variant面板中,我为app和API模块选择了调试版本。但是当我按下play / clean / rebuild / remove hand / resync gradle删除所有构建目录时,无论我做什么,这都是每次都编译的发布API。

任何提示?

尝试使用gradle构建工具2.1.02.2.0-aplha3

1 个答案:

答案 0 :(得分:1)

只需在子模块build.gradle

中添加此代码即可
// There is a limitation in gradle: You can't pick what submodule of app you want to compile your app with.
// This attribut define which build variant you want your api to be compiled against.
// https://sites.google.com/a/android.com/tools/tech-docs/new-build-system/user-guide#TOC-Library-Publication
defaultPublishConfig "debug"