1

我正在使用 react-native 创建一个应用程序。到目前为止,我已经实现了一些模块,例如react-native-camerareact-native-maps

一切正常,直到我尝试实施react-native-push-notification.

我使用本教程遵循了他们的实现,但是现在,即使应用程序构建成功,它也会在启动时崩溃。

这是我的 logcat(它实际上被裁剪了,因为它不适合这里)

11-19 18:29:15.419 29371 29456 I art     : Rejecting re-init on previously-failed class java.lang.Class<com.google.android.gms.maps.model.Cap>: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/internal/safeparcel/zza;
11-19 18:29:15.419 29371 29456 I art     :   at java.util.List com.airbnb.android.react.maps.MapsPackage.createViewManagers(com.facebook.react.bridge.ReactApplicationContext) (MapsPackage.java:36)
11-19 18:29:15.419 29371 29456 I art     :   at java.util.List com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(com.facebook.react.bridge.ReactApplicationContext) (ReactInstanceManager.java:753)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.uimanager.UIManagerModule com.facebook.react.CoreModulesPackage.createUIManager(com.facebook.react.bridge.ReactApplicationContext) (CoreModulesPackage.java:168)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.uimanager.UIManagerModule com.facebook.react.CoreModulesPackage.access$200(com.facebook.react.CoreModulesPackage, com.facebook.react.bridge.ReactApplicationContext) (CoreModulesPackage.java:52)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.NativeModule com.facebook.react.CoreModulesPackage$7.get() (CoreModulesPackage.java:126)
11-19 18:29:15.419 29371 29456 I art     :   at java.lang.Object com.facebook.react.CoreModulesPackage$7.get() (CoreModulesPackage.java:123)
11-19 18:29:15.419 29371 29456 I art     :   at void com.facebook.react.NativeModuleRegistryBuilder.processPackage(com.facebook.react.ReactPackage) (NativeModuleRegistryBuilder.java:61)
11-19 18:29:15.419 29371 29456 I art     :   at void com.facebook.react.ReactInstanceManager.processPackage(com.facebook.react.ReactPackage, com.facebook.react.NativeModuleRegistryBuilder) (ReactInstanceManager.java:1171)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.NativeModuleRegistry com.facebook.react.ReactInstanceManager.processPackages(com.facebook.react.bridge.ReactApplicationContext, java.util.List, boolean) (ReactInstanceManager.java:1141)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.ReactApplicationContext com.facebook.react.ReactInstanceManager.createReactContext(com.facebook.react.bridge.JavaScriptExecutor, com.facebook.react.bridge.JSBundleLoader) (ReactInstanceManager.java:1083)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.ReactApplicationContext com.facebook.react.ReactInstanceManager.access$900(com.facebook.react.ReactInstanceManager, com.facebook.react.bridge.JavaScriptExecutor, com.facebook.react.bridge.JSBundleLoader) (ReactInstanceManager.java:116)
11-19 18:29:15.419 29371 29456 I art     :   at void com.facebook.react.ReactInstanceManager$5.run() (ReactInstanceManager.java:913)
11-19 18:29:15.419 29371 29456 I art     :   at void java.lang.Thread.run() (Thread.java:762)
11-19 18:29:15.419 29371 29456 I art     : Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.common.internal.safeparcel.zza" on path: DexPathList[[zip file "/data/app/com.dpassapp-2/base.apk"],nativeLibraryDirectories=[/data/app/com.dpassapp-2/lib/arm, /data/app/com.dpassapp-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]
11-19 18:29:15.419 29371 29456 I art     :   at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:56)
11-19 18:29:15.419 29371 29456 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:380)
11-19 18:29:15.419 29371 29456 I art     :   at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
11-19 18:29:15.419 29371 29456 I art     :   at java.util.List com.airbnb.android.react.maps.MapsPackage.createViewManagers(com.facebook.react.bridge.ReactApplicationContext) (MapsPackage.java:36)
11-19 18:29:15.419 29371 29456 I art     :   at java.util.List com.facebook.react.ReactInstanceManager.getOrCreateViewManagers(com.facebook.react.bridge.ReactApplicationContext) (ReactInstanceManager.java:753)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.uimanager.UIManagerModule com.facebook.react.CoreModulesPackage.createUIManager(com.facebook.react.bridge.ReactApplicationContext) (CoreModulesPackage.java:168)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.uimanager.UIManagerModule com.facebook.react.CoreModulesPackage.access$200(com.facebook.react.CoreModulesPackage, com.facebook.react.bridge.ReactApplicationContext) (CoreModulesPackage.java:52)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.NativeModule com.facebook.react.CoreModulesPackage$7.get() (CoreModulesPackage.java:126)
11-19 18:29:15.419 29371 29456 I art     :   at java.lang.Object com.facebook.react.CoreModulesPackage$7.get() (CoreModulesPackage.java:123)
11-19 18:29:15.419 29371 29456 I art     :   at void com.facebook.react.NativeModuleRegistryBuilder.processPackage(com.facebook.react.ReactPackage) (NativeModuleRegistryBuilder.java:61)
11-19 18:29:15.419 29371 29456 I art     :   at void com.facebook.react.ReactInstanceManager.processPackage(com.facebook.react.ReactPackage, com.facebook.react.NativeModuleRegistryBuilder) (ReactInstanceManager.java:1171)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.NativeModuleRegistry com.facebook.react.ReactInstanceManager.processPackages(com.facebook.react.bridge.ReactApplicationContext, java.util.List, boolean) (ReactInstanceManager.java:1141)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.ReactApplicationContext com.facebook.react.ReactInstanceManager.createReactContext(com.facebook.react.bridge.JavaScriptExecutor, com.facebook.react.bridge.JSBundleLoader) (ReactInstanceManager.java:1083)
11-19 18:29:15.419 29371 29456 I art     :   at com.facebook.react.bridge.ReactApplicationContext com.facebook.react.ReactInstanceManager.access$900(com.facebook.react.ReactInstanceManager, com.facebook.react.bridge.JavaScriptExecutor, com.facebook.react.bridge.JSBundleLoader) (ReactInstanceManager.java:116)
11-19 18:29:15.419 29371 29456 I art     :   at void com.facebook.react.ReactInstanceManager$5.run() (ReactInstanceManager.java:913)
11-19 18:29:15.419 29371 29456 I art     :   at void java.lang.Thread.run() (Thread.java:762)

