且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android:加载库并将其仅用于开发分支而不用于发行

更新时间:2021-10-30 23:42:44

因此,对于Debug来说,它工作正常,但是当我构建Store-Release/Development-Release apk时,由于我正在使用该库,因此无法编译ApplicationWithDebugLibrary.java,因为该库未在gradle文件中进行编译以实现发行版本

So for Debug it is working fine but when I am building Store-Release/ Development-Release apk it is not able to compile ApplicationWithDebugLibrary.java, as I am using the library, which is not compiled in gradle file for release flavour

根据逻辑,没有办法神奇地删除代码使用的库,而且由于缺少符号,因此仍然可以正确编译所有剩余库.因此,您必须创建虚拟"库,该库具有与调试库相同的API,但没有方法主体.另外,您可以用一些代码包装lib,这些代码以后可以交换为生产版本,而该版本不使用任何库依赖项.

By logic there's no way to magically remove library your code uses and still have all remainings properly compile as there're simply missing symbols. So you must create "dummy" library, with the same API as your debug one but with no methods body. Alternatively you can wrap your lib with some code that can be later swapped for production with version that uses no library dependencies.

Android Gradle插件可以根据构建的类型来帮助构建具有不同版本的依赖项:

Android Gradle plugin can help building with different version of dependencies based of what type of build it is:

编译配置用于编译主应用程序. 其中的所有内容都会添加到编译类路径中 打包在最终的APK中.还有其他可能的配置 将依赖项添加到:

The compile configuration is used to compile the main application. Everything in it is added to the compilation classpath and also packaged in the final APK. There are other possible configurations to add dependencies to:

  • 编译:主要应用程序
  • androidTestCompile:测试应用程序
  • debugCompile:调试构建类型
  • releaseCompile:发布构建类型.
  • compile: main application
  • androidTestCompile: test application
  • debugCompile: debug Build Type
  • releaseCompile: release Build Type.

docs: http://tools.android.com/tech-docs/new-build-system/用户指南#TOC-Dependencies-Android-Libraries-and-Multi-project-setup