1
votes

Environment

OS: macOS Mojave 10.14.6
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Memory: 140.81 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash

Binaries: Node: 14.4.0 - /var/folders/vb/yvc825yd15ldmskwnwtrpsnjdgvdj0/T/yarn--1596208558025-0.4815624974976791/node Yarn: 1.19.0 - /var/folders/vb/yvc825yd15ldmskwnwtrpsnjdgvdj0/T/yarn--1596208558025-0.4815624974976791/yarn npm: 6.14.4 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman SDKs: iOS SDK: Platforms: iOS 13.1, DriverKit 19.0, macOS 10.15, tvOS 13.0, watchOS 6.0 Android SDK: API Levels: 28, 29 Build Tools: 27.0.3, 28.0.3, 29.0.1, 29.0.2 System Images: android-19 | Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-21 | Google APIs Intel x86 Atom, android-22 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom IDEs: Android Studio: 3.6 AI-192.7142.36.36.6392135 Xcode: 11.1/11A1027 - /usr/bin/xcodebuild npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.5 => 0.61.5 npmGlobalPackages: react-native-cli: 2.0.1

Upgrading version

From 0.59.5 to 0.61.5

Description

Duplicate Resources error while generating release APK

Upgraded react-from 0.59.5 to 0.61.5 version. After upgrade tried to generate release APK for the application but build failed with an exception stating duplicate resources for the assets. Tried a workaround by updating the below code in react.gradle file.

doLast { 

    def moveFunc = { resSuffix -> 

        File originalDir = file("$buildDir/generated/res/react/release/${resSuffix}"); 

        if (originalDir.exists()) { 

            File destDir = file("$buildDir/../src/main/res/${resSuffix}"); 

            ant.move(file: originalDir, tofile: destDir); 

        } 

     } 

     moveFunc.curry("drawable-ldpi").call() 

     moveFunc.curry("drawable-mdpi").call() 

     moveFunc.curry("drawable-hdpi").call() 

     moveFunc.curry("drawable-xhdpi").call() 

     moveFunc.curry("drawable-xxhdpi").call() 

     moveFunc.curry("drawable-xxxhdpi").call() 

     moveFunc.curry("raw").call() 

} 

Now after the above workaround we are able to generate release APK successfully but in the generated APK none of the images are present since they get removed but we need to use those images.

Reproducible demo

Run ./gradlew assembleRelease to get this error.

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:mergeReleaseResources'.

[drawable-mdpi-v4/toasset] /path/toasset.png

Why we created a new issue?

React Native : Error: Duplicate resources - Android - provides step to overcome the build failure by removing the images but we need those images to be in the final bundle.

1
you can delete your resource drawable inside android folder , its not an issue ...Tushar Pandey
I need those images, without them none of the images inside my app work.Satheesh

1 Answers

0
votes

This was a bug in canary versions of AGP 4.1. It has been fixed now and the fix will be included in 4.1-RC1.

It was because AGP tried to generate too many PNGs for vector drawables. To save yourself pain in the future, as well as improve your build speed and reduce APK size you can use the support library to instead handle vector drawables at runtime. You can use this feature by changing your build.gradle file:

android {
   defaultConfig {
     vectorDrawables.useSupportLibrary = true
    }
 }

You can find more info about vector drawable support in support library in the documentation.