将 Android SDK 从版本 33 升级到 34 后,应用程序在 Android 33 上运行流畅,但在 Android 34 上崩溃。
进行了以下更改:
buildscript {
ext {
googlePlayServicesVersion = "+"
firebaseMessagingVersion = "21.1.0"
buildToolsVersion = "34.0.0"
minSdkVersion = 21
compileSdkVersion = 34
targetSdkVersion = 34
androidXAnnotation = "1.1.0"
androidXBrowser = "1.0.0"
pdfViewer = "3.1.0-beta.1"
}
我当前的 React Native 版本是 0.68.6。
Android 34 中的错误:
FATAL EXCEPTION:
java.lang.RuntimeException: Unable to create application com.poi.MainApplication: java.lang.RuntimeException: Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7716)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2478)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:230)
at android.os.Looper.loop(Looper.java:319)
at android.app.ActivityThread.main(ActivityThread.java:8919)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:578)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
Caused by: java.lang.RuntimeException: Requested enabled DevSupportManager, but BridgeDevSupportManager class was not found or could not be created
at
但是,在启动应用程序时,我遇到了应用程序在启动后立即崩溃的问题。为了调查这个问题,我提取了一份错误报告,其中提供了以下见解:
幸运的是,我找到了解决方案。仍然面临上述问题的朋友,请参考以下内容
打开 MainApplication.java 文件并添加以下代码。
首先,导入这些行
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import org.jetbrains.annotations.Nullable;
并确保将此代码添加到 oncreate() 方法上方。
@Override
public Intent registerReceiver(@Nullable BroadcastReceiver receiver, IntentFilter filter) {
if (Build.VERSION.SDK_INT >= 34 && getApplicationInfo().targetSdkVersion >= 34) {
return super.registerReceiver(receiver, filter, Context.RECEIVER_EXPORTED);
} else {
return super.registerReceiver(receiver, filter);
}
}
将此行添加到 android/app/build.gradle 依赖项中。
实现“org.jetbrains:注释:16.0.2”
现在运行您的应用程序。我希望它会起作用。确保正确测试应用程序是否正常工作。