Expo React Native Bare 发布 APK 在启动时立即崩溃

Posted

技术标签:

【中文标题】Expo React Native Bare 发布 APK 在启动时立即崩溃【英文标题】:Expo React Native Bare release APK crashing immediatly when launch 【发布时间】:2020-08-08 22:09:41 【问题描述】:

当我在我的真实设备中启动应用程序时,应用程序在启动屏幕之前崩溃(停止工作)。我发布了所有架构 APK,然后我在我的设备中测试了所有这些,没有一个工作。我正在使用 Hermes、Expo 库(我已经为 unimodules 设置了),并且在弹出项目之前,我已经在 Expo 应用程序中进行了测试,一切正常!

我的环境

System:
    OS: Windows 8.1 6.3.9600
    CPU: (4) x64 Intel(R) Pentium(R) CPU G4560 @ 3.50GHz
    Memory: 4.70 GB / 7.96 GB
  Binaries:
    Node: 12.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.21.1 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 6.13.4 - C:\Program Files\nodejs\npm.CMD
    Watchman: Not Found
  SDKs:
    android SDK:
      API Levels: 27, 28
      Build Tools: 27.0.3, 28.0.3
      Android NDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 1.8.0_231
    Python: 2.7.17
  npmPackages:
    @react-native-community/cli: Not Found
    react: ~16.11.0 => 16.11.0
    react-native: ~0.62.2 => 0.62.2
  npmGlobalPackages:
    *react-native*: Not Found

package.JSON


  "scripts": 
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "postinstall": "jetify"
  ,
  "dependencies": 
    "expo": "~38.0.8",
    "expo-splash-screen": "^0.5.0",
    "expo-status-bar": "^1.0.2",
    "expo-updates": "~0.2.10",
    "react": "~16.11.0",
    "react-dom": "~16.11.0",
    "react-native": "~0.62.2",
    "react-native-gesture-handler": "1.6.1",
    "react-native-reanimated": "1.8.0",
    "react-native-screens": "2.7.0",
    "react-native-unimodules": "~0.10.1",
    "react-native-web": "~0.11.7",
    "@react-native-community/masked-view": "0.1.10",
    "@react-native-community/netinfo": "5.9.0",
    "@react-native-community/viewpager": "^4.1.4",
    "expo-camera": "^8.3.1",
    "expo-document-picker": "^8.3.0",
    "expo-file-system": "^9.1.0",
    "expo-image-manipulator": "^8.2.1",
    "expo-image-picker": "^8.4.0",
    "expo-intent-launcher": "^8.2.1",
    "expo-permissions": "^9.1.0",
    "firebase": "^7.17.2",
    "react-native-animatable": "^1.3.3",
    "react-native-material-ripple": "^0.9.1",
    "react-native-modal": "^11.5.6",
    "react-native-paper": "^4.0.1",
    "react-native-progress-circle": "^2.1.0",
    "react-native-safe-area-context": "1.0.2",
    "react-native-vector-icons": "^7.0.0",
    "react-navigation": "4.2.2",
    "react-navigation-drawer": "^2.5.0",
    "react-navigation-stack": "^2.8.2",
    "react-navigation-tabs": "^2.9.0",
    "react-redux": "^7.2.1",
    "redux": "^4.0.5"
  ,
  "devDependencies": 
    "@babel/core": "^7.8.6",
    "babel-jest": "~25.2.6",
    "jest": "~25.2.6",
    "react-test-renderer": "~16.11.0",
    "babel-preset-expo": "~8.1.0"
  ,
  "private": true

build.gradle(android/app)

apply plugin: "com.android.application"

import com.android.build.OutputFile

project.ext.react = [
    enableHermes: true
]

apply from: '../../node_modules/react-native-unimodules/gradle.groovy'
apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/expo-updates/scripts/create-manifest-android.gradle"

def enableSeparateBuildPerCPUArchitecture = true

def enableProguardInReleaseBuilds = false

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

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

android 
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    

    defaultConfig 
        applicationId "com.bookep"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
    
    splits 
        abi 
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk true  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        
    
    signingConfigs 
        debug 
            storeFile file('my-release-key.keystore')
            storePassword '******'
            keyAlias 'my-key-alias'
            keyPassword '*****'
        
    
    buildTypes 
        debug 
            signingConfig signingConfigs.debug
        
        release 
            signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        
    

    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"
    

    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
            

        
    
    dexOptions 
        javaMaxHeapSize "3g"
    


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"
    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()

    if (enableHermes) 
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
     else 
        implementation jscFlavor
    


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)

【问题讨论】:

【参考方案1】:

我已经解决了这个问题,在 index.js 文件中使用 Expo 中的 registerRootComponent

【讨论】:

你把那行放在哪里了? 我是我的index.js 文件:import registerRootComponent from 'expo' import App from './App' registerRootComponent(App)

以上是关于Expo React Native Bare 发布 APK 在启动时立即崩溃的主要内容,如果未能解决你的问题,请参考以下文章

弹出 React Native 项目时,Bare 和 ExpoKit 有啥区别?

如何为 React Native Bare 工作流指定重定向 URI

Expo react-native 裸工作流使用推送通知

React-native (expo) - 无效类型

React Native - 如何构建 expo react native 应用程序,使其不需要 Expo android 应用程序打开

使用 react-native (expo) 切换手电筒