在 Android 版本中 React Native :app:transformDexArchiveWithExternalLibsDexMergerForDebug 错误 [英] React Native :app:transformDexArchiveWithExternalLibsDexMergerForDebug error in Android build

查看:69
本文介绍了在 Android 版本中 React Native :app:transformDexArchiveWithExternalLibsDexMergerForDebug 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试构建我成功构建的项目时,但现在出现此错误

<代码>>任务 :app:transformDexArchiveWithExternalLibsDexMergerForDebug 失败D8:程序类型已经存在:android.support.v4.os.ResultReceiver$1

我需要构建我的项目来应用新的包,但是在做的时候,firebase 包给了我错误,所以我升级了它们然后我在这里..我在谷歌中尝试了 %90 的所有建议解决方案,但没有一个工作..

<块引用>

android/build.gradle

buildscript {分机{buildToolsVersion = "27.0.3"minSdkVersion = 22compileSdkVersion = 28目标SDK版本= 27supportLibVersion = "27.1.1"}存储库{谷歌()行家本地()MavenCentral()jcenter()}依赖{类路径 'com.android.tools.build:gradle:3.2.0'类路径 'com.google.gms:google-services:4.0.1'//注意:不要将您的应用程序依赖项放在这里;他们属于//在单独的模块 build.gradle 文件中}}所有项目{存储库{谷歌()行家本地()MavenCentral()jcenter()行家{//所有 React Native(JS、Obj-C 源代码、Android 二进制文件)都是从 npm 安装的url "$rootDir/../node_modules/react-native/android"}maven { url 'https://jitpack.io' }}}任务包装器(类型:包装器){gradleVersion = '4.4'distributionUrl = distributionUrl.replace("bin", "all")}子项目 { 子项目 ->后评价{if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {安卓 {变体过滤器 { 变体 ->定义名称=变体.flavors*.nameif (names.contains("reactNative51") || names.contains("reactNative55")) {设置忽略(真)}}}}}}

<块引用>

android/app/build.gradle

buildscript {存储库{maven { url 'https://plugins.gradle.org/m2/' }//Gradle 插件门户}依赖{类路径 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'}}应用插件:'com.onesignal.androidsdk.onesignal-gradle-plugin'应用插件:com.android.application"导入 com.android.build.OutputFile项目.ext.react = [条目文件:配置文件.js"]申请自:../../node_modules/react-native/react.gradle"def enableProguardInReleaseBuilds = false安卓 {compileSdkVersion rootProject.ext.compileSdkVersionbuildToolsVersion rootProject.ext.buildToolsVersion默认配置{applicationId "com.xx"minSdkVersion rootProject.ext.minSdkVersiontargetSdkVersion rootProject.ext.targetSdkVersionmissingDimensionStrategy "RNN.reactNativeVersion", "reactNative57"版本代码 1版本名称1.0"ndk{abiFilters "armeabi-v7a", "x86"}}签名配置{释放 {如果(project.hasProperty('MYAPP_RELEASE_STORE_FILE')){存储文件文件(MYAPP_RELEASE_STORE_FILE)商店密码 MYAPP_RELEASE_STORE_PASSWORDkeyAlias MYAPP_RELEASE_KEY_ALIAS密钥密码 MYAPP_RELEASE_KEY_PASSWORD}}}编译选项{sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}分裂{阿比{重启()启用 enableSeparateBuildPerCPUArchitectureUniversalApk false//如果为 true,也生成一个通用 APK包括armeabi-v7a"、x86"}}构建类型{释放 {minifyEnabled enableProguardInReleaseBuildsproguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"签名配置signingConfigs.release}}//applicationVariants 是例如调试,发布applicationVariants.all { 变体 ->variant.outputs.each { 输出 ->//对于每个架构的每个单独的 APK,设置一个唯一的版本代码,如下所述://http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splitsdef versionCodes = ["armeabi-v7a":1, "x86":2]def abi = output.getFilter(OutputFile.ABI)if (abi != null) {//通用调试、通用发布变体为空output.versionCodeOverride =versionCodes.get(abi) * 1048576 + defaultConfig.versionCode}}}}依赖{实施项目(':react-native-image-picker')实施项目(':react-native-sound')实施项目(':react-native-onesignal')实施项目(':react-native-svg')实施项目(':react-native-device-info')实施项目(':react-native-firebase')实现('com.google.firebase:firebase-core:17.0.0'){排除组:'com.android.support'}实现('com.google.firebase:firebase-database:17.0.0'){排除组:'com.android.support'}实现文件树(目录:库",包括:[*.jar"])实现com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"实现 "com.facebook.react:react-native:+"//来自 node_modules实施项目(':react-native-navigation')实现 'com.android.support:design:27.1.0'}//运行一次,以便能够使用 BUCK 运行应用程序//将所有编译依赖项放入文件夹 libs 以供 BUCK 使用任务 copyDownloadableDepsToLibs(类型:复制){从configuration.compile进入库"}应用插件:'com.google.gms.google-services'

<块引用>

package.json

<代码>{"name": "xxx",版本":0.0.1",私人":真的,rnpm":{资产":[./assets/fonts"]},脚本":{"start": "节点 node_modules/react-native/local-cli/cli.js start",测试":开玩笑"},依赖关系":{"axios": "^0.18.0","不可变": "^4.0.0-rc.12",反应":16.6.1",反应原生":0.57.5","react-native-chart-kit": "^2.0.0","react-native-device-info": "^0.26.1","react-native-firebase": "^5.2.3","react-native-image-picker": "^0.28.1","react-native-indicators": "^0.13.0","react-native-navigation": "^2.0.2641","react-native-onesignal": "^3.2.12","react-native-progress": "^3.5.0","react-native-sound": "^0.10.12","react-native-svg": "^9.0.0","react-native-typewriter": "^0.5.4","react-redux": "^6.0.0","redux": "^4.0.1","redux-logger": "^3.0.6"},开发依赖":{"babel-jest": "23.6.0","jest": "23.6.0","metro-react-native-babel-preset": "0.49.2",反应测试渲染器":16.6.1"},开玩笑":{预设":反应原生"}}

解决方案

根本原因是相关迁移到Androidx,google play服务更新到androidX

如果您使用的是real-native-info,请升级.它将用 2.1.2

解决您的问题

请参阅此处申请链接

这个问题的类似问题

<块引用>

应用注意:将 com.google.android.gms 升级到 17.0.0 会导致很多问题.

When I try to build my project, which I was successfully building, but now I get this error

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: android.support.v4.os.ResultReceiver$1

I needed to build my project to apply new packages, but while doing it firebase packages gave me error so I upgraded them then here I'm.. I tried %90 of the all suggested solutions in the google none of them worked..

android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 22
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = "27.1.1"
    }
    repositories {
        google()
        mavenLocal()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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


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

subprojects { subproject ->
    afterEvaluate {
        if ((subproject.plugins.hasPlugin('android') || subproject.plugins.hasPlugin('android-library'))) {
            android {
                variantFilter { variant ->
                    def names = variant.flavors*.name
                    if (names.contains("reactNative51") || names.contains("reactNative55")) {
                        setIgnore(true)
                    }
                }
            }
        }
    }
}

android/app/build.gradle

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' } // Gradle Plugin Portal
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.1, 0.99.99]'
    }
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

apply plugin: "com.android.application"

import com.android.build.OutputFile


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

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

def enableProguardInReleaseBuilds = false

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

    defaultConfig {
        applicationId "com.xx"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57"
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    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
                }
            }
     }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    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-image-picker')

    implementation project(':react-native-sound')
    implementation project(':react-native-onesignal')

    implementation project(':react-native-svg')
    implementation project(':react-native-device-info')
    implementation project(':react-native-firebase')

    implementation ('com.google.firebase:firebase-core:17.0.0'){
        exclude group: 'com.android.support'
    }
    implementation ('com.google.firebase:firebase-database:17.0.0'){
        exclude group: 'com.android.support'
    }

    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-navigation')
    implementation 'com.android.support:design:27.1.0'
}

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

