React Native:Firebase 性能插件在 Android 中复制了 com.reactnativecommunity.geolocation.BuildConfig

如何解决React Native:Firebase 性能插件在 Android 中复制了 com.reactnativecommunity.geolocation.BuildConfig

我的 react-native 项目(没有 Expo)运行良好。但是,一旦我安装了 @react-native-firebase/perf,我的 Android 构建就失败了。我按照所有说明操作,iOS 运行良好。

这是我得到的错误:

Type com.reactnativecommunity.geolocation.BuildConfig is defined multiple times: myProject/android/app/build/intermediates/transforms/FirebasePerformancePlugin/dev/debug/156.jar:com/reactnativecommunity/geolocation/BuildConfig.class,myProject/android/app/build/intermediates/transforms/FirebasePerformancePlugin/dev/debug/163.jar:com/reactnativecommunity/geolocation/BuildConfig.class

这是我的代码:

package.json:

{
  "name": ...,"version": "0.0.1","private": true,"scripts": {
    "android": "react-native run-android","ios": "react-native run-ios","start": "react-native start","test": "jest","test:watch": "jest --watch","precommit": "lint-staged","compile": "tsc --noEmit -p . --pretty","format": "npm-run-all format:*","format:js": "prettier --write {.,**}/*.js","format:json": "prettier --write {.,**}/*.json","format:md": "prettier --write {.,**}/*.md","format:ts": "prettier --write {.,**}/*.{ts,tsx}","hack:types-react-navigation": "rimraf node_modules/@types/react-navigation/node_modules/@types","hack:types-react-native": "rimraf node_modules/@types/react-native/node_modules/@types","hack:types-react-test-renderer": "rimraf node_modules/@types/react-test-renderer/node_modules/@types","lint": "eslint index.js app/ --ext .js,.ts,.tsx","patch": "patch-package","postinstall": "node ./bin/postInstall","prepare": "npm-run-all patch hack:*","storybook": "start-storybook -p 9001 -c ./storybook","adb": "adb reverse tcp:9090 tcp:9090 && adb reverse tcp:3000 tcp:3000 && adb reverse tcp:9001 tcp:9001 && adb reverse tcp:8081 tcp:8081"
  },"dependencies": {
    "@mdi/font": "^5.0.45","@ptomasroos/react-native-multi-slider": "^2.2.2","@react-native-community/async-storage": "^1.5.1","@react-native-community/eslint-config": "^2.0.0","@react-native-community/geolocation": "^2.0.2","@react-native-community/masked-view": "0.1.5","@react-native-community/push-notification-ios": "^1.2.2","@react-native-community/slider": "^3.0.3","@react-native-firebase/analytics": "^11.2.0","@react-native-firebase/app": "^11.2.0","@react-native-firebase/crashlytics": "^11.2.0","@react-native-firebase/dynamic-links": "^11.2.0","@react-native-firebase/in-app-messaging": "^11.2.0","@react-native-firebase/messaging": "^11.2.0","@react-native-firebase/perf": "^11.2.0","@react-navigation/native": "^5.1.3","@types/enzyme": "^3.10.8","@types/lodash": "^4.14.168","@types/react-native-snap-carousel": "^3.8.2","@types/semver": "^7.3.4","@typescript-eslint/eslint-plugin-tslint": "^4.20.0","apisauce": "1.0.3","axios": "^0.19.2","formik": "^2.1.4","fractional": "^1.0.0","i18n-js": "^3.0.11","ignite-cli": "^3.5.1","lodash": "^4.17.15","lodash.throttle": "4.1.1","mobx": "^4.13.0","mobx-react-lite": "^1.4.1","mobx-state-tree": "^3.15.0","moment": "^2.24.0","ramda": "0.26.1","react": "16.9.0","react-native": "0.61.2","react-native-auth0": "2.3.0","react-native-datepicker": "^1.7.2","react-native-device-info": "^8.0.7","react-native-document-picker": "^4.0.0","react-native-dotenv": "^0.2.0","react-native-dropdown-autocomplete": "^1.0.18","react-native-elements": "^3.3.2","react-native-fbsdk": "^3.0.0","react-native-flash-message": "^0.1.15","react-native-formik": "^1.7.8","react-native-gesture-handler": "^1.5.0","react-native-keyboard-accessory": "^0.1.11","react-native-keyboard-aware-scroll-view": "^0.9.1","react-native-keychain": "3.1.3","react-native-localize": "^1.0.0","react-native-material-dropdown": "^0.11.1","react-native-material-textfield": "^0.16.1","react-native-material-ui": "^1.30.1","react-native-multiple-select": "^0.5.5","react-native-paper": "^4.6.0","react-native-pie-chart": "^1.0.13","react-native-push-notification": "^3.5.2","react-native-radio-buttons-group": "^1.0.7","react-native-reanimated": "^1.13.2","react-native-safe-area-context": "^3.2.0","react-native-safe-area-view": "1.0.0","react-native-screens": "^2.0.0-alpha.6","react-native-splash-screen": "^3.2.0","react-native-vector-icons": "^7.1.0","react-native-webview": "^10.9.2","react-navigation": "4.0.10","react-navigation-drawer": "^2.6.0","react-navigation-stack": "2.0.9","react-navigation-tabs": "^2.10.1","react-redux": "^7.2.0","reactotron-mst": "^3.1.1","redux": "^4.0.5","semver": "^6.3.0","smartlook-react-native-wrapper": "^0.39.0","validate.js": "0.13.1","yup": "^0.28.3"
  },"devDependencies": {
    "@babel/core": "^7.13.14","@babel/plugin-proposal-decorators": "^7.0.0","@babel/plugin-proposal-optional-catch-binding": "^7.0.0","@babel/runtime": "^7.13.10","@storybook/addon-storyshots": "5.2.8","@storybook/react-native": "5.2.8","@storybook/react-native-server": "5.2.8","@types/i18n-js": "^3.8.0","@types/jest": "24.0.18","@types/ramda": "0.26.18","@types/react": "16.8.24","@types/react-native": "0.60.19","@types/react-native-dotenv": "^0.2.0","@types/react-test-renderer": "16.8.3","@typescript-eslint/eslint-plugin": "^4.20.0","@typescript-eslint/parser": "^4.20.0","babel-jest": "^24.1.0","enzyme": "^3.11.0","enzyme-adapter-react-16": "^1.15.2","eslint": "^7.23.0","eslint-config-airbnb": "^18.2.1","eslint-config-airbnb-typescript": "^12.3.1","eslint-config-prettier": "^6.15.0","eslint-config-standard": "^13.0.1","eslint-plugin-import": "^2.22.1","eslint-plugin-jsx-a11y": "^6.4.1","eslint-plugin-node": "^9.1.0","eslint-plugin-promise": "^4.0.1","eslint-plugin-react": "^7.22.0","eslint-plugin-react-hooks": "^4.2.0","eslint-plugin-react-native": "^3.6.0","eslint-plugin-standard": "^4.0.0","husky": "^4.2.3","ignite-bowser": "^4.13.0","jest": "^24.9.0","jetifier": "^1.6.1","lint-staged": "^10.0.8","metro-react-native-babel-preset": "^0.51.1","npm-run-all": "4.1.5","patch-package": "6.1.2","postinstall-prepare": "1.0.1","prettier": "^1.19.1","react-devtools-core": "3.6.3","react-powerplug": "1.0.0","react-test-renderer": "^16.8.1","reactotron-react-native": "^4.0.3","redux-devtools": "^3.5.0","rimraf": "2.6.3","solidarity": "2.3.1","typescript": "3.5.3"
  },"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },"lint-staged": {
    "./app/*.{ts,tsx}": [
      "npx prettier --write","eslint ./app/*.{ts,tsx} --quiet --fix-dry-run"
    ]
  },"eslintIgnore": [
    "!.*","ios","android","node_modules/*"
  ],"jest": {
    "preset": "react-native","setupFiles": [
      "<rootDir>/test/set-up.ts","<rootDir>/node_modules/react-native/jest/setup.js","<rootDir>/test/setup.ts","./node_modules/react-native-gesture-handler/jestSetup.js"
    ],"testPathIgnorePatterns": [
      "/node_modules/","/e2e"
    ],"transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-native|react-navigation|@react-navigation|@storybook|@react-native-community)"
    ]
  }
}

