React Native Android Duplicate file error when generating apk

后端 未结 8 1467
生来不讨喜
生来不讨喜 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:19

    A way to remove the error would be to:

    • put your images in the android/app/src/main/res/drawable folder (create a “drawable” folder if one doesn’t exist)
    • delete all the drawable folders that have suffixes (i.e. drawable-hdpi, drawable-mdpi, etc)
    • don’t bundle assets (i.e. don’t run: react-native bundle …)
    • run Gradle’s assembleRelease

    However, this is not an ideal solution because each image will only have one resolution for all device sizes. For images that are too big for a device it leaves downscaling to the device and leads to download size and speed issues, and for images too small for a device it leads to diminished image quality.

    One convenient solution I’ve found is to use an Android Studio plugin called Android Drawable Importer. To use it after it is installed:

    • open your project in Android studio and navigate to: android/app/src/main/res/drawable
    • right click on the folder and choose: New > Batch Drawable Import
    • select and configure image assets to import

    The plugin will handle the generation of the drawable folders and correct image sizes. Once you’ve imported your image, you should be able to run Gradle’s assembleRelease without the duplicate resources error.

提交回复
热议问题