【问题标题】:React native Amplify AWS package conflicting firebase反应原生 Amplify AWS 包与火力库冲突
【发布时间】:2019-09-15 07:16:21
【问题描述】:

在我之前的 react native 项目中,我添加了 aws amplify 用于推送通知。之后我想做分析,所以我添加了 firebase。之后,我的 android 应用程序构建,但一启动就停止。

我得到错误

java.lang.RuntimeException:无法实例化服务 com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService: java.lang.ClassNotFoundException:找不到类 "com.amazonaws.amplify.pushnotification.RNPushNotificationMessagingService

抑制:java.lang.NoClassDefFoundError:解析失败: Lcom/google/firebase/messaging/FirebaseMessagingService; 在 java.lang.VMClassLoader.findLoadedClass(本机方法) 在 java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738) 在 java.lang.ClassLoader.loadClass(ClassLoader.java:363) ... 10 更多 引起:java.lang.ClassNotFoundException: com.google.firebase.messaging.FirebaseMessagingService

我的app/build.gradle

apply plugin: "com.android.application"

import com.android.build.OutputFile

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

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

/**
 * Set this to true to create two separate APKs instead of one:
 *   - An APK that only works on ARM devices
 *   - An APK that only works on x86 devices
 * The advantage is the size of the APK is reduced by about 4MB.
 * Upload all the APKs to the Play Store and people will download
 * the correct one based on the CPU architecture of their device.
 */
def enableSeparateBuildPerCPUArchitecture = false

/**
 * Run Proguard to shrink the Java bytecode in release builds.
 */
def enableProguardInReleaseBuilds = false

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

    packagingOptions {
        pickFirst 'lib/x86_64/libjsc.so'
        pickFirst 'lib/x86_64/libc++_shared.so'
        pickFirst 'lib/x86/libc++_shared.so'
        pickFirst 'lib/arm64-v8a/libjsc.so'
        pickFirst 'lib/arm64-v8a/libc++_shared.so'
        pickFirst 'lib/armeabi-v7a/libc++_shared.so'
    }

    defaultConfig {
        applicationId "com.project”
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 2
        versionName "1.1"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
        manifestPlaceholders = [
                appAuthRedirectScheme: 'com.project’
        ]
    }
    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 {
    implementation project(':react-native-firebase')
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-reanimated')
    implementation project(':@react-native-community_netinfo')
    compile project(':react-native-charts-wrapper')
    compile project(':rn-fetch-blob')
    compile project(':react-native-wheel-picker')
    compile project(':react-native-vector-icons')
    compile project(':react-native-pdf')
    compile project(':react-native-app-auth')
    compile project(':@aws-amplify_pushnotification')
    implementation (project(':react-native-device-info')){
        exclude group: "com.google.android.gms" 
        exclude group: "com.android.support"
    }
    implementation project(':react-native-wheel-picker')
    implementation project(':react-native-vector-icons')
    implementation project(':amazon-cognito-identity-js')
    implementation project(':@aws-amplify_pushnotification')
    implementation project(':react-native-app-auth')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules
    // Firebase dependencies
    implementation "com.google.android.gms:play-services-base:16.1.0"
    implementation "com.google.firebase:firebase-core:16.0.9"
}

// 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 plugin: 'com.google.gms.google-services'
//com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true

【问题讨论】:

    标签: java android firebase react-native


    【解决方案1】:

    您必须使用编译或实现,而不是两者。删除这些行。

    compile project(':react-native-wheel-picker')
    compile project(':@aws-amplify_pushnotification')
    compile project(':react-native-vector-icons')
    compile project(':react-native-app-auth')
    

    【讨论】:

      【解决方案2】:

      当您设置 AWS Amplify 推送通知时,您必须首先设置一个 Firebase project,AWS Amplify 将连接到该Firebase project

      您可以在 Firebase 项目设置过程中Enable Google Analytics

      然后在android/app/build.gradle 中包含implementation 'com.google.firebase:firebase-analytics:17.2.1' 行。

      我有created a walkthrough for the Firebase setup process for AWS Amplify,包含各个步骤的图像。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-21
        • 2020-08-26
        • 1970-01-01
        • 1970-01-01
        • 2014-03-10
        • 2020-06-20
        • 1970-01-01
        • 2018-10-03
        相关资源
        最近更新 更多