网上搜索发现这可能是依赖版本冲突。所以我检查了我的依赖树并注意到我正在使用的另一个模块也使用了com.google.android.gms:play-services-gcm,但版本不同。所以我更改了我的应用程序级别 build.gradle 中的版本以匹配另一个版本,但我仍然得到同样的错误。

这是我项目中的依赖树:

releaseRuntimeClasspath - Resolved configuration for runtime for variant: release
+--- com.android.support:appcompat-v7:26.1.0 -> 27.1.1
|    +--- com.android.support:support-annotations:27.1.1
|    +--- com.android.support:support-core-utils:27.1.1
|    |    +--- com.android.support:support-annotations:27.1.1
|    |    \--- com.android.support:support-compat:27.1.1
|    |         +--- com.android.support:support-annotations:27.1.1
|    |         \--- android.arch.lifecycle:runtime:1.1.0
|    |              +--- android.arch.lifecycle:common:1.1.0
|    |              \--- android.arch.core:common:1.1.0
|    +--- com.android.support:support-fragment:27.1.1
|    |    +--- com.android.support:support-compat:27.1.1 (*)
|    |    +--- com.android.support:support-core-ui:27.1.1
|    |    |    +--- com.android.support:support-annotations:27.1.1
|    |    |    +--- com.android.support:support-compat:27.1.1 (*)
|    |    |    \--- com.android.support:support-core-utils:27.1.1 (*)
|    |    +--- com.android.support:support-core-utils:27.1.1 (*)
|    |    +--- com.android.support:support-annotations:27.1.1
|    |    +--- android.arch.lifecycle:livedata-core:1.1.0
|    |    |    +--- android.arch.lifecycle:common:1.1.0
|    |    |    +--- android.arch.core:common:1.1.0
|    |    |    \--- android.arch.core:runtime:1.1.0
|    |    |         \--- android.arch.core:common:1.1.0
|    |    \--- android.arch.lifecycle:viewmodel:1.1.0
|    +--- com.android.support:support-vector-drawable:27.1.1
|    |    +--- com.android.support:support-annotations:27.1.1
|    |    \--- com.android.support:support-compat:27.1.1 (*)
|    \--- com.android.support:animated-vector-drawable:27.1.1
|         +--- com.android.support:support-vector-drawable:27.1.1 (*)
|         \--- com.android.support:support-core-ui:27.1.1 (*)
+--- com.facebook.react:react-native:+ -> 0.57.4
|    +--- com.facebook.infer.annotation:infer-annotation:0.11.2
|    |    \--- com.google.code.findbugs:jsr305:3.0.1 -> 3.0.2
|    +--- javax.inject:javax.inject:1
|    +--- com.android.support:appcompat-v7:27.1.1 (*)
|    +--- com.facebook.fresco:fresco:1.10.0
|    |    +--- com.facebook.fresco:fbcore:1.10.0
|    |    +--- com.facebook.fresco:drawee:1.10.0
|    |    |    +--- com.facebook.fresco:fbcore:1.10.0
|    |    |    \--- com.facebook.fresco:imagepipeline:1.10.0
|    |    |         +--- com.facebook.fresco:imagepipeline-base:1.10.0
|    |    |         |    +--- com.facebook.soloader:soloader:0.5.0 -> 0.5.1
|    |    |         |    +--- com.parse.bolts:bolts-tasks:1.4.0
|    |    |         |    \--- com.facebook.fresco:fbcore:1.10.0
|    |    |         +--- com.facebook.soloader:soloader:0.5.0 -> 0.5.1
|    |    |         +--- com.parse.bolts:bolts-tasks:1.4.0
|    |    |         \--- com.facebook.fresco:fbcore:1.10.0
|    |    +--- com.facebook.fresco:imagepipeline:1.10.0 (*)
|    |    \--- com.facebook.soloader:soloader:0.5.0 -> 0.5.1
|    +--- com.facebook.fresco:imagepipeline-okhttp3:1.10.0
|    |    +--- com.squareup.okhttp3:okhttp:3.10.0 -> 3.11.0
|    |    |    \--- com.squareup.okio:okio:1.14.0
|    |    +--- com.facebook.fresco:fbcore:1.10.0
|    |    \--- com.facebook.fresco:imagepipeline:1.10.0 (*)
|    +--- com.facebook.soloader:soloader:0.5.1
|    +--- com.google.code.findbugs:jsr305:3.0.2
|    +--- com.squareup.okhttp3:okhttp:3.11.0 (*)
|    +--- com.squareup.okhttp3:okhttp-urlconnection:3.11.0
|    |    \--- com.squareup.okhttp3:okhttp:3.11.0 (*)
|    +--- com.squareup.okio:okio:1.14.0
|    \--- org.webkit:android-jsc:r174650
+--- project :react-native-ble-manager
|    \--- com.facebook.react:react-native:[0.30.0,) -> 0.57.4 (*)
+--- project :react-native-camera
|    +--- com.google.zxing:core:3.3.0
|    +--- com.drewnoakes:metadata-extractor:2.9.1
|    |    \--- com.adobe.xmp:xmpcore:5.1.2
|    +--- com.google.android.gms:play-services-vision:11.0.4
|    |    +--- com.google.android.gms:play-services-base:[11.0.4] -> 16.0.1
|    |    |    +--- com.google.android.gms:play-services-basement:16.0.1
|    |    |    |    \--- com.android.support:support-v4:26.1.0
|    |    |    |         +--- com.android.support:support-compat:26.1.0 -> 27.1.1 (*)
|    |    |    |         +--- com.android.support:support-media-compat:26.1.0
|    |    |    |         |    +--- com.android.support:support-annotations:26.1.0 -> 27.1.1
|    |    |    |         |    \--- com.android.support:support-compat:26.1.0 -> 27.1.1 (*)
|    |    |    |         +--- com.android.support:support-core-utils:26.1.0 -> 27.1.1 (*)
|    |    |    |         +--- com.android.support:support-core-ui:26.1.0 -> 27.1.1 (*)
|    |    |    |         \--- com.android.support:support-fragment:26.1.0 -> 27.1.1 (*)
|    |    |    \--- com.google.android.gms:play-services-tasks:16.0.1
|    |    |         \--- com.google.android.gms:play-services-basement:16.0.1 (*)
|    |    +--- com.google.android.gms:play-services-basement:[11.0.4] -> 16.0.1 (*)
|    |    \--- com.google.android.gms:play-services-vision-common:[11.0.4] -> 11.0.4
|    |         +--- com.google.android.gms:play-services-base:[11.0.4] -> 16.0.1 (*)
|    |         \--- com.google.android.gms:play-services-basement:[11.0.4] -> 16.0.1 (*)
|    +--- com.android.support:exifinterface:26.1.0
|    |    \--- com.android.support:support-annotations:26.1.0 -> 27.1.1
|    +--- com.android.support:support-annotations:26.1.0 -> 27.1.1
|    \--- com.android.support:support-v4:26.1.0 (*)
+--- project :react-native-vector-icons
|    \--- com.facebook.react:react-native:+ -> 0.57.4 (*)
+--- project :react-native-maps
|    +--- com.google.android.gms:play-services-base:11.0.4 -> 16.0.1 (*)
|    +--- com.google.android.gms:play-services-maps:11.0.4
|    |    +--- com.google.android.gms:play-services-base:[11.0.4] -> 16.0.1 (*)
|    |    \--- com.google.android.gms:play-services-basement:[11.0.4] -> 16.0.1 (*)
|    \--- com.google.maps.android:android-maps-utils:0.5+ -> 0.5
+--- project :react-native-push-notification
|    +--- com.android.support:appcompat-v7:26.1.0 -> 27.1.1 (*)
|    +--- com.facebook.react:react-native:+ -> 0.57.4 (*)
|    +--- com.google.android.gms:play-services-gcm:11.0.4
|    |    +--- com.google.android.gms:play-services-base:[11.0.4] -> 16.0.1 (*)
|    |    +--- com.google.android.gms:play-services-basement:[11.0.4] -> 16.0.1 (*)
|    |    \--- com.google.android.gms:play-services-iid:[11.0.4] -> 11.0.4
|    |         +--- com.google.android.gms:play-services-base:[11.0.4] -> 16.0.1 (*)
|    |         \--- com.google.android.gms:play-services-basement:[11.0.4] -> 16.0.1 (*)
|    +--- me.leolin:ShortcutBadger:1.1.8
|    \--- com.google.firebase:firebase-messaging:+ -> 17.3.4
|         +--- com.google.android.gms:play-services-basement:16.0.1 (*)
|         +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|         +--- com.google.firebase:firebase-common:16.0.3
|         |    +--- com.google.android.gms:play-services-basement:16.0.1 (*)
|         |    \--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|         +--- com.google.firebase:firebase-iid:[17.0.4] -> 17.0.4
|         |    +--- com.google.android.gms:play-services-basement:16.0.1 (*)
|         |    +--- com.google.android.gms:play-services-stats:16.0.1
|         |    |    \--- com.google.android.gms:play-services-basement:16.0.1 (*)
|         |    +--- com.google.android.gms:play-services-tasks:16.0.1 (*)
|         |    +--- com.google.firebase:firebase-common:16.0.3 (*)
|         |    \--- com.google.firebase:firebase-iid-interop:16.0.1
|         |         +--- com.google.android.gms:play-services-base:16.0.1 (*)
|         |         \--- com.google.android.gms:play-services-basement:16.0.1 (*)
|         \--- com.google.firebase:firebase-measurement-connector:17.0.1
|              \--- com.google.android.gms:play-services-basement:16.0.1 (*)
+--- com.google.android.gms:play-services-gcm:11.0.4 (*)
\--- project :react-native-barcode-scanner-google
     +--- com.google.android.gms:play-services-vision:11.0.4 (*)
     \--- com.facebook.react:react-native:0.20.+ -> 0.57.4 (*)

