I'm developing an app on Flutter. There's this button in the Flutter code that when I press it I go to a native activity on Android as it uses a specific library only available there (JCenter repo).

This works perfectly fine when I plug my phone to the PC and run it through Android studio, but when I create the APK, install it on the same phone and press the button to go to the native activity it crashes. I've ran adb logcat when this happens and the error I see that could cause the crash is NoSuchMethodError: no static method "libraryName;methodName".

I imagine the APK doesn't load the specific library from JCenter, but I can't find a single reason why that would happen, or how to make it work. Or maybe I'm completely wrong and this isn't what's happening, but I'm at a loss.

Does anyone have any idea why that would happen or how to find out more that would help me fix it?

EDIT:

the library is called wifination. The method of the error is OnSave2ToGallery. I've found out also exactly where in my code it crashes (copied from their sample code), and it's when I do wifination.appContext=getApplicationContext() in the onCreate() method of the Activity. appContext is public static Context appContext in the wifination class.

A bit more of the error:

09-29 18:19:32.853 30468 30468 D AndroidRuntime: Shutting down VM
09-29 18:19:32.853 30468 30468 E AndroidRuntime: FATAL EXCEPTION: main
09-29 18:19:32.853 30468 30468 E AndroidRuntime: Process: com.my.app, PID: 30468
09-29 18:19:32.853 30468 30468 E AndroidRuntime: java.lang.NoSuchMethodError: no static method "Lcom/joyhonest/wifination/wifination;.OnSave2ToGallery(Ljava/lang/String;I)V"
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at java.lang.Runtime.nativeLoad(Native Method)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at java.lang.Runtime.nativeLoad(Runtime.java:1121)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at java.lang.Runtime.loadLibrary0(Runtime.java:1075)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at java.lang.Runtime.loadLibrary0(Runtime.java:998)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at java.lang.System.loadLibrary(System.java:1656)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at com.joyhonest.wifination.wifination.<clinit>(Unknown Source:15)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at com.my.app.MyActivity.onCreate(Unknown Source:36)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:8057)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.Activity.performCreate(Activity.java:8037)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1344)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3688)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3864)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2253)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:106)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.os.Looper.loopOnce(Looper.java:201)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:288)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7870)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:550)
09-29 18:19:32.853 30468 30468 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
09-29 18:19:32.856  1340  7072 W ActivityTaskManager:   Force finishing activity com.my.app/.MyActivity
09-29 18:19:32.856  1340 30620 I DropBoxManagerService: add tag=data_app_crash isTagEnabled=true flags=0x2
09-29 18:19:32.858  1340  7072 W ActivityTaskManager:   Force finishing activity com.my.app/.MainActivity
09-29 18:19:32.859  1340  1562 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.stats.service.DropBoxEntryAddedReceiver
09-29 18:19:32.860  1340  1562 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.intent.action.DROPBOX_ENTRY_ADDED flg=0x10 (has extras) } to com.google.android.gms/.chimera.GmsIntentOperationService$PersistentTrustedReceiver


Solution 1: Stasky

It was R8 that wasn't including the private static methods of the library. I added them in the proguard-rules file and it works fine.