【发布时间】:2019-07-09 06:55:14
【问题描述】:
我有两个罐子,left.jar 和 right.jar。它们相似但不相同。
left.jar:
package com.mydomain.config
public class PkgConfig {
public static int getID() {
throw new RuntimeException();
}
public static String getLeftValue() {
throw new RuntimeException();
}
// the rest of the methods are the same with right.jar
}
right.jar:
package com.mydomain.config
public class PkgConfig {
public static int getID() {
throw new RuntimeException();
}
public static String getRightValue() {
throw new RuntimeException();
}
// the rest of the methods are the same with left.jar
}
在我的活动中,我这样做:
public void myMethod() {
if(com.mydomain.config.PkgConfig.getID() > 1000) {
mDeviceValue = com.mydomain.config.PkgConfig.getLeftValue();
}
else {
mDeviceValue = com.mydomain.config.PkgConfig.getRightValue();
}
}
这就是我声明依赖项的方式:
compileOnly files('libs/left.jar')
compileOnly files('libs/right.jar')
这个设置给我一个错误提示
错误:找不到符号方法getRightValue()
我的目标是从中创建一个 APK。我知道我可以使用sourcesets 并这样做:
leftCompileOnly files('libs/left.jar')
rightCompileOnly files('libs/right.jar')
但它会创建两个 APK。有没有办法解决这个问题?
【问题讨论】:
-
你检查过这个SO Question吗?一些答案建议编写自定义类加载器。