相关疑难解决方法(0)

Gradle:如何在android-library中使用BuildConfig,并在应用程序中设置一个标志

我的(gradle 1.10和gradle插件0.8)基于android的项目包含一个大的android-library,它是3个不同的android-app的依赖

在我的图书馆,我希望能够使用这样的结构

if (BuildConfig.SOME_FLAG) {
    callToBigLibraries()
}
Run Code Online (Sandbox Code Playgroud)

因为proguard可以根据SOME_FLAG的最终值减小生成的apk的大小

但我无法想象如何用gradle做到:

* the BuildConfig produced by the library doesn't have the same package name than the app
* I have to import the BuildConfig with the library package in the library
* The apk of an apps includes the BuildConfig with the package of the app but not the one with the package of the library.
Run Code Online (Sandbox Code Playgroud)

我尝试使用BuildTypes和类似的东西没有成功

release {
    // packageNameSuffix "library"
    buildConfigField "boolean", "SOME_FLAG", "true"
}
debug {
    //packageNameSuffix "library" …
Run Code Online (Sandbox Code Playgroud)

buildconfig android-gradle-plugin

54
推荐指数
5
解决办法
4万
查看次数

标签 统计

android-gradle-plugin ×1

buildconfig ×1