作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在Android Studio中进行有条件的构建,可以在其中通过删除多余的库依赖项(如果特定发行版不需要它们)来减少生成的APK的大小。
我有一些代码大致类似于以下内容:
public class MyClass {
/* Static Declarations. */
public static final boolean USE_LIBRARY = false;
public void doSomething() {
// Are we using the library?
if(MyClass.USE_LIBRARY) {
// Do something with the library that we'd define in my build.gradle.
com.some.gradle.library.MyLibrary.doSomethingWithLibrary();
}
else {
// Do something else.
}
}
}
com.some.gradle.library
,则会收到指示无法编译以上代码的编译错误。如您所见,只要
USE_LIBRARY
保持为false,我们就永远不需要做任何引用
MyLibrary
;甚至在实例化时也没有,因为它没有引用导入;这些仅在运行时被侵犯。
USE_LIBRARY
是与应用程序的
BuildConfig.java
相关的以编程方式生成的常量。
最佳答案
I'm trying to make a conditional build in Android Studio, where I can reduce the size of the generated APK by removing any superfluous library dependencies if they're not needed for a particular distribution.
foo
。您还需要其他发行版本的其他产品口味。
compile
语句更改为
fooCompile
语句,因此它将仅用于
foo
构建。
MyClass
版本(例如
src/foo/java/
),其中
foo
中的一个引用库,而其他版本则不。
关于android - 如何在Android中有条件地编译JAR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43853097/
我是一名优秀的程序员,十分优秀!