简体   繁体   English

离子 3 错误:当命令运行 ionic cordova run android

[英]Ionic 3 Error : when command run ionic cordova run android

ionic 3 Error : when commend run离子 3 错误:当推荐运行时

cordova platform add android --save × Running command - failed! cordova 平台添加 android --save × 运行命令 - 失败! [WARN] Platform already added. [警告] 平台已添加。 Saving platforms to config.xml.将平台保存到 config.xml。 Platform android is not installed!未安装平台android! Would you like to install it?您要安装它吗? (Y/n) (是/否)

and when i try run当我尝试跑步时

cordova run android shown Error: Source path does not exist: resources/android/icon/drawable-hdpi-icon.png cordova run android 显示错误:源路径不存在:resources/android/icon/drawable-hdpi-icon.png

ionic cordova platform add android

Platform android is not installed!未安装平台android! Would you like to install it?您要安装它吗? (Y/n) press Y (Y/n) 按Y

Please remove any preference with portrait/landscape from your config.xml file before adding platform .在添加 platform 之前,请从您的config.xml文件中删除任何带有纵向/横向的首选项

Solution解决方案

Step 1 : Remove android platform第 1 步:删除 android 平台

ionic cordova platform rm android

Step 2 :check config.xml if android platform array is there, if it is still there remove it.第 2 步:检查config.xml是否存在 android 平台数组,如果仍然存在,则将其删除。

Step 3 : Add android platform again第三步:再次添加android平台

ionic cordova platform add android

Step 4 : Run ionic on android第 4 步:在 android 上运行ionic

ionic cordova run android -l -c

step 5 : genrate resource files for platform details here第 5 步在此处生成平台详细信息的资源文件

ionic cordova resources android离子科尔多瓦资源android

Firstly you need to run the command:首先,您需要运行以下命令:

ionic cordova resources android

It creates all the various size images based of a default you supply, adding lines to config.xml for build to use later in generation of the APK.它根据您提供的默认值创建所有不同大小的图像,将行添加到config.xml以供构建,以便稍后在生成 APK 时使用。

More info on the size can be obtained here .可以在 此处获得有关尺寸的更多信息。

  • icon.png 1024px x1024px - you supply this. icon.png 1024px x1024px - 你提供这个。

  • splash.png 2732px x 2732px飞溅.png 2732px x 2732px

The source image for icons should ideally be at least 1024×1024px and located at resources/icon.png .理想情况下,图标的源图像应至少为 1024×1024px 并位于resources/icon.png The source image for splash screens should ideally be at least 2732×2732px and located at resources/splash.png .初始屏幕的源图像理想情况下应至少为 2732×2732px 并位于resources/splash.png

... ...


Then follow up with the build:然后跟进构建:

ionic cordova build android --prod

As others have indicated it may be prudent to remove/add platform again to be sure.正如其他人所指出的那样,再次 删除/添加平台可能是谨慎的做法。

  1. ionic cordova platform rm android
  2. ionic cordova resources android
  3. ionic cordova platform add android

Android Studio:安卓工作室:

  • Build > Generate Signed APK构建 > 生成签名的 APK
  • Next下一个
  • Keystore password - supply it.密钥库密码 - 提供它。
  • Next下一个
  • Finish结束
  • click locate in notification copy app-release-apk to wherever.单击通知中的定位将 app-release-apk 复制到任何地方。

If you continue to have issues.如果您继续遇到问题。 Run:跑:

ionic info

And paste output into your question as well.并将输出也粘贴到您的问题中。


UPDATED to reflect comments below:更新以反映以下评论:

I would presume your config.xml is somehow hosed .我想你的config.xml以某种方式被处理了

There is a section in it which associates icon and splashscreen.其中有一个部分将图标和闪屏关联起来。

This is what I have in mine for the android platform part.这就是我的 android 平台部分。

<platform name="android">
        <allow-intent href="market:*" />
        <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="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.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>

This part gets injected into the code by the这部分被注入到代码中

ionic cordova resources android

If you have src locations that don't relate to real artwork of icons/splashscreens then you are likely to get the error.如果您的 src 位置与图标/启动画面的真实图稿无关,那么您可能会收到错误消息。 Try manually deleting everything between:尝试手动删除以下所有内容:

<platform name="android">
 ....
</platform><!-- The one relating to android! -->

Then rerun from the top until the update section.然后从顶部重新运行,直到更新部分。

If all else fails, there may be more issues with the config.xml, in which case you could take more drastic actions...如果所有其他方法都失败了,那么 config.xml 可能会出现更多问题,在这种情况下,您可以采取更严厉的措施...

  1. It may be prudent to host your config.xml somewhere and link it in the original question rather than comments first though.将您的config.xml托管在某个地方并将其链接到原始问题中可能是谨慎的做法,而不是首先进行评论。 Somewhere like Googledocs perhaps first.像 Googledocs 这样的地方,也许首先。

If I am not around later to answer...如果我稍后不在附近回答...

  1. You could try creating a new scratch project just to get a clean config.xml.您可以尝试创建一个新的临时项目以获得干净的 config.xml。
  2. If you have many cordova plugins for native functionality, add those to your project with the ionic cli too to update config.xml appropriately.如果您有许多用于本机功能的 cordova 插件,也可以使用ionic cli将它们添加到您的项目中,以适当地更新 config.xml。 For example.例如。

ionic cordova plugin add cordova-plugin-inappbrowser@latestcordova-plugin-inappbrowser@latest

This incidentally adds these nodes to the config.xml这顺便将这些节点添加到 config.xml

<plugin name="..." spec="..." />
  1. manually update these again too.再次手动更新这些。

    • widget id property - eg com.yourdomain.yourappname小部件 id 属性 - 例如com.yourdomain.yourappname
    • name姓名
    • description描述
    • author作者
  2. In the meantime, at the os level delete the platforms folder from your original app project folder,同时,在操作系统级别从原始应用程序项目文件夹中删除平台文件夹,

  3. then rename config.xml to config-old.xml in the original project然后在原项目中将 config.xml 重命名为 config-old.xml
  4. and copy over the config.xml from the scratch project并从草稿项目复制 config.xml
  5. Then try the whole sequence of steps I have described above again (from the top until the update, returning to step 9 if all is ok at end.然后再次尝试我上面描述的整个步骤序列(从顶部到更新,如果最后一切正常,则返回到步骤 9。
  6. Delete the scratch project folder if everything works.如果一切正常,请删除临时项目文件夹。

Let me know if it helps.如果有帮助,请告诉我。

在您的 xml 配置中,您应该相应地指定引擎

<engine name="android" spec="7.1.4" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM