在我的库中,我希望能够使用这样的结构。
if (BuildConfig.SOME_FLAG) {
callToBigLibraries()
}
由于SOME_FLAG的最终值,proguard可以减小生成的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.
我曾尝试使用BuildTypes等相关功能,但没有成功。
release {
// packageNameSuffix "library"
buildConfigField "boolean", "SOME_FLAG", "true"
}
debug {
//packageNameSuffix "library"
buildConfigField "boolean", "SOME_FLAG", "true"
}
如何构建一个共享的BuildConfig,让我的库和应用程序可以在编译时覆盖其标志?
BuildConfig
是否保证在该包中? - VladBuildConfig
的输出位置——然而根据我的经验,这对于默认设置是有保证的。 - Philcontext.getPackageName()
将返回带有该后缀的包名,但是BuildConfig仍然会部署在没有后缀的包名上。因此,当该方法寻找com.example.app.suffix.BuildConfig
类时,实际上需要寻找的是com.example.app.BuildConfig
类。对此有什么想法吗? - Tito Leiva