我正试图在Mac上使用“cordova build --release android
”命令从Ionic项目获取一个APK文件但它不起作用,因为我收到此错误
“错误:源路径不存在:resources \ android \ icon \ drawable-hdpi-icon.png”
。谁知道它可能来自哪里?
这是config.xml文件的副本:
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.ionicframework.rise268787" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>RISE</name>
<description>
Discover music as you go
</description>
<author email="[email protected]" href="http://olivierlam.fr/">
Olivier Lam
</author>
<content src="index.html" />
<access origin="*" />
<preference name="webviewbounce" value="false" />
<preference name="UIWebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
<preference name="SplashScreen" value="screen" />
<preference name="orientation" value="portrait" />
<preference name="SplashScreenDelay" value="1000" />
<preference name="android-minSdkVersion" value="16" />
<preference name="BackupWebStorage" value="none" />
<preference name="SplashScreen" value="screen" />
<preference name="SplashScreenDelay" value="1000" />
<feature name="StatusBar">
<param name="ios-package" onload="true" value="CDVStatusBar" />
</feature>
<platform name="android">
<preference name="android-minSdkVersion" value="23" />
<preference name="android-targetSdkVersion" value="23" />
<icon density="ldpi" src="resources\android\icon\drawable-ldpi-icon.png" />
<icon density="mdpi" src="resources\android\icon\drawable-mdpi-icon.png" />
<icon density="hdpi" src="resources\android\icon\drawable-hdpi-icon.png" />
<icon density="xhdpi" src="resources\android\icon\drawable-xhdpi-icon.png" />
<icon density="xxhdpi" src="resources\android\icon\drawable-xxhdpi-icon.png" />
<icon density="xxxhdpi" src="resources\android\icon\drawable-xxxhdpi-icon.png" />
<splash density="port-ldpi" src="resources\android\splash\drawable-port-ldpi-screen.png" />
<splash density="port-mdpi" src="resources\android\splash\drawable-port-mdpi-screen.png" />
<splash density="port-hdpi" src="resources\android\splash\drawable-port-hdpi-screen.png" />
<splash density="port-xhdpi" src="resources\android\splash\drawable-port-xhdpi-screen.png" />
<splash density="port-xxhdpi" src="resources\android\splash\drawable-port-xxhdpi-screen.png" />
<splash density="port-xxxhdpi" src="resources\android\splash\drawable-port-xxxhdpi-screen.png" />
</platform>
<platform name="ios">
<icon height="57" src="resources/ios/icon/icon.png" width="57" />
<icon height="114" src="resources/ios/icon/[email protected]" width="114" />
<icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
<icon height="80" src="resources/ios/icon/[email protected]" width="80" />
<icon height="120" src="resources/ios/icon/[email protected]" width="120" />
<icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
<icon height="100" src="resources/ios/icon/[email protected]" width="100" />
<icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
<icon height="120" src="resources/ios/icon/[email protected]" width="120" />
<icon height="180" src="resources/ios/icon/[email protected]" width="180" />
<icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
<icon height="144" src="resources/ios/icon/[email protected]" width="144" />
<icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
<icon height="152" src="resources/ios/icon/[email protected]" width="152" />
<icon height="167" src="resources/ios/icon/[email protected]" width="167" />
<icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
<icon height="58" src="resources/ios/icon/[email protected]" width="58" />
<icon height="87" src="resources/ios/icon/[email protected]" width="87" />
<splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
<splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
<splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
<splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
<splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
<splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
<splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
</platform>
<icon src="resources/ios/icon/[email protected]" />
<plugin name="cordova-plugin-facebook4" spec="~1.7.1">
<variable name="APP_ID" value="XXXXXXX" />
<variable name="APP_NAME" value="Rise" />
</plugin>
<allow-intent href="mailto:*" />
<allow-navigation href="*.youtube.com" />
<plugin name="cordova-plugin-whitelist" spec="~1.2.2" />
谢谢你的帮助。
运行后,我遇到了同样的错误
离子资源
要么
离子科多瓦资源
(基于您的应用程序的离子版本)
它消失了。
问题是我在图标的路径中有Windows样式的斜杠(反斜杠),即我遇到的错误是这样的:
错误:源路径不存在:resources \ android \ icon \ drawable-hdpi-icon.png
因此,将反斜杠转换为斜线可以解决它。
希望这对你和其他寻找同样问题的人有所帮助。这一切都发生在因为使用不同的机器[mac和windows]来开发像mac和windows这样的项目。
只需编辑config.xml文件即可。我看起来像这样:
<platform name="android">
<splash density="hdpi" src="res/screen/android/screen-hdpi-landscape.png" />
<splash density="port-hdpi" src="res/screen/android/screen-hdpi-portrait.png" />
<splash density="ldpi" src="res/screen/android/screen-ldpi-landscape.png" />
<splash density="port-ldpi" src="res/screen/android/screen-ldpi-portrait.png" />
<splash density="mdpi" src="res/screen/android/screen-mdpi-landscape.png" />
<splash density="port-mdpi" src="res/screen/android/screen-mdpi-portrait.png" />
<splash density="xhdpi" src="res/screen/android/screen-xhdpi-landscape.png" />
<splash density="port-xhdpi" src="res/screen/android/screen-xhdpi-portrait.png" />
</platform>
请注意,res /是相对于项目根目录的。文件名可能会有所不同。
在config.xml中,我将resources \ android \ icon \ drawable-hdpi.png更改为资源resources \ android \ icon \ drawable-hdpi.png
在config.xml中,我将resources / android / icon / drawable-hdpi.png更改为资源resources \ android \ icon \ drawable-hdpi.png
注意斜线变化。
问题是因为你有:
<preference name="Orientation" value="portrait" />
在你的config.xml
,当你运行ionic cordova resources
时,它只生成纵向方向的资源。
我使用类似于Fakan的方式解决了错误。您只需要将平台标签外的src =“resources \ android \ icon \ drawable-hdpi.png”更改为“resources \ icon.png”以解决此错误
试着在Ionic结构中找到这个资源的路径。有时,或者在某些版本中,此路径可能如下所示:
你的资源:
resources/android/icon/drawable-hdpi.png
试试这个:
res/android/icon/drawable-hdpi.png
检查您的图标是否实际保存为“.png”。不是“.PNG”。右键单击它并单击“属性”。
如果不是,请编辑您的图标并使用文件扩展名“.png”进行保存。
不要忘记在resources
文件夹中添加文件。
理想情况下,图标的源图像应至少为1024×1024像素,位于resources/icon.png
。初始屏幕的源图像最好至少为2732×2732像素,位于resources/splash.png
。如果您使用了离子启动,则资源/目录中应该已经存在默认的Ionic资源,您可以覆盖它们。
您需要使用以下格式:.png
,.psd
或.ai
。
您可以使用https://code.ionicframework.com/resources/splash.psd作为启动画面的模板,使用https://code.ionicframework.com/resources/icon.psd作为图标。
只需删除config.xml文件中的<preference name="Orientation" value="portrait" />
并运行ionic cordova资源即可。
问题是当你运行离子cordova资源时,它只生成纵向方向的资源。