我看到有一些不匹配的版本,但我真的不知道如何正确跟踪或更正它们。

这是我的 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 = 19
        compileSdkVersion = 27
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}

allprojects {
    repositories {
        google()
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

ext {
    compileSdkVersion   = 26
    targetSdkVersion    = 26
    buildToolsVersion   = "26.0.2"
    supportLibVersion   = "26.1.0"
    googlePlayServicesVersion = "11.0.4"
    androidMapsUtilsVersion = "0.5+"
}

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

// Application level
apply plugin: "com.android.application"

import com.android.build.OutputFile

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

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 "com.dpassapp"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    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"
        }
    }
    // 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 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-ble-manager')
    implementation project(':react-native-camera')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-maps')

    implementation project(':react-native-push-notification')
    implementation ('com.google.android.gms:play-services-gcm:11.0.4') {
        force = true;
    }

    implementation project(':react-native-barcode-scanner-google')
}

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

有谁知道我会错过什么?或者如何正确调试依赖版本冲突?

4

3 回答 3

0

这样做可能会对您有所帮助:

react-native link

react-native link (your dependency name)

像这样 :

react-native link react-native-push-notification

我有像你这样的问题,这对我有帮助

祝你好运

于 2018-11-20T14:07:24.943 回答
0

在依赖版本冲突(例如 Google Play 服务)中,最好的办法是像您所做的那样修复顶级 gradle 中的依赖关系,然后从冲突库中排除依赖关系。

