Android APK 在活动时崩溃,但从 Android Studio 运行时可以正常工作

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

我正在 Flutter 上开发一个应用程序。 Flutter 代码中有一个按钮,当我按下它时,我会进入 Android 上的本机活动,因为它使用仅在那里可用的特定库(

JCenter
存储库)。

当我将手机插入 PC 并通过 Android studio 运行它时,效果非常好,但是当我创建 APK,将其安装在同一部手机上并按下按钮转到本机 Activity 时,它崩溃了。当发生这种情况时,我已经运行了

adb logcat
,我发现可能导致崩溃的错误是
NoSuchMethodError: no static method "libraryName;methodName"

我想 APK 不会从

JCenter
加载特定库,但我找不到发生这种情况的任何原因,或者如何使其工作。或者也许我完全错了,这不是正在发生的事情,但我不知所措。

为什么会发生这种情况或者如何找到更多信息来帮助我解决这个问题?

图书馆名为

wifination
。错误的方法是
OnSave2ToGallery
。我还准确地发现了我的代码中崩溃的位置(从他们的示例代码中复制),就是当我在 Activity 的
wifination.appContext=getApplicationContext()
方法中执行
onCreate()
时。
appContext
public static Context appContext
类中的
wifination

还有一点错误:

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
java android flutter apk jcenter
1个回答
0
投票

R8 不包含库的

private static
方法。我将它们添加到
proguard-rules
文件中,效果很好。

© www.soinside.com 2019 - 2024. All rights reserved.