可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
Your system information:
Cordova CLI: 6.5.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
OS: macOS Sierra
Node Version: v6.9.5
Xcode version: Xcode 8.2.1 Build version 8C1002
I am trying to use ionic platform add android
to create an android project, but it always complains that resources/android/icon/drawable-hdpi-icon.png
does not exist. In fact it doesn't -- none of these resources exist. They can get created by ionic resources
.
However if I try to run ionic resources
without the platform, I am told to add the platform first. This leads me to essentially do something like:
ionic platform add android
ionic resources
ionic platform rm android
ionic platform add android
Then it works properly. Is there anything I can do to make sure the resources get properly built or referenced before adding the platform?
回答1:
For me, in config.xml, path had backward slash in tag, changed it from:
<icon src="resources\android\icon\drawable-xhdpi-icon.png" />
to:
<icon src="resources/android/icon/drawable-xhdpi-icon.png" />
回答2:
This actually had to do with my configuration. If you don't specify the platform in your configuration, platform add
will create one for you. This automatically includes paths to resources that may not be there.
Update your config.xml to include the platform; even if it is empty:
<platform name="android"/>
<platform name="ios"/>
Then, platform add
will not update the platform in the config and look for resources that may not be there. You still should do ionic resources
to generate them after the fact, though.
回答3:
In my case it was a config.xml
path issue.
Before I had this:
<icon density="hdpi" src="res/android/ic-hdpi.png" />
but in my folder structure I have an extra folder called icon, so I change all the .png
path files to:
<icon density="hdpi" src="res/icon/android/ic-hdpi.png" />
and it worked for me
回答4:
For me, this issue was due to below line in config.xml:
'<preference name="orientation" value="portrait" />'
Actually when you try to add any platform using "ionic cordova platform add android/ios", it will add respective platform and generates respective resources("icon.png" and "splash.png"). With portrait orientation, it will add only relevant resources to that orientation(i.e. ionic cordova resources does not add the landscape images if the orientation is set to portrait) and fails with "UnhandledPromiseRejectionWarning: Error: Source path does not exist: resources/android/icon/drawable-hdpi-icon.png" error.
Hence please check whether your config.xml have any preference for portrait/landscape mode.
Please remove any preference with portrait/landscape from your config.xml file before adding platform.
回答5:
For Ionic this works for me:
npm i -g cordova-res
ionic cordova resources --cordova-res
found here https://github.com/ionic-team/ionic-cli/issues/3762#issuecomment-456967033
Think it's an mac/windows-issue.
回答6:
may be while creating the ionic app resources not added properly simply you can do one thing install another app by using following command.
ionic start appname blank
then copy the android icons folder and paste into you current app folder this will work fine.the image missed in your project is 72*72 image.please check the resources once.
回答7:
Check the name of the splash screen and app icon. I mistaken in the name of the files. In my case the error was due to the invalid file names. I just copied and pasted the assets i.e., AppName_splash.png and icon-512.png while it should have been "splash.png" and "icon.png".
回答8:
I had the same problem which was fixed by removing "package-lock.json" and "npm install"