加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

React Native应用程序崩溃:无法从资产’index.android.bundle’

发布时间:2020-12-15 05:05:30 所属栏目:百科 来源:网络整理
导读:在发布模式下,在设备上运行React Native应用程序时,我在启动时遇到崩溃(调试模式工作正常).主要错误似乎是: AndroidRuntime: java.lang.RuntimeException: Unable to load script from assets ‘index.android.bundle’. Make sure your bundle is packaged
在发布模式下,在设备上运行React Native应用程序时,我在启动时遇到崩溃(调试模式工作正常).主要错误似乎是:

AndroidRuntime: java.lang.RuntimeException: Unable to load script from assets ‘index.android.bundle’. Make sure your bundle is packaged correctly or you’re running a packager server.

我发现了有关此错误的各种线程,但有旧版本,并且没有提供的解决方案正常工作.

日志如下:

12-16 19:20:28.581 29088 29109 E AndroidRuntime: FATAL EXCEPTION: Thread-3
12-16 19:20:28.581 29088 29109 E AndroidRuntime: Process: net.cozic.joplin,PID: 29088
12-16 19:20:28.581 29088 29109 E AndroidRuntime: java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at com.facebook.react.bridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at com.facebook.react.bridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:216)
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at com.facebook.react.bridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:32)
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at com.facebook.react.bridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:243)
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:1114)
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at com.facebook.react.ReactInstanceManager.access$900(ReactInstanceManager.java:116)
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at com.facebook.react.ReactInstanceManager$5.run(ReactInstanceManager.java:913)
12-16 19:20:28.581 29088 29109 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:761)
12-16 19:20:28.582  1695  1707 W ActivityManager:   Force finishing activity net.cozic.joplin/.MainActivity

这是我的app / build.gradle文件:

apply plugin: "com.android.application"

import com.android.build.OutputFile

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

def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion

    defaultConfig {
        applicationId "net.cozic.joplin"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 2097414
        versionName "1.0.178"
        ndk {
            abiFilters "armeabi-v7a","x86"
        }
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true,also generate a universal APK
            include "armeabi-v7a","x86"
        }
    }
    signingConfigs {
        release {
            if (project.hasProperty('JOPLIN_RELEASE_STORE_FILE')) {
                storeFile file(JOPLIN_RELEASE_STORE_FILE)
                storePassword JOPLIN_RELEASE_STORE_PASSWORD
                keyAlias JOPLIN_RELEASE_KEY_ALIAS
                keyPassword JOPLIN_RELEASE_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"),"proguard-rules.pro"
            signingConfig signingConfigs.release
        }
    }
    // 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]
            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 project(':react-native-firebase')
    implementation (project(':react-native-camera')) {
        exclude group: "com.google.android.gms"
    }
    implementation project(':react-native-file-viewer')
    implementation project(':react-native-securerandom')
    implementation project(':react-native-fs')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-fs')
    implementation fileTree(dir: "libs",include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation project(':react-native-sqlite-storage')
    implementation project(':rn-fetch-blob')
    implementation project(':react-native-document-picker')
    implementation project(':react-native-image-resizer')
    implementation project(':react-native-share-extension')
    implementation project(':react-native-version-info')
    implementation "com.facebook.react:react-native:+"

    implementation "com.google.android.gms:play-services-base:16.0.1" // For Firebase
    implementation "com.google.firebase:firebase-core:16.0.4" // For Firebase
    implementation "com.google.firebase:firebase-messaging:17.3.4" // For Firebase
    implementation 'me.leolin:ShortcutBadger:1.1.21@aar' // For Firebase - this line if you wish to use badge on Android

    compile ("com.android.support:support-v4:26.0.1") {
        force = true //<-- force dependency resolution to 26.0.1 in my case
    }
}

// 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: "../../node_modules/react-native-vector-icons/fonts.gradle"
apply plugin: 'com.google.gms.google-services' // For Firebase

和android / build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0' // Upgraded from 3.1.4 to 3.2.0 for Firebase
        classpath 'com.google.gms:google-services:4.0.1' // For Firebase

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

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter() // Was added by me - still needed?
        maven {
            url "https://maven.google.com"
        }
        maven {
            // All of React Native (JS,Obj-C sources,Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}


subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 26
                buildToolsVersion "27.0.3"
            }
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.4'
    distributionUrl = distributionUrl.replace("bin","all")
}

知道可能是什么问题吗?

编辑:我不能将gradle构建工具从3.2.0降级到3.1.4,因为一些答案建议,因为Firebase模块需要3.2.0.

您没有指定您正在使用哪个版本的react-native.我和0.57.3有同样的问题,其他答案让我走上了正确的轨道:Android构建系统中有一个带有android gradle插件版本3.2的错误,该错误在0.57.5( changelog)中得到解决.

错误修复是here,如果您不想升级RN,则手动集成非常简单.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读