android - 由 java.lang.NoClassDefFoundError 引起的 react native 致命异常

标签 android react-native

我仅在我的新测试手机 (Android 6.0) 上遇到此致命异常。 这是错误日志:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2

Process: com.***, PID: 19024
java.lang.RuntimeException: An error occurred while executing doInBackground()
   at android.os.AsyncTask$3.done(AsyncTask.java:309)
   at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
   at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
   at java.util.concurrent.FutureTask.run(FutureTask.java:242)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
   at java.lang.Thread.run(Thread.java:818)

Caused by: java.lang.NoClassDefFoundError: com.facebook.react.devsupport.InspectorPackagerConnection$Connection
   at com.facebook.react.devsupport.InspectorPackagerConnection.<init>(InspectorPackagerConnection.java:39)
   at com.facebook.react.devsupport.DevServerHelper$3.doInBackground(DevServerHelper.java:203)
   at com.facebook.react.devsupport.DevServerHelper$3.doInBackground(DevServerHelper.java:200)
   at android.os.AsyncTask$2.call(AsyncTask.java:295)
   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
   at java.lang.Thread.run(Thread.java:818) 

我使用了很多库,在这里:

"buffer": "^5.0.6",
"fetchival": "^0.3.2",
"lodash": "^4.17.4",
"native-base": "^2.1.3",
"qs": "^6.4.0",
"react": "16.0.0-alpha.12",
"react-native": "0.45.1",
"react-native-background-upload": "^3.0.0-beta",
"react-native-camera": "git+https://github.com/lwansbrough/react-native-camera.git",
"react-native-datepicker": "^1.6.0",
"react-native-easy-grid": "^0.1.13",
"react-native-fetch-blob": "^0.10.6",
"react-native-fs": "^2.3.3",
"react-native-image-picker": "^0.26.3",
"react-native-keyboard-aware-scroll-view": "^0.2.9",
"react-native-linear-gradient": "^2.0.0",
"react-native-message-bar": "^1.6.0",
"react-native-swiper": "^1.5.4",
"react-native-vector-icons": "^4.0.1",
"react-native-video": "^1.0.0",
"react-native-video-controls": "^1.2.0",
"react-navigation": "git+https://github.com/react-community/react-navigation.git",
"react-redux": "^5.0.5",
"redux": "^3.6.0",
"redux-persist": "^4.8.0",
"redux-persist-transform-filter": "0.0.10",
"redux-thunk": "^2.2.0",
"remote-redux-devtools": "^0.5.11"

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

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.1"

    defaultConfig {
        applicationId "com.***"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }

    signingConfigs {
        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 {
        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 {
    compile project(':react-native-fetch-blob')
    compile project(':react-native-image-picker')
    compile project(':react-native-background-upload')
    compile project(':react-native-fs')
    compile project(':react-native-video')
    compile project(':react-native-vector-icons')
    compile project(':react-native-linear-gradient')
    compile project(':react-native-camera')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:24.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

// 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'
}

这是 Android 独有的问题,该应用程序在 iOS 上运行良好。此外,这似乎是一个仅限开发的问题。发布的APK没有这个问题。 有人面临或遇到过类似的问题吗?

谢谢

最佳答案

我得到了同样的结果,并发现这是因为我将 com.squareup.okhttp3.okhttp 解析为不是最新版本。

将其解析为 3.6.0 解决了我的问题

关于android - 由 java.lang.NoClassDefFoundError 引起的 react native 致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44858911/

相关文章:

Android 警报管理器不起作用

java - 禁用自动旋转屏幕 - Android

Android GIF 支持 -- React Native 0.50

android - React-native 应用程序在真实的 Android 设备上崩溃

react-native - 如何解决使用 AsyncStorage (deprecated) 警告?使用社区(正确)库

node.js - Nodejs 服务器迁移到云端后无法响应

android - cordova run android 执行良好。但Android 4.1.2 不启动应用

android - 动态更新 ViewPager?

android - 如果为自定义任务注册了警报(作为提醒),那么当任务被删除时,警报会被删除吗?

reactjs - React Native 样板模板