gradle Android版React native的开发(调试)版本每次都会异常崩溃

odopli94  于 2023-03-30  发布在  Android
关注(0)|答案(1)|浏览(137)

我试图在Android中启动我的React原生应用程序以添加更多功能。但是当我尝试在Android设备上运行调试应用程序时,它崩溃并将我扔到启动器主屏幕上。我试图在Android Studio上运行应用程序以获取有关应用程序出错的更多信息,当我运行应用程序时,我在终端中发现了一些错误,我还在网上看了这个问题的解决方案。我发现社区建议的解决方案已经在代码库中实现了。我尝试了很多方法来解决这个问题,也尝试了模拟器,但没有运气。所以我想在StackOverflow上问一个问题

  • 我在Android Studio中发现的错误如下:- https://prnt.sc/D7ei7In6_bWn我正在添加所有需要的配置,您可以查看并帮助我(如果可能)
    问题更新:- 使用节点v16.13.1
  • Package.json
"dependencies": {
    "@monterosa/react-native-parallax-scroll": "^1.8.0",
    "@notifee/react-native": "^5.7.0",
    "@react-native-async-storage/async-storage": "^1.17.10",
    "@react-native-community/progress-bar-android": "^1.0.4",
    "@react-native-community/progress-view": "^1.3.2",
    "@react-native-firebase/app": "^14.5.0",
    "@react-native-firebase/messaging": "^14.5.0",
    "frisbee": "^3.1.4",
    "immutability-helper": "^3.1.1",
    "lodash": "^4.17.21",
    "native-base": "^2.8.1",
    "react": "17.0.1",
    "react-icons": "^4.4.0",
    "react-native": "^0.63.5",
    "react-native-a": "^1.0.1",
    "react-native-app-intro-slider": "^1.0.1",
    "react-native-facebook-login": "^1.6.2",
    "react-native-fast-image": "^8.6.1",
    "react-native-firebase-push-notifications": "^2.0.2",
    "react-native-fs": "^2.20.0",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-image-crop-picker": "^0.38.0",
    "react-native-in-app-utils": "^6.1.0",
    "react-native-loading-spinner-overlay": "^3.0.1",
    "react-native-localization": "^2.3.1",
    "react-native-material-dialog": "^0.7.7",
    "react-native-modal": "^13.0.1",
    "react-native-music-control": "^1.4.1",
    "react-native-music-player-service": "^0.1.4-beta",
    "react-native-popup-menu": "^0.16.1",
    "react-native-push-notification": "^8.1.1",
    "react-native-restart": "^0.0.24",
    "react-native-screens": "^3.17.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-sound": "^0.11.2",
    "react-native-splash-screen": "^3.3.0",
    "react-native-super-grid": "^4.6.1",
    "react-native-swift": "^1.2.3",
    "react-native-swiper": "^1.6.0",
    "react-native-track-player": "^1.2.7",
    "react-native-typing-text": "^0.0.3",
    "react-native-vector-icons": "^9.2.0",
    "react-native-webview": "^11.6.6",
    "react-navigation": "^3.0.4",
    "react-redux": "^8.0.2",
    "react-timeago": "^7.1.0",
    "realm": "^10.6.0",
    "redux": "^4.2.0",
    "redux-saga": "^1.2.1",
    "rn-sliding-up-panel": "^2.4.6",
    "toggle-switch-react-native": "^3.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.19.1",
    "@babel/runtime": "^7.19.0",
    "babel-jest": "^29.0.3",
    "jest": "^29.0.3",
    "metro-react-native-babel-preset": "^0.72.3",
    "schedule": "^0.5.0"
  },

构建等级:-

// Top-level build file where you can add configuration options common to all sub-projects/modules.
def REACT_NATIVE_VERSION = new File(['node', '--print',"JSON.parse(require('fs').readFileSync(require.resolve('react-native/package.json'), 'utf-8')).version"].execute(null, rootDir).text.trim())

allprojects {
    configurations.all {
        resolutionStrategy {
            // Remove this override in 0.65+, as a proper fix is included in react-native itself.
            force "com.facebook.react:react-native:" + REACT_NATIVE_VERSION
        }
    }
}
buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 23
        compileSdkVersion = 31
        targetSdkVersion = 30
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
        mavenLocal()
        maven { url "https://jitpack.io" }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
            }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven { url("$rootDir/../node_modules/jsc-android/dist") }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath 'com.google.gms:google-services:4.3.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
    }
    configurations.all {
            resolutionStrategy.force "com.android.support:support-v4:26.1.0"
        }
}
subprojects { subproject ->
    afterEvaluate{
        if((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion

            }
        }
    }
    subproject.configurations.all {
         resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                  && !details.requested.name.contains('multidex') ) {
               details.useVersion "28.0.0"
            }
         }
      }
}
ext {
    buildToolsVersion = "30.0.2"
    minSdkVersion = 23
    compileSdkVersion = 31
    targetSdkVersion = 30
    supportLibVersion = "28.0.0"
    googlePlayServicesVersion = "23.0.0"
}

