gpt4 book ai didi

android - 使用 build apk 命令构建的 Flutter 应用程序无法运行特定于平台的代码

转载 作者:行者123 更新时间:2023-12-03 13:30:10 25 4
gpt4 key购买 nike

我有一个 flutter 应用程序,它使用方法 channel 运行某些特定于平台的代码。此代码还通过 gradle 依赖项使用外部库。使用 android studio 构建调试和 Release模式时,一切正常。但是当使用 flutter build apk 构建时命令,应用程序在尝试执行平台代码时崩溃。
这些是我从 adb logcat 获得的日志从方法之一:

05-30 02:04:53.302  4398  4398 E AndroidRuntime: Process: com.**.**, PID: 4398
05-30 02:04:53.302 4398 4398 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.**.**/com.razorpay.CheckoutActivity}: java.lang.ClassNotFoundException: com.razorpay.G__G_
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3271)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3410)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2017)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:107)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.os.Looper.loop(Looper.java:214)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7397)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: com.razorpay.G__G_
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.O__Y_.G__G_(:1100)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.b1.<clinit>(Unknown Source:1683)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.b1.a(Unknown Source:0)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.c.f(Unknown Source:11)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.g.c(Unknown Source:0)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.k.onCreate(Unknown Source:70)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.w0.onCreate(Unknown Source:110)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at com.razorpay.CheckoutActivity.onCreate(Unknown Source:0)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7993)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7982)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3246)
05-30 02:04:53.302 4398 4398 E AndroidRuntime: ... 11 more

这里 com.razorpay 就是我正在使用的一个这样的外部库。对于其他库,我也遇到同样的错误。所以基本上它在尝试使用任何外部库时都会崩溃。知道可能是什么问题吗?

编辑:

这是我的 list 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.**.**">

<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />

<application
android:name="io.flutter.app.FlutterApplication"
android:icon="@mipmap/ic_launcher"
android:label="**"
android:requestLegacyExternalStorage="true">
<activity
android:name=".IncomingCallActivity"
android:screenOrientation="portrait"
android:theme="@style/NoActionBar" />
<activity
android:name=".TokboxActivity"
android:label="Incoming Call"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout"
android:supportsPictureInPicture="true"
android:theme="@style/NoActionBar" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java
-->
<meta-data
android:name="flutterEmbedding"
android:value="2" />

<service
android:name=".MessagingService"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>

</manifest>

最佳答案

当您使用 flutter build apk 时似乎, gradle 不包括您在构建的 apk 中添加的库。

您需要进行几项检查:

  • 检查您是否正在使用 proguard 优化和 minifyEnabled true .如果是,尝试设置minifyEnabled false , 否则按照第二次检查
  • 检查您是否在使用 implementation为您的项目添加依赖项时使用关键字。如果是,请尝试将其替换为 api

  • 我希望这有帮助

    关于android - 使用 build apk 命令构建的 Flutter 应用程序无法运行特定于平台的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62095953/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com