React Native 应用程序版本 <=0.65 for android is crashing in real device when targetSdkVersion is bumped from 33 to 34

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

我使用的是 RN 版本 0.64.0。当我将 targetSdkVersion 从 33 更改为 34 时,我的 React Native Android 崩溃了。

环境:
RN:0.64.0
节点:16.16.0
Gradle 版本(更新):7.4.2
Gradle插件版本(更新):7.3.0

I've updated the following packages versions in package.json to the ones that I felt its compatible to 0.64.0.
  
"@react-native-community/cli-platform-android": "6.0.0",
"react-native-screens": "2.17.0",
"react-native-reanimated": "2.2.0",

//android/build.gradle

buildscript {
    ext {
        androidSvgVersion = '1.2.1'
        appAuthVersion = '0.7.1'
        bitmovinCollectorVersion = '2.6.1'
        bitmovinPlayerVersion = '3.24.2'
        buildToolsVersion = '31.0.0'
        excludeAppGlideModule = true
        glideVersion = '4.11.0'
        minSdkVersion = 24
        compileSdkVersion = 33
        targetSdkVersion = 34
        timberVersion = '4.5.1'
        kotlinVersion = '1.6.21'
        ndkVersion = "20.1.5948944"
    }
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${project.ext.kotlinVersion}"
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.0.1'
        classpath 'com.google.gms:google-services:4.3.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        /*  android build throws minSdk not compatible for androidx.appcompat and it looks like the dependency versions are read from maven and not node_modules.
            Hence exclusiveContent block is required to ensure that dependency versions are read from node_modules and not from maven.
            It may not be required when react native version is upgraded to 0.71.0.
        */
        exclusiveContent{
            filter {
                includeGroup "com.facebook.react"
            }
            forRepository {
                maven {
                    // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
                    url "$rootDir/../node_modules/react-native/android"
                }

            }
        }
        maven {
            // Android JSC is installed from npm
            url "$rootDir/../node_modules/jsc-android/dist"
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        mavenLocal()
        google()
        mavenCentral()
        jcenter()
        maven { url 'https://bitmovin.jfrog.io/artifactory/public-releases' }
        maven { url 'https://maven.google.com' }
        maven { url "https://www.jitpack.io" }
    }
}

// TODO: React Native libraries (linked as project modules) with native code need to have a unified `compileSdkVersion` and `buildToolsVersion`.
// 3rd party dependencies usually have differing versions used and are not always using the latest ones (a *known* issue in the RN ecosystem). We work around this by using Gradle's `subproject` API (refer to the top-level/root `build.gradle` file).
subprojects { subproject ->
    afterEvaluate {
        if (subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library')) {
            android {
                compileSdkVersion rootProject.compileSdkVersion
                buildToolsVersion rootProject.buildToolsVersion
            }
        }
    }
}

我按照社区的建议进行了尝试。我做了以下更改,应用程序在调试模式下工作,但当我安装在真实设备中时,在发布模式下崩溃了。

MainApplication.java file

import android.content.Intent;
    import android.content.IntentFilter;
    import android.os.Build;
    import org.jetbrains.annotations.Nullable;
    @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
implementation 'org.jetbrains:annotations:16.0.2'

然后在寻找答案时,有人向我指出了https://medium.com/@zahitesh/android-14-sdk-34-support-for-react-native-ver-0-69-x-2554f4dc937d。我尝试这样做,但出现以下错误

cd android && ./gradlew ReactAndroid:installArchives
It gives below error:
FAILURE: Build failed with an exception.
* What went wrong:
Project 'ReactAndroid' not found in root project 'MyProjectName''.

另外从这篇文章SDK更新33到34我了解到PlayCore库已更新到Android 14并建议更新项目中的PlayCore Maven依赖项。但我认为上面的修复可以解决这个问题。而且由于它是运行时,所以很难说。我不确定要更新它的 Maven 依赖项。

我的问题是我确信可能有一些应用程序运行带有 RN 的版本 <= 0.65.0. Can anyone tell me what's the problem in the run time. Is it the problem of the patch mentioned above can't be applied to the version < 0.73.0. If there is any help, I would highly appreciate as i've tried all ways on my end to fix this. And i'm in a dire need to roll out soon as my time is ticking for the other project.

android react-native crash-reports
1个回答
0
投票

我终于找到答案了。

问题是 Gradle 版本和 Gradle 插件版本不兼容,这破坏了发布版本。然而,当我将 Gradle 版本和 Gradle 插件版本都设置为 7.0 时,它就像一个魅力。致所有参加 RN 的人 <= 0.65.0 this should positively work.

祝你好运!!!

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