集成 Proguard 后,我遇到了 Rhino API 的问题。
没有 proguard,下面的代码可以正常工作。
org.mozilla.javascript.Context context = org.mozilla.javascript.Context.enter();
context.setOptimizationLevel(-1);
ScriptableObject scope = context.initStandardObjects();
try {
InputStream inputStream = mContext.getAssets().open(JAVASCRIPT_FILE);
InputStreamReader reader = new InputStreamReader(inputStream);
context.evaluateReader(scope, reader, JAVASCRIPT_FILE, 1, null);
} catch (IOException exception) {
throw new CustomException(null, exception);
}
Function functionAdd = (Function) scope.get(JAVASCRIPT_FUNCTION_NAME);
Object returnObject = functionAdd.call(context, scope, scope, new Object[] {
parameter1, parameter2, parameter3
});
但是在集成 Proguard 之后,出现以下错误:
02-26 14:58:13.200: E/AndroidRuntime(11607): Caused by: java.lang.IllegalStateException: Failed to create VMBridge instance
02-26 14:58:13.200: E/AndroidRuntime(11607): at org.a.b.ds.<clinit>(Unknown Source)
02-26 14:58:13.200: E/AndroidRuntime(11607): ... 11 more
最佳答案
Proguard 会混淆 rhino 库类,除非您明确告诉它不要这样做。正如 Selvin 所指出的,尤其是 VMBridge.java 类会受到影响。
防止 rhino 库类被混淆将解决这个问题。为此使用以下 proguard 异常:
-keep class org.mozilla.javascript.** { *; }
关于android - 集成 proguard 后 Rhino API 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22045384/