android/build.gradle:

buildscript {
    ext {
        buildToolsVersion = "28.0.3"
        minSdkVersion = 16
        compileSdkVersion = 29
        targetSdkVersion = 29
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.6.4')
        classpath 'com.google.gms:google-services:4.3.5'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.2'
        classpath 'com.google.firebase:perf-plugin:1.3.5'
    }
}

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion rootProject.ext.compileSdkVersion
                buildToolsVersion rootProject.ext.buildToolsVersion
            }
        }
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS,Obj-C sources,Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }
        maven {
            url "https://sdk.smartlook.com/android/release"
        }
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

android/app/build.gradle:

apply plugin: "com.android.application"
apply plugin: "com.google.gms.google-services"
apply plugin: "com.google.firebase.crashlytics"
apply plugin: 'com.google.firebase.firebase-perf'

import com.android.build.OutputFile project.ext.react = [
entryFile: "index.js",enableHermes: false,// clean and rebuild if changing
]

apply from: "../../node_modules/react-native/react.gradle"
enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false
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 ...
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 55
        versionName "1.14.2"
        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 {
        release {
            ...
        }
        debug {
            ...
        }
    }
    buildTypes {
        debug {
            signingConfig signingConfigs.debug
        }
        release {
            signingConfig signingConfigs.release
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"),"proguard-rules.pro"
        }

    }
    flavorDimensions "env"
   productFlavors {
        dev {
            ...
        }
        prod {
            ...
        }
    }
    applicationVariants.all { variant ->
        variant.outputs.each { output ->
            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 project(':react-native-fbsdk')
    implementation project(':@react-native-community_geolocation')
    implementation project(':react-native-vector-icons')
    implementation project(':react-native-device-info')
    implementation project(':react-native-splash-screen')

    implementation 'com.android.support:multidex:1.0.3'
    implementation project(':react-native-webview')
    implementation project(':react-native-auth0')
    implementation fileTree(dir: "libs",include: ["*.jar"])
    implementation platform('com.google.firebase:firebase-bom:26.4.0')
    implementation "com.facebook.react:react-native:+"  // From node_modules
    implementation 'com.google.firebase:firebase-analytics:18.0.3'
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-inappmessaging-display'
    implementation 'com.google.firebase:firebase-messaging:21.1.0'
    implementation 'com.facebook.android:facebook-android-sdk:8.2.0'
    implementation 'com.google.firebase:firebase-perf'
    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

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)

这是我得到的错误:

Type com.reactnativecommunity.geolocation.BuildConfig is defined multiple times: myProject/android/app/build/intermediates/transforms/FirebasePerformancePlugin/dev/debug/156.jar:com/reactnativecommunity/geolocation/BuildConfig.class,myProject/android/app/build/intermediates/transforms/FirebasePerformancePlugin/dev/debug/163.jar:com/reactnativecommunity/geolocation/BuildConfig.class

我已经将 multiDexEnabled 设为 true,我已经尝试清理、重建、使缓存无效并重新启动...但没有任何效果。我还尝试手动删除重复的文件。但是,当我重建项目时,这些文件会自动再次创建。

我能做什么?

解决方法

我已经解决了!这些是我遵循的步骤:

  • 运行react-native unlink @react-native-community/geolocation
  • 运行:
rm -rf android/.gradle
rm -rf .gradle
rm -rf ~/.gradle
./gradlew clean
  • 最后,转到 Android Studio 并Build -> Clean

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-