在集成proguard之后,在Rhino API中出现问题

问题描述 投票:1回答:1

在集成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
android rhino
1个回答
12
投票

Proguard会对rhino库类进行模糊处理,除非你明确告诉它不要这样做。正如Selvin所指出的,特别是VMBridge.java类会受到影响。

保持rhino库类不被混淆将解决问题。使用以下proguard异常:

-keep class org.mozilla.javascript.** { *; }
© www.soinside.com 2019 - 2024. All rights reserved.