加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – React Native:任务执行失败’:app:transform

发布时间:2020-12-15 20:30:41 所属栏目:百科 来源:网络整理
导读:我已经尝试了gradlew clean以及此处和 GitHub上提供的所有其他解决方案,但错误不匹配且解决方案不起作用 Error on cmd After running react-native run-android Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED D8: Program type al
我已经尝试了gradlew clean以及此处和 GitHub上提供的所有其他解决方案,但错误不匹配且解决方案不起作用

Error on cmd After running react-native run-android

> Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
    D8: Program type already present: com.google.android.gms.common.api.internal.zzda


    FAILURE: Build failed with an exception.


* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug1.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug2.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug3.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug4.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug5.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug6.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug7.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug8.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug9.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug10.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug11.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug12.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug13.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug14.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug15.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug16.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug17.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug18.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug19.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug20.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug21.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug22.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug23.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug24.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug25.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug26.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug27.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug28.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug29.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug30.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug31.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug32.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug33.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug34.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug35.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug36.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug37.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug38.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug39.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug40.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug41.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug42.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug43.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug44.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug45.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug46.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug47.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug48.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug49.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug50.jar,C:New folderAppandroidappbuildintermediatestransformsdexBuilderdebug51.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 39s
82 actionable tasks: 78 executed,4 up-to-date
Could not install the app on the device,read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

我已经尝试了所有的解决方案,但似乎都没有.请帮忙

react-native-cli: 2.0.1
react-native: 0.53.0

build.gradle文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'

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

allprojects {
    repositories {
        mavenLocal()
        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://maven.google.com'
        }
    }
}

ext {
  compileSdkVersion = 26
  targetSdkVersion = 26
  buildToolsVersion = "26.0.2"
  supportLibVersion = "26.1.0"
  googlePlayServicesVersion = "11.8.0"
  oreoEXPERIMENTAL = "yes"
}

android / app / build.gradle文件:

apply plugin: "com.android.application"

import com.android.build.OutputFile

/**
 * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
 * and bundleReleaseJsAndAssets).
 * These basically call `react-native bundle` with the correct arguments during the Android build
 * cycle. By default,bundleDebugJsAndAssets is skipped,as in debug/dev mode we prefer to load the
 * bundle directly from the development server. Below you can see all the possible configurations
 * and their defaults. If you decide to add a configuration block,make sure to add it before the
 * `apply from: "../../node_modules/react-native/react.gradle"` line.
 *
 * project.ext.react = [
 *   // the name of the generated asset file containing your JS bundle
 *   bundleAssetName: "index.android.bundle",*
 *   // the entry file for bundle generation
 *   entryFile: "index.android.js",*
 *   // whether to bundle JS and assets in debug mode
 *   bundleInDebug: false,*
 *   // whether to bundle JS and assets in release mode
 *   bundleInRelease: true,*
 *   // whether to bundle JS and assets in another build variant (if configured).
 *   // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
 *   // The configuration property can be in the following formats
 *   //         'bundleIn${productFlavor}${buildType}'
 *   //         'bundleIn${buildType}'
 *   // bundleInFreeDebug: true,*   // bundleInPaidRelease: true,*   // bundleInBeta: true,*
 *   // whether to disable dev mode in custom build variants (by default only disabled in release)
 *   // for example: to disable dev mode in the staging build type (if configured)
 *   devDisabledInStaging: true,*   // The configuration property can be in the following formats
 *   //         'devDisabledIn${productFlavor}${buildType}'
 *   //         'devDisabledIn${buildType}'
 *
 *   // the root of your project,i.e. where "package.json" lives
 *   root: "../../",*
 *   // where to put the JS bundle asset in debug mode
 *   jsBundleDirDebug: "$buildDir/intermediates/assets/debug",*
 *   // where to put the JS bundle asset in release mode
 *   jsBundleDirRelease: "$buildDir/intermediates/assets/release",*
 *   // where to put drawable resources / React Native assets,e.g. the ones you use via
 *   // require('./image.png')),in debug mode
 *   resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",in release mode
 *   resourcesDirRelease: "$buildDir/intermediates/res/merged/release",*
 *   // by default the gradle tasks are skipped if none of the JS files or assets change; this means
 *   // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
 *   // date; if you have any other folders that you want to ignore for performance reasons (gradle
 *   // indexes the entire tree),add them here. Alternatively,if you have JS files in android/
 *   // for example,you might want to remove it from here.
 *   inputExcludes: ["android/**","ios/**"],*
 *   // override which node gets called and with what additional arguments
 *   nodeExecutableAndArgs: ["node"],*
 *   // supply additional arguments to the packager
 *   extraPackagerArgs: []
 * ]
 */

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 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.cherishx_vendors"
        minSdkVersion 16
        targetSdkVersion 22
        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 {
    compile project(':react-native-onesignal')
    compile project(':react-native-mauron85-background-geolocation')
    compile fileTree(dir: "libs",include: ["*.jar"])
    compile "com.android.support:appcompat-v7:23.0.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
}

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

编辑

将multidexEnabled = true添加到android / app / build.gradle文件后
弹出以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 16s
68 actionable tasks: 1 executed,67 up-to-date
Could not install the app on the device,read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/getting-started.html

这个错误在任何地方都没有回答,因此我将其作为此问题的更新.

解决方法

几天前得到同样的错误,似乎你必须启用multidex = true并删除我的构建文件夹

您可以在react-native上检查此线程

https://github.com/oney/react-native-gcm-android/issues/32

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读