Estoy creando una aplicación usando react-native. Hasta ahora he implementado algunos módulos como react-native-camera y react-native-maps.

Todo funcionaba bien hasta que intenté implementar react-native-push-notification.

Seguí su implementación usando este tutorial, pero ahora, aunque la aplicación se construye con éxito, se bloquea al iniciarse.

Este es mi logcat (en realidad está recortado porque no encajaría aquí)

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)

Al buscar en línea, descubrí que esto podría ser un conflicto de versión de dependencia. Así que revisé mi árbol de dependencias y noté que había otro módulo que estaba usando que también usa com.google.android.gms:play-services-gcm, pero en una versión diferente. Así que cambié la versión en el nivel de mi aplicación build.gradle para que coincida con la otra versión, pero sigo teniendo el mismo error.

Este es el árbol de dependencias de mi proyecto:

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

Veo que hay algunas versiones que no coinciden, pero realmente no sé cómo rastrearlas o corregirlas correctamente.

Este es mi 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'
}

¿Alguien sabe qué podría estar perdiendo? ¿O cómo depurar correctamente los conflictos de versión de dependencia?

1
Thiago Loddi 19 nov. 2018 a las 23:48

3 respuestas

La mejor respuesta

Descubrí que había 2 razones (similares) por las que mi aplicación fallaba.

  1. Tenía dependencias que requerían diferentes versiones de la biblioteca de soporte de Android
  2. Tenía dependencias que requerían diferentes versiones de las bibliotecas de servicios de google

El primero fue más fácil de arreglar. Pero me costó mucho descubrir por qué no podía forzar a todos los servicios de Google a la misma versión, seguía recibiendo mensajes de error de que las bibliotecas no se podían encontrar en el repositorio. El problema no era que todas las dependencias tienen las mismas versiones menores / parche (como se enumera aquí).

Por ejemplo: com.google.android.gms: la última versión de play-services-base es 16.0.1 (ni siquiera tiene 16.0.0), mientras que com.google.android.gms: play.services.maps la última versión es 16.0 .0. Entonces, si codifico alguna de estas versiones, la otra arrojaría un error no encontrado.

Para resolver esto, tuve que forzar a todas las bibliotecas de servicios de Google a la misma versión principal, para que pudiera obtener la versión correcta para cada una.

Agregar estas líneas a mi build.gradle de nivel superior lo resolvió:

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.+'
            }
        }
    }
}
0
Thiago Loddi 23 nov. 2018 a las 15:54

Hacer esto puede ayudarte:

react-native link

Y

react-native link (your dependency name)

Me gusta esto :

react-native link react-native-push-notification

Tengo un problema como el tuyo y esto me ayudó

Buena suerte

0
MoHammaD ReZa DehGhani 20 nov. 2018 a las 14:07

En los conflictos de versiones de dependencia (como los Servicios de Google Play), lo mejor que puede hacer es corregir la dependencia en el nivel superior como lo ha hecho y luego excluir la dependencia de las bibliotecas en conflicto.

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

Sin embargo, asegúrese de que la versión adecuada compatible con todas las dependencias esté fijada en el nivel superior.

0
Miyuru Sagarage 21 nov. 2018 a las 07:17