frostwire / frostwire-jlibtorrent

A swig Java interface for libtorrent by the makers of FrostWire. Develop libtorrent based apps with the joy of coding in Java.
http://www.frostwire.com
MIT License
444 stars 137 forks source link

java.lang.NoSuchMethodError #192

Closed e4basil closed 6 years ago

e4basil commented 6 years ago
ANDROID_VERSION=6.0.1
APP_VERSION_NAME=1.5
BRAND=Xiaomi
PHONE_MODEL=Redmi Note 3
CUSTOM_DATA=
STACK_TRACE=java.lang.NoSuchMethodError: no static method "Lcom/frostwire/jlibtorrent/swig/libtorrent_jni;.SwigDirector_alert_notify_callback_on_alert(Lcom/frostwire/jlibtorrent/swig/alert_notify_callback;)V"
at com.frostwire.jlibtorrent.swig.libtorrent_jni.swig_module_init(Native Method)
at com.frostwire.jlibtorrent.swig.libtorrent_jni.<clinit>(libtorrent_jni.java:3145)
at com.frostwire.jlibtorrent.swig.libtorrent_jni.alert_error_notification_get(Native Method)
at com.frostwire.jlibtorrent.swig.e.<clinit>(alert.java:493)
at com.frostwire.jlibtorrent.a.d.<clinit>(AlertType.java:11)
at com.frostwire.jlibtorrent.q.<clinit>(SessionManager.java:23)
at org.proninyaroslav.libretorrent.services.TorrentTaskService.onCreate(TorrentTaskService.java:217)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:2910)
at android.app.ActivityThread.access$2000(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1458)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:5527)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
aldenml commented 6 years ago

Hi @e4basil, I notice that you are using another project (org.proninyaroslav.libretorrent), this looks like a missing dependency, can you post your gradle dependencies?

proninyaroslav commented 6 years ago

This happened when it enabled option minifyEnabled, please see https://github.com/proninyaroslav/libretorrent/issues/157.

aldenml commented 6 years ago

right, well, this goes to the core of how JNI and SWIG works together, but it's very easy to solve. You just need to be sure to keep all the native methods declaration. Since they are all native, stripping them gains nothing (or very little) to you, all the actual code still remains in the native library. Modify your proguard rules files with the following line:

-keep class com.frostwire.jlibtorrent.swig.libtorrent_jni {*;}

you can use the configuration just to minify, take a look at: https://github.com/frostwire/frostwire/blob/master/android/build.gradle#L142

abbasshah17 commented 4 years ago

Why is this issue closed? It is still there.

Using the latest library version: 1.2.7.0

I've added the following rule (also tried a few other variations)

-keep class com.frostwire.jlibtorrent.swig.libtorrent_jni {*;}

You can confirm this error in the following sample app I've created this repo just for this issue.

Just clone and run the project to see the error since minifyenabled is true in debug too.

gubatron commented 4 years ago

I can't replicate

gubatron commented 4 years ago

@abbasshah17 try classpath 'com.android.tools.build:gradle:3.6.3'

we're very hesitant to build android with gradle 4.0.0, lots of issues when building releases.

abbasshah17 commented 4 years ago

I can't replicate

Did you try the sample project I attached?

classpath 'com.android.tools.build:gradle:3.6.3'

Tried changing in the sample, still the same issue... Can you share the ndk version you are using?

gubatron commented 4 years ago

You can see them on the .travis.yml of the project.

- env: os_build=android os_arch=arm android_api=19
- env: os_build=android os_arch=arm64 android_api=21
- env: os_build=android os_arch=x86 android_api=19
- env: os_build=android os_arch=x86_64 android_api=21

https://dl.google.com/android/repository/android-ndk-r21-linux-x86_64.zip

You should probably follow the build instructions on Travis and use travis to make your builds.

We also have build scripts if you want to build on your own computer. e.g. https://github.com/frostwire/frostwire-jlibtorrent/blob/master/swig/build-android-x86_64.sh

abbasshah17 commented 4 years ago

Finally found a rule that works...

-keep public class com.frostwire.jlibtorrent.swig.** {
  *;
}

There is some issue with R8 minifier, the keep rule mentioned in the README or in this thread doesn't work, haven't verified whether it's just the R8 or also proguard or something else. Also haven't verified if this works in proguard.

Strangely the rule only applies when added in app/default module's proguard-rules.pro.