LiquidPlayer / LiquidCore

Node.js virtual machine for Android and iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No such method. Did you make it public?

crazytomaoto opened this issue · comments

when use signed apk ,it broken.but there is no problem an debug apk.

@crazytomaoto this is most likely an issue with an "unused" function (from the java perspective) being filtered out of the apk in production build. Since the function is only called by reflection from native code, proguard does not see it as used, and will strip it from the final apk. You have to put an exception in your proguard.pro file. See 'Keep Options' in the proguard manual.

Actually, this can be easier. Use the @Keep attribute on any function you don't want minified away. Example:

JSFunction function = new JSFunction(context, "myFunction") {
   @public @Keep
   int myFunction(int val) {
       return val + 1;
   }
}

The compiler won't get rid of it in release builds then.
https://developer.android.com/reference/android/support/annotation/Keep

@ericwlange I'm getting this error if I try to build a minified version with version 0.6.2 of LiquidCore. If I downgrade to 0.5.0 I stop having this problem.

Using it as a Native Javascript Engine.

Don't think it will help much but here's the stacktrace:

Fatal Exception: org.liquidplayer.javascript.JSException: No such method. Did you make it public?
at org.liquidplayer.javascript.JSFunction. + 286(JSFunction.java:286)
at org.liquidplayer.javascript.JSFunction. + 327(JSFunction.java:327)
at org.liquidplayer.javascript.JSFunction. + 356(JSFunction.java:356)
at org.liquidplayer.javascript.JSContext$2. + 155(JSContext.java:155)
at org.liquidplayer.javascript.JSContext. + 155(JSContext.java:155)
at org.liquidplayer.javascript.JSContext. + 89(JSContext.java:89)

This should be the same issue as flagged here. If it works in regular debug mode, but you get this error in minified mode, it means that the compiler is stripping out a function that it thinks is unused. If it is only being called from LiquidCore, then it will appear unused, as LiquidCore calls the function using Reflection. The compiler is not smart enough to realize that.

If you are using the Android Studio IDE, it will show you warnings where it thinks functions are unused. You should be able to use the @Keep attribute to stop the compiler from stripping the function.

@ericwlange Thanks for the reply.
I do have @Keep on my functions and as I said on my previous message, this works fine under 0.5.0. My problem now is that 0.5.0 is broken on Jitpack. This forced me to update so I tried to upgrade to 0.6.2 to later find out this issue again.

I only have two callback classes and they both have the @Keep annotation. I decompiled my signed apk and I can see that the functions are there with their names intact to I fear that this problem comes from within the library itself. Any suggestion?

Update
I managed to make it working on the latest version 0.6.2 by adding these proguard rules:

-keepattributes InnerClasses
-keep class org.liquidplayer.** { *; }
-keep interface org.liquidplayer.** { *; }

In conclusion, minifying was also removing stuff that shouldn't be removed from the LiquidPlayer Library. Will do some more testing but hopefully this solves it and will help someone else.

Have you test with version 0.7.10 yet?