0

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

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面板中,我为应用程序和 API 模块选择了调试变体。但是,当我手动按下 play/clean/rebuild/remove all build directory/resync gradle 时,无论我做什么都是每次都会编译的发布 API。

有什么提示吗?

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

4

1 回答 1

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"
于 2016-06-20T12:25:15.570 回答