React Native Android Duplicate file error when generating apk

后端 未结 8 1494
生来不讨喜
生来不讨喜 2020-11-30 20:30

When I am trying to generate android apk by using ./gradlew installRelease, I get this error in console:

~/React-Native/mockingbird/android/app/         


        
8条回答
  •  南笙
    南笙 (楼主)
    2020-11-30 21:22

    Give some tips for you, hope it's work.

    Update with "react": "16.7.0", "react-native": "0.57.8"

    Custom node_modules/react-native/react.gradle to solve the Duplicate file error perfectly. Add following code into currentBundleTask's creation block (after doFirst block)

    doLast {
        def moveFunc = { resSuffix ->
            File originalDir = file("${resourcesDir}/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()
    }
    

    You can create script to do it automatically.

    1. Create android-react-gradle-fix file
    2. Create script android-release-gradle-fix.js file
    3. Update package.json file:

      "scripts": { "postinstall": "node ./android-release-gradle-fix.js" },

    That's it! Run npm install to get awesome.

    Note: If you run npm install on ci like jenkins, you may get error: postinstall: cannot run in wd %s %s (wd=%s) node => just use npm install --unsafe-perm instead

提交回复
热议问题