gradlew assembleRelease command in react-native android is not generating the app-release.apk

Viewed 20752

I want to generate the unsigned app-release.apk without the react-packager server. I am running the following commands for that.

cd react-native-project-dir

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

After the following command I get the error in command prompt like these:

cd android && gradlew assemblerelease

app:processReleaseManifestessReleaseManifest

:app:processReleaseResources D:\ReactNativeProject\android\app\build\intermediates\res\merged\release\drawable-mdpi-v4\image_background_unique_2.jpg: error: Duplicate file. D:\ReactNativeProject\android\app\build\intermediates\res\merged\release\drawable-mdpi\image_background_unique_2.jpg: Original is here. The version qualifier may be implied. :app:processReleaseResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:processReleaseResources'. com.android.ide.common.process.ProcessException: Failed to execute aapt

And I am not able to generate the app-release.apk and not understanding why the image_background_unique_2.jpg file is getting added two times in different folders.

8 Answers

I have managed to solve this problem by deleting the duplicates of the folder in react native /android/app/build/intermediates/res/merged/release/drawable-mdpi

this worked for me

Add the following code to file node_modules/react-native/react.gradle :

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

inside def currentBundleTask = tasks.create(...

found this solution here https://github.com/facebook/react-native/issues/5787

you can do one things for debug to make react native bundle run below command

react-native bundle --assets-dest ./android/app/src/main/res/ --entry-file ./index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --platform android --dev true

For release:

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