应用程序/build.gradle:-

apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block, make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",
 *
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",
 *
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,
 *
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,
 *
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,
 *   // bundleInPaidRelease: true,
 *   // bundleInBeta: true,
 *
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,
 *   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project, i.e. where "package.json" lives
 *   root: "../../",
 *
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
 *
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
 *
 *   // where to put drawable resources / React Native assets, e.g. the ones you use via
 *   // require('./image.png')), in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
 *
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
 *   // for example, you might want to remove it from here.
 *   inputExcludes: ["android/**", "ios/**"],
 *
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],
 *
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

project.ext.react = [
    entryFile: "index.js",
    enableHermes: false,
]

apply from: "../../node_modules/react-native/react.gradle"

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    ndkVersion "22.0.7026061"

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    defaultConfig {
            applicationId "com.loveworld.worship"
            minSdkVersion rootProject.ext.minSdkVersion
            targetSdkVersion rootProject.ext.targetSdkVersion
            missingDimensionStrategy "RNN.reactNativeVersion", "reactNative56"
            versionCode 37
            versionName "4.2"
            vectorDrawables.useSupportLibrary = true
            multiDexEnabled true
            ndk {
                abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
            }
        }
        signingConfigs {
                debug {
                    storeFile file('debug.keystore')
                    storePassword 'android'
                    keyAlias 'androiddebugkey'
                    keyPassword 'android'
                }
                release {
                    if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                        storeFile file(MYAPP_RELEASE_STORE_FILE)
                        storePassword MYAPP_RELEASE_STORE_PASSWORD
                        keyAlias MYAPP_RELEASE_KEY_ALIAS
                        keyPassword MYAPP_RELEASE_KEY_PASSWORD
                    }
                }
            }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            signingConfig signingConfigs.release
        }
        mySpecialRelease {
            matchingFallbacks = ['release', 'debug']
        }
    }
    // applicationVariants are e.g. debug, release
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            // For each separate APK per architecture, set a unique version code as described here:
            // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
            def versionCodes = ["armeabi-v7a":1, "x86":2, "arm64-v8a": 3, "x86_64": 4]
            def abi = output.getFilter(OutputFile.ABI)
            if (abi != null) {  // null for the universal-debug, universal-release variants
                output.versionCodeOverride =
                        versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
            }
        }
    }

    compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
     }
}

dependencies {
    implementation project(':@react-native-async-storage_async-storage')
    implementation project(':react-native-facebook-login')
    implementation project(':react-native-firebase-push-notifications')
    implementation'com.facebook.soloader:soloader:0.9.0+'
    implementation project(':react-native-screens')
    implementation project(':react-native-restart')
    implementation project(':react-native-track-player')
    implementation project(':realm')
    implementation project(':react-native-fs')
    implementation project(':react-native-music-control')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-localization')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-image-crop-picker')
    implementation project(':react-native-sound')
    implementation project(':react-native-fast-image')
    implementation 'com.android.support:multidex:1.0.1'
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    if (enableHermes) {
        // for RN 0.61+
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// Run this once to be able to run the application with BUCK
// puts all compile dependencies into folder libs for BUCK to use
task copyDownloadableDepsToLibs(type: Copy) {
    from configurations.compile
    into 'libs'
}

AndroidManifest.json:-

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.loveworld.worship"
          xmlns:tools="http://schemas.android.com/tools">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:exported="true"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:launchMode="singleTop"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="true" />
        <activity tools:replace="android:theme"
                  android:exported="true"
                  android:name="com.facebook.FacebookActivity"
                  android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

        <!--add CustomTabActivity-->
        <activity
                android:name="com.facebook.CustomTabActivity"
                android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

        <!--reference your fb_app_id-->
        <meta-data
                android:name="com.facebook.sdk.ApplicationId"
                android:value="@string/fb_app_id"/>
        <meta-data
                android:name="com.google.firebase.messaging.default_notification_icon"
                android:resource="@mipmap/ic_launcher" />
    </application>

</manifest>

帮助是高度赞赏从React本地乡亲
谢谢

rnmwe5a2

rnmwe5a21#

我找到解决办法了
1.删除包锁定文件
1.使用Yarn来安装依赖项
1.将build.gradle文件sdk值更改为

minSdkVersion = 21
    compileSdkVersion = 31
    targetSdkVersion = 30

相关问题