Duplicate resources android studio ошибка

The reason you are seeing this error is because Android considers the following images to be the same, based on how they are referenced in your layouts:

E:AndroidLEDappsrcmainresdrawable-hdpilogin_bg.png
E:AndroidLEDappsrcmainresdrawable-hdpilogin_bg.9.png

The first image, login_bg.png, is a normal image. The second image, login_bg.9.png, is named in such a way to tell Android that it is a 9-patch image. However, in terms of referencing the images, they are declared the same, as in the following examples.

Normal image:

<ImageView
    android:id="@+id/normalImage"
    android:background="@drawable/login_bg"/>

Nine-patch image:

<ImageView
    android:id="@+id/ninePatchImage"
    android:background="@drawable/login_bg"/>

Note: There is no difference in terms of referencing the images from the /res/drawables directory of your Android project.

See here for more info about nine-patch image, or the correct term for it is nine-patch drawable. For reference, nine-patch drawables must be declared as <name>.9.png, as in login_bg.9.png.

Therefore, simply renaming them will not solve the issue. You need to check with whoever developed the UI to see which one should be used: either the normal image (login_bg.png) or the 9-patch image (login_bg.9.png)—not both.

  • Review the documentation: https://facebook.github.io/react-native
  • Search for existing issues: https://github.com/facebook/react-native/issues
  • Use the latest React Native release: https://github.com/facebook/react-native/releases

Environment

React Native Environment Info:

System:
  OS: macOS 10.14
  CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
  Memory: 103.10 MB / 8.00 GB
  Shell: 3.2.57 - /bin/bash
Binaries:
  Node: 8.12.0 - /usr/local/bin/node
  Yarn: 1.0.1 - /usr/local/bin/yarn
  npm: 6.4.1 - /usr/local/bin/npm
  Watchman: 4.7.0 - /usr/local/bin/watchman
SDKs:
  iOS SDK:
    Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
  Android SDK:
    API Levels: 16, 17, 19, 21, 23, 24, 25, 26, 27, 28
    Build Tools: 19.1.0, 20.0.0, 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.3, 28.0.0, 28.0.0, 28.0.2, 28.0.3
    System Images: android-16 | ARM EABI v7a, android-16 | MIPS, android-16 | Intel x86 Atom, android-16 | Google APIs Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-24 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-26 | Google Play Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-P | Google APIs Intel x86 Atom, android-P | Google Play Intel x86 Atom
IDEs:
  Android Studio: 3.2 AI-181.5540.7.32.5056338
  Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
  react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728 
  react-native: 0.57.4 => 0.57.4 
npmGlobalPackages:
  babel-preset-react-native: 4.0.0
  react-native-cli: 2.0.1
  react-native-create-library: 3.1.2
  react-native-git-upgrade: 0.2.7

Description

I’m not able to create a release apk with the PNG image in Android. But can able to create a release apk when there is no PNG image in it. Here is the error I’m getting while generating the release build

[drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/src/main/res/drawable-mdpi/assets_mario.png	[drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/build/generated/res/react/release/drawable-mdpi-v4/assets_mario.png: Error: Duplicate resources
:app:mergeReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.
> [drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/src/main/res/drawable-mdpi/assets_mario.png	[drawable-mdpi-v4/assets_mario] /Users/jeffreyrajan/Tutorials/RN/errorCheck/android/app/build/generated/res/react/release/drawable-mdpi-v4/assets_mario.png: Error: Duplicate resources

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Reproducible Demo

  1. Create a app — react-native init demo
  2. Create a assets folder in the project root folder.
  3. Add a PNG image inside the assets folder.
  4. Now implement a image component with the above PNG image.
  5. Now bundle it using the cmd
    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/src/main/res/
  6. Then generate release apk using Generate Signed APK

То, что Android считает, что при сопоставлении изображений в ваших макетах одно и то же:

E:AndroidLEDappsrcmainresdrawable-hdpilogin_bg.png
E:AndroidLEDappsrcmainresdrawable-hdpilogin_bg.9.png

login_bg.9.png image сообщает Android, что это изображение является 9-патч-изображением. В то время как другое изображение, login_bg.png, является обычным образом. Но с точки зрения ссылок на изображения они объявляются одинаковыми, как в следующих примерах.

Нормальное изображение:

<ImageView
    android:id="@+id/normalImage"
    android:background="@drawable/login_bg"/>

Изображение Nine-patch:

<ImageView
    android:id="@+id/ninePatchImage"
    android:background="@drawable/login_bg"/>

Примечание. Нет никакой разницы в ссылках на изображения из вашего каталога /res/drawables вашего проекта Android.

См. здесь для получения дополнительной информации об изображении с девятью патчами, или для правильного термина для него доступно девять патчей. Для справки, 9-патч-чертежи должны быть объявлены как <name>.9.png, как в login_bg.9.png.

It seems like you have the same image resource in two files OR you added an additional, non-required file to the res folder. Rename or remove the other. You can check the required structure of the res folder and subfolders by downloading a fresh copy of WebViewGold from CodeCanyon.

Moreover, please go to the Build drop-down menu in the menu bar. You can see the Rebuild Project under the Clean Project. If you can’t find Rebuild Project, you can use Clean Project instead. Try to build the app again afterward.

This the error I’m getting :

:app:mergeDebugResources
:app:mergeDebugResources FAILED
/Users/vedantdasswain/GitRepositories/EnergyLens/AndroidStudioVersion/EnergyLens/app/src/main/res/values/themes_apptheme.xml
Error:Error: Duplicate resources: /Users/vedantdasswain/GitRepositories/EnergyLens/AndroidStudioVersion/EnergyLens/app/src/main/res/values/themes_apptheme.xml:style/AppTheme, /Users/vedantdasswain/GitRepositories/EnergyLens/AndroidStudioVersion/EnergyLens/app/src/main/res/values/styles.xml:style/AppTheme
Error:Execution failed for task ':app:mergeDebugResources'.
> /Users/vedantdasswain/GitRepositories/EnergyLens/AndroidStudioVersion/EnergyLens/app/src/main/res/values/themes_apptheme.xml: Error: Duplicate resources: /Users/vedantdasswain/GitRepositories/EnergyLens/AndroidStudioVersion/EnergyLens/app/src/main/res/values/themes_apptheme.xml:style/AppTheme, /Users/vedantdasswain/GitRepositories/EnergyLens/AndroidStudioVersion/EnergyLens/app/src/main/res/values/styles.xml:style/AppTheme

The source of this error is the following file, themes_apptheme.xml :

<?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="AppTheme" parent="@style/_AppTheme"/>

  <style name="_AppTheme" parent="android:Theme.Holo.Light">

    <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_light</item>

    <item name="android:textColorHighlight">#99003366</item>
    <item name="android:textSelectHandleLeft">@drawable/apptheme_text_select_handle_left</item>
    <item name="android:textSelectHandleRight">@drawable/apptheme_text_select_handle_right</item>
    <item name="android:textSelectHandle">@drawable/apptheme_text_select_handle_middle</item>

    <item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewAppTheme</item>

    <item name="android:listChoiceIndicatorMultiple">@drawable/apptheme_btn_check_holo_light</item>

    <item name="android:listChoiceIndicatorSingle">@drawable/apptheme_btn_radio_holo_light</item>

    <item name="android:buttonStyle">@style/ButtonAppTheme</item>

    <item name="android:imageButtonStyle">@style/ImageButtonAppTheme</item>

    <item name="android:dropDownSpinnerStyle">@style/SpinnerAppTheme</item>

    <item name="android:listChoiceBackgroundIndicator">@drawable/apptheme_list_selector_holo_light</item>

    <item name="android:activatedBackgroundIndicator">@drawable/apptheme_activated_background_holo_light</item>

    <item name="android:fastScrollThumbDrawable">@drawable/apptheme_fastscroll_thumb_holo</item>

  </style>

</resources>

Could someone please explain what is causing the error and how to resolve it?

UPDATE:

The duplicate resource was mentioned in styles.xml, which I commented out:

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

    <!-- Application theme. -->
    <!--<style name="AppTheme" parent="AppBaseTheme">-->
        <!--&lt;!&ndash; All customizations that are NOT specific to a particular API-level can go here. &ndash;&gt;-->
    <!--</style>-->


</resources>

This seems to have let me complete the build successfully and solve the problem. Thanks for the comment @pyus13

Возможно, вам также будет интересно:

  • Duolingo произошла ошибка попробуйте позже
  • Dungs mpa 22 коды ошибок
  • Dungeon siege 2 критическая ошибка
  • Dungeon lords ошибка сохранения
  • Dungeon lords ошибка deep6

  • Понравилась статья? Поделить с друзьями:
    0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии