React Native 0.57.1 Android Duplicate Resources

前端 未结 10 990
离开以前
离开以前 2020-12-05 09:41

When running ./android/gradlew assembleRelease I get the following error:

``` * What went wrong: Execution failed for task \':app:mergeReleaseResources\

相关标签:
10条回答
  • 2020-12-05 10:05

    Recent versions of React Native (>0.57.0) have increased the Gradle wrapper level to 4.4 and Gradle plugin to 3.1.4, as indicated by the changelog. This has the effect of making the Gradle build process store the results of AAPT, which are now required, within a different directory than previously. So basically you have to edit the /node_modules/react-native/react.gradle file and add the doLast right after the doFirst block, manually.

    doFirst { ... }
    doLast {
        def moveFunc = { resSuffix ->
            File originalDir = file("$buildDir/generated/res/react/release/drawable-${resSuffix}");
            if (originalDir.exists()) {
                File destDir = file("$buildDir/../src/main/res/drawable-${resSuffix}");
                ant.move(file: originalDir, tofile: destDir);
            }
        }
        moveFunc.curry("ldpi").call()
        moveFunc.curry("mdpi").call()
        moveFunc.curry("hdpi").call()
        moveFunc.curry("xhdpi").call()
        moveFunc.curry("xxhdpi").call()
        moveFunc.curry("xxxhdpi").call()
    }
    
    0 讨论(0)
  • 2020-12-05 10:10

    Remove raw file in src/main/res/raw

    Then run This cmd=>

    npx react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/build/intermediates/res/merged/release/

    Then go run /android=> agradlew assembleRelease

    0 讨论(0)
  • 2020-12-05 10:16

    This problem will happen when you have 2 images with similar names and different types.

    Just Check your assets and avoid naming the same.

    0 讨论(0)
  • 2020-12-05 10:16

    If the build fails after executing Task :app:bundleReleaseJsAndAssets you will observe this error in the subsequent attempt

    The easiest way to find the duplicate entries is through version control.

    If you are using Git. You can get the all the Un-tracked files using the command

    git status

    & delete the files in /android/app/src/main/res/drawable** directories.

    Re-run the build should work.

    0 讨论(0)
  • 2020-12-05 10:17

    llya today I have faced a similar problem and fixed by following steps:

    • updated classpath 'com.android.tools.build:gradle:3.1.3' to classpath 'com.android.tools.build:gradle:3.2.0' in build.gradle.

    • changed distributionUrl=https://services.gradle.org/distributions/gradle-4.4-all.zip to distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip in /android/gradle/wrapper/gradle-wrapper.properties

    • Removed android.enableAapt2=false from gradle.properties

    • Updated buildToolsVersion:27.0.3

    • clean project

    • sync gradle again in android studio.

    • bundle and try again to make a release build.

    0 讨论(0)
  • 2020-12-05 10:21

    I just deleted android/app/build/generated/ folder and the build succeded.

    0 讨论(0)
提交回复
热议问题