package.json

{
  "name": "xxx",
  "version": "0.0.1",
  "private": true,
  "rnpm": {
    "assets": [
      "./assets/fonts"
    ]
  },
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "axios": "^0.18.0",
    "immutable": "^4.0.0-rc.12",
    "react": "16.6.1",
    "react-native": "0.57.5",
    "react-native-chart-kit": "^2.0.0",
    "react-native-device-info": "^0.26.1",
    "react-native-firebase": "^5.2.3",
    "react-native-image-picker": "^0.28.1",
    "react-native-indicators": "^0.13.0",
    "react-native-navigation": "^2.0.2641",
    "react-native-onesignal": "^3.2.12",
    "react-native-progress": "^3.5.0",
    "react-native-sound": "^0.10.12",
    "react-native-svg": "^9.0.0",
    "react-native-typewriter": "^0.5.4",
    "react-redux": "^6.0.0",
    "redux": "^4.0.1",
    "redux-logger": "^3.0.6"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "jest": "23.6.0",
    "metro-react-native-babel-preset": "0.49.2",
    "react-test-renderer": "16.6.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

解决方案

The root cause is related migration to Androidx, google play service updated to androidX

If you are using real-native-info, please upgrade. It will solve your problem with 2.1.2

See here apply link

A similar question to this question

Apply Note: Upgrading com.google.android.gms to 17.0.0 will cause many problems.

这篇关于在 Android 版本中 React Native :app:transformDexArchiveWithExternalLibsDexMergerForDebug 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