【问题标题】:React Native Android: Release build keeps crashing sinceReact Native Android:发布版本一直在崩溃
【发布时间】:2021-03-18 16:27:10
【问题描述】:

我是原生反应的新手——事实上,我对一般的应用程序开发很陌生。我正在尝试在 Android 模拟器上运行发布版本,但应用程序一直在崩溃。

调试版本运行没有任何问题,在 iOS 上同样的发布版本运行完美。

这是我所做的:

1.清理构建文件夹

2.在android/app/src/main/assets创建index.android.bundle

3.创建发布APK文件

4.在安卓模拟器上运行,但一直崩溃。

我在这里迷路了。有人可以帮忙告诉我哪里可能出错了吗?

这是由 android/app/build.gradle 提供的:

    import com.android.build.OutputFile


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


    project.ext.react = [
        enableHermes: false
    ]

    apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
    apply from: "../../node_modules/react-native/react.gradle"
    apply from: "../../node_modules/react-native-vector-icons/fonts.gradle"


    def enableSeparateBuildPerCPUArchitecture = false


    def enableProguardInReleaseBuilds = true


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

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

    //Function to get key from the key store

    def getPassword(String currentUser, String keyChain) {
    def stdout = new ByteArrayOutputStream()
    def stderr = new ByteArrayOutputStream()
    exec {
        commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w'
        standardOutput = stdout
        errorOutput = stderr
        ignoreExitValue true
    }
    //noinspection GroovyAssignabilityCheck
        stdout.toString().trim()
    }

    def pass = getPassword("my_name","my_keystore");

    android {
        compileSdkVersion rootProject.ext.compileSdkVersion

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }

        defaultConfig {
            applicationId "com.myappid"
            minSdkVersion rootProject.ext.minSdkVersion
            targetSdkVersion rootProject.ext.targetSdkVersion
            versionCode 1
            versionName "1.0"
            multiDexEnabled true 
            vectorDrawables.useSupportLibrary = true
        }
        splits {
            abi {
                reset()
                enable enableSeparateBuildPerCPUArchitecture
                universalApk false  // If true, also generate a universal APK
                include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
            }
        }
        signingConfigs {
            debug {
                storeFile file('debug.keystore')
                storePassword 'android'
                keyAlias 'androiddebugkey'
                keyPassword 'android'
            }
            release {
                storeFile file('release.keystore')
                storePassword pass 
                keyAlias 'release'
                keyPassword pass 
            }
        }
        buildTypes {
            debug {
                signingConfig signingConfigs.debug
            }
            release {
                // Caution! In production, you need to generate your own keystore file.
                // see https://facebook.github.io/react-native/docs/signed-apk-android.
                signingConfig signingConfigs.release
                minifyEnabled enableProguardInReleaseBuilds
                proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
                shrinkResources true
            }
        }

        packagingOptions {
            pickFirst "lib/armeabi-v7a/libc++_shared.so"
            pickFirst "lib/arm64-v8a/libc++_shared.so"
            pickFirst "lib/x86/libc++_shared.so"
            pickFirst "lib/x86_64/libc++_shared.so"
        }

        dexOptions {
            javaMaxHeapSize "4g"
        }


        // 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:
                // https://developer.android.com/studio/build/configure-apk-splits.html
                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
                }

            }
        }
    }

    dependencies {
        implementation fileTree(dir: "libs", include: ["*.jar"])
        //noinspection GradleDynamicVersion
        implementation "com.facebook.react:react-native:+"  // From node_modules
        implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
        implementation 'com.google.firebase:firebase-core:17.0.0'
        
        debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.fbjni'
        }
        debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
            exclude group:'com.facebook.flipper'
        }
        debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
            exclude group:'com.facebook.flipper'
        }
        addUnimodulesDependencies([exclude: ['expo-splash-screen','expo-permissions']])

        if (enableHermes) {
            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'
    }

    apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

这是来自 adb logcat 的错误日志:

【问题讨论】:

    标签: android react-native react-native-android


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      从 android/app 打开 Build.gradle。

      将 enableProguardInReleaseBuilds 更改为 false,

      def enableProguardInReleaseBuilds = false

      清理 gradle 并尝试

      【讨论】:

        猜你喜欢
        • 2021-04-24
        • 2018-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多