compile(project(":react-native-push-notification")){ exclude group: "com.google.android.gms" }

但是,请确保与所有依赖项兼容的正确版本已在顶级 gradle 中修复。

于 2018-11-21T07:17:50.003 回答
0

我发现我的应用程序崩溃有 2 个(类似的)原因。

  1. 我有需要不同版本的android支持库的依赖项
  2. 我的依赖项需要不同版本的谷歌服务库

第一个更容易修复。但是我很难弄清楚为什么我不能将所有谷歌服务强制使用相同的版本,我不断收到错误消息,指出在存储库中找不到库。问题不是所有依赖项都具有相同的次要/补丁版本(如此所列)。

例如:com.google.android.gms:play-services-base 最新版本是 16.0.1(甚至没有 16.0.0),而 com.google.android.gms:play.services.maps 最新版本是 16.0 .0. 所以如果我对这些版本中的任何一个进行硬编码,另一个会抛出一个未找到的错误。

为了解决这个问题,我不得不强制所有谷歌服务库使用相同的主要版本,这样它就可以为每个库获取正确的版本。

将这些行添加到我的顶级 build.gradle 解决了它:

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->

            // force all android support dependencies to 27.1.1
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "27.1.1"
            }

            // force all google services libraries to the same latest major version
            if(details.requested.group == 'com.google.android.gms') {
                details.useVersion '16.+'
            }
        }
    }
}
于 2018-11-23T15:54:56.683 回答