Error occurred while copying resources/android/icon/mdpi-foreground.png
Asked Answered
T

7

41

I am getting following error while copying icons and splash screen using cordova-res.

I am using capacitor to build the app

I am using following command to copy the icons:

cordova-res android --skip-config --copy

here is the response of the command:

~/Public/accountech-ecommerce/ionic-files$ cordova-res android --skip-config --copy
Generated 18 resources for Android
WARN:   Error occurred while copying resources/android/icon/mdpi-foreground.png
WARN:   Error occurred while copying resources/android/icon/mdpi-background.png
WARN:   Error occurred while copying resources/android/icon/hdpi-foreground.png
WARN:   Error occurred while copying resources/android/icon/hdpi-background.png
WARN:   Error occurred while copying resources/android/icon/xhdpi-foreground.png
WARN:   Error occurred while copying resources/android/icon/xhdpi-background.png
WARN:   Error occurred while copying resources/android/icon/xxhdpi-foreground.png
WARN:   Error occurred while copying resources/android/icon/xxhdpi-background.png
WARN:   Error occurred while copying resources/android/icon/xxxhdpi-foreground.png
WARN:   Error occurred while copying resources/android/icon/xxxhdpi-background.png
Copied 31 resource items to Android

PS: I have followed this instruction to do that: https://capacitorjs.com/docs/guides/splash-screens-and-icons

Toms answered 3/2, 2021 at 11:30 Comment(0)
D
93

I ran into the same error in a new Ionic [email protected] project. I had the splash.png and icon.png in the resources directory. But those aren't enough. The error is related to the Adaptive Icons section for cordova-res. 2 more icons are missing in your resources directory.

  1. Add the required icon-foreground.png and icon-background.png to the resources/android directory
  2. (Optional) Check if cordova-res is the latest. For me I upgraded to version 0.15.3 on a mac with this commands: sudo npm -g remove cordova-res and then sudo npm -g install cordova-res --unsafe-perm
  3. Re-run the command:
cordova-res android --skip-config --copy
  • Successful output now looks like (the 18 changed to 24):
Generated 24 resources for Android
Copied 31 resource items to Android
Desulphurize answered 31/3, 2021 at 2:26 Comment(3)
It seems it doesn't work anymore, even with the latest Cordova-res. No error, no missing files, but just the same warnings and still 18 images generated.Uncertainty
Any idea on what are the required dimensions of these images?Passional
You may have to remove your android and resources/android directories. Then npx cap add android. Then cordova-res android --skip-config --copy.Abott
B
35

The files should be organized like this:

resources/
├── android/
│   ├── icon-background.png
│   └── icon-foreground.png
├── icon.png
└── splash.png

Next, run this command to generate all images then copy them into the native projects:

 cordova-res ios --skip-config --copy
 cordova-res android --skip-config --copy
Basque answered 22/3, 2022 at 13:1 Comment(0)
Z
16

The following steps worked for me.

you will need to create two images manually.

Step 1

Create a 432x432 .png file. Then save it as "icon-background.png". you may decide to make the color transparent or not

In my case, I created a white image since I need a white background for my icon and I went for the 432x432 dimension.

Step 2

Create another 432x432 .png file and save it as "icon-foreground.png".

In this case, you will be mindful of the color of the background you use in the first image.

Step 3

put the two images created above into <Project Directory>/resources/android/

Step 4

then run either of the following from the project directory, depending on whichever works for you. number 1 worked for me.

  1. cd android && gradlew assembleDebug && cd ..
  2. ionic cordova run android
Zins answered 16/3, 2021 at 19:35 Comment(2)
what do you mean with "you will be mindful of the color of the background you use in the first image" ??Arette
it has to be a contrasting color. if the background color is white, then icon-foreground.png image should either be black or something that is visible when placed on top of white colorZins
S
1

I followed the instructions on this video. https://www.youtube.com/watch?v=2Ce09by4qFE

You basically have to go in to Android Studio and create a new image resource/whatever it's called.

It all used to work with a CLI command. Not anymore... (at least for me)

Sidle answered 30/6, 2022 at 7:36 Comment(0)
N
1

I solved by using capacitor-assets, which has an "Easy Mode". For example in my ionic-vue android project I used:

npx capacitor-assets generate --android --assetPath resources/android --androidProject android

if you don't have it installed, you can do it by typing:

npm install @capacitor/assets -g
Natoshanatron answered 8/2, 2023 at 14:2 Comment(0)
M
0

Directly ADD your android application via android studio go to APP then click file > new > image asset now set your app icon manually

Mousseline answered 8/9, 2021 at 13:35 Comment(3)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewNeptunian
That will not replace the splash screen.Teledu
yes , but splash screen added by ionic command and after you got this error for app icon that time this is helpful .throw this you direct change your app icon. @JohnHarrisMousseline
L
-4

If you using ionicframework try this
ionic cordova resources [<platform>] [options]

ionic cordova resources

Land answered 3/2, 2021 at 16:27 Comment(1)
Since I am using capacitorjs, getting this error: [ERROR] Could not find cordova integration in the default project.Toms

© 2022 - 2024 — McMap. All rights reserved.