10
votes

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
Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.halfer
Did you use Create React Native Application?Mayur Bhangale
I have used react-native init projectNameMayuri Birajdar
when I have deleted my drawable-folders I get the error like: Unable to process incoming event 'ProgressComplete ' (ProgressCompleteEvent)Mayuri Birajdar

8 Answers

8
votes

I was trying to generate a signed APK following the steps from https://facebook.github.io/react-native/docs/signed-apk-android.html to generate a signed apk.

I had the same issue. Showed error: Duplicate file for some of my images when I ran ./gradlew assembleRelease. assembleRelease seems to cause some problems with drawable- folders. I deleted all the drawable- folders from /android/app/src/main/res/. Then I ran ./gradlew assembleRelease again. Finaly, it generated a signed APK at /android/app/build/outputs/apk/.

21
votes

The issue is that the new version of react-native bundles the assets under /app/build/intermediates/res/merged/release instead of app/src/main/res

To resolve it, this is what I did

rm -rf android/app/src/main/res/drawable-*

Now bundle assets using this command:

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/build/intermediates/res/merged/release/

Note the updated --assets-dest in the above command. Assembling the APK worked ok after that!

react-native run-android --variant=release

1
votes

It seems that you bundled your app and installed it to your phone with assembleDebug. When you decided to go for assembleRelease then you should delete drawable- folders. They create problem somehow when you decide to produce an .apk file.

0
votes

Did you try a react native clean build ? Try resetting the cache and then bundle. Maybe it will resolve this issue.

0
votes

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

0
votes

First delete all folders that are potentially causing this error by typing:

rm -rf ./android/app/build/intermediates/res/merged/release/drawable-*

Then change mdpi to mdpi-v4 in:

./node_modules/react-native/local-cli/bundle/assetPathUtils.js

function getAndroidAssetSuffix(scale) {
  switch (scale) {
    case 0.75: return 'ldpi';
    case 1: return 'mdpi-v4';
    case 1.5: return 'hdpi';
    case 2: return 'xhdpi';
    case 3: return 'xxhdpi';
    case 4: return 'xxxhdpi';
  }
}

Then bundle your offline includes:

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/build/intermediates/res/merged/release/

Finally build the release version of your app:

cd ./android && ./gradlew assembleRelease
0
votes

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

0
votes

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/