类型io.invertase.firebase.BuildConfig被定义多次

问题描述 投票:0回答:3

我正在尝试在 VSCode 中构建一个 React Native 应用程序。当我尝试构建应用程序时,出现以下错误。在完成构建时,我不断遇到以下问题。我尝试更改 firebase 版本和 Gradle 更新,但没有成功。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeDexRelease'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 
     Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
     Type io.invertase.firebase.BuildConfig is defined multiple times: /path/node_modules/@react-native-firebase/app/android/build/.transforms/7d2ce1f5b074ed872b704906f3d41618/classes/classes.dex, /path/node_modules/react-native-firebase/android/build/.transforms/0b00760c914c9cf3e84f7c87e9135514/classes/classes.dex

BUILD FAILED in 3m 50s

`app/build.gradle` 如下所示
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'

import com.android.build.OutputFile;
// import androidx.core.content.FileProvider;

project.ext.react = [
    enableHermes: false,  // clean and rebuild if changing
]

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

def jscFlavor = 'org.webkit:android-jsc:+'

def enableHermes = project.ext.react.get("enableHermes", false);

android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.odotime"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 40
        versionName "1.41"
        multiDexEnabled true
    }
    splits {
        abi {
            reset()
            enable enableSeparateBuildPerCPUArchitecture
            universalApk false  // If true, also generate a universal APK
            include "armeabi-v7a", "x86", "arm64-v8a", "x86_64"
        }
    }
    signingConfigs {
        debug {
            storeFile file('debug.keystore')
            storePassword 'android'
            keyAlias 'androiddebugkey'
            keyPassword 'android'
        }
        release {
            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {
                storeFile file(MYAPP_UPLOAD_STORE_FILE)
                storePassword MYAPP_UPLOAD_STORE_PASSWORD
                keyAlias MYAPP_UPLOAD_KEY_ALIAS
                keyPassword MYAPP_UPLOAD_KEY_PASSWORD
            }
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            // Caution! In production, you need to generate your own keystore file.
            // see https://reactnative.dev/docs/signed-apk-android.
            signingConfig signingConfigs.debug
            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:
            // https://developer.android.com/studio/build/configure-apk-splits.html
            def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4]
            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"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules

    // Import the Firebase BoM
    implementation platform('com.google.firebase:firebase-bom:28.0.1') 
    
    compile project(':react-native-sms-retriever')
    
    // Declare the dependency for the Firebase SDK for Google Analytics
    implementation 'com.google.firebase:firebase-analytics:18.0.3'

    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'com.android.support:multidex:1.0.3'
    implementation "com.android.support:support-v4:22.1.0"
    implementation 'com.android.support:design:27.1.0'

    implementation project(':react-native-push-notification')

    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }

    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }

    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }

    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

// 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: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

package.json
如下

"dependencies": {
    "@capacitor/android": "^3.6.0",
    "@capacitor/core": "^3.6.0",
    "@react-native-community/art": "^1.2.0",
    "@react-native-community/async-storage": "^1.12.0",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/netinfo": "^5.9.6",
    "@react-native-community/push-notification-ios": "^1.8.0",
    "@react-native-firebase/app": "^12.1.0",
    "@react-native-firebase/messaging": "^12.1.0",
    "@react-navigation/bottom-tabs": "^5.8.0",
    "@react-navigation/material-bottom-tabs": "^5.2.16",
    "@react-navigation/native": "^5.7.3",
    "@react-navigation/stack": "^5.9.0",
    "amazon-cognito-identity-js": "^4.3.3",
    "aws-amplify": "^3.0.23",
    "axios": "^0.20.0",
    "cordova-plugin-androidx-adapter": "^1.1.3",
    "i18n-js": "^3.7.1",
    "jetifier": "^2.0.0",
    "lodash.memoize": "^4.1.2",
    "moment": "^2.29.1",
    "moment-range": "^4.0.2",
    "moment-timezone": "^0.5.33",
    "react": "16.13.1",
    "react-devtools": "^4.8.2",
    "react-native": "0.63.2",
    "react-native-calendars": "^1.343.0",
    "react-native-contacts": "^6.0.3",
    "react-native-country-picker-modal": "^2.0.0",
    "react-native-date-picker": "^3.2.3",
    "react-native-drop-shadow": "^0.0.2",
    "react-native-dropdown-picker": "^3.7.1",
    "react-native-email-link": "^1.11.3",
    "react-native-firebase": "^5.6.0",
    "react-native-gesture-handler": "^1.7.0",
    "react-native-hyperlinked-text": "^1.0.2",
    "react-native-image-picker": "^2.3.4",
    "react-native-loading-spinner-overlay": "^1.1.0",
    "react-native-localize": "^2.0.1",
    "react-native-paper": "^4.1.0",
    "react-native-pie": "^1.1.2",
    "react-native-push-notification": "^7.3.1",
    "react-native-raw-bottom-sheet": "^2.2.0",
    "react-native-reanimated": "^1.13.0",
    "react-native-safe-area-context": "^3.1.6",
    "react-native-screens": "^2.10.1",
    "react-native-sectioned-multi-select": "^0.8.1",
    "react-native-simple-radio-button": "^2.7.4",
    "react-native-simple-toast": "^1.1.2",
    "react-native-sms-retriever": "^1.1.1",
    "react-native-svg-transformer": "^0.14.3",
    "react-native-switch-selector": "^2.0.6",
    "react-native-vector-icons": "^7.1.0",
    "react-redux": "^7.2.1",
    "redux": "^4.0.5",
    "redux-form": "^8.3.6",
    "redux-persist": "^6.0.0",
    "redux-persist-transform-filter": "0.0.20",
    "redux-saga": "^1.1.3",
    "reselect": "^4.0.0",
    "save": "^2.4.0",
    "toggle-switch-react-native": "^2.3.0"
  },
  "devDependencies": {
    "@babel/core": "^7.8.4",
    "@babel/runtime": "^7.8.4",
    "@capacitor/cli": "^3.6.0",
    "@react-native-community/eslint-config": "^1.1.0",
    "babel-jest": "^25.1.0",
    "eslint": "^6.8.0",
    "jest": "^25.1.0",
    "metro-react-native-babel-preset": "^0.59.0",
    "react-test-renderer": "16.13.1",
    "remote-redux-devtools": "^0.5.16"
  },
java android firebase react-native build
3个回答
4
投票

当我们尝试让多个包一起编译时重叠时,就会发生这种情况。当我们使用一些旧版本的软件包时,这是一个非常常见的问题。

当用户尝试安装和使用

@react-native-firebase/app
react-native-firebase
时,会发生此特定实例。我使用旧版本的
react-native-firebase
进行推送通知,但根据我的知识和经验,
@react-native-firebase/app
涵盖了这一点。因此,删除
react-native-firebase
并执行
npm i
然后构建对我来说很有效。

在一般情况下,我们必须逐个包检查每个包,并检查哪个包导致了重叠,然后将其删除或在开发和构建中为该包找到一些替代方案。


4
投票

就我而言,我发现这是一个终极错误。

在我的 package.json 文件中,我在早些时候安装了 @react-native-firebase/appreact-native-firebase 软件包。

似乎聪明的自动导入/链接将这两者都带入了 Android 项目(正如它应该的那样),这导致了重复的类错误。我删除了 @react-native-firebase/ 软件包,现在我的大部分问题都已解决。

它对我有用


1
投票

当用户尝试安装和使用

@react-native-firebase/app
react-native-firebase
时,会发生此特定实例。我使用旧版本的react-native-firebase来推送通知,但据我的知识和经验
@react-native-firebase/app
涵盖了这一点。

© www.soinside.com 2019 - 2024. All rights reserved.