简体   繁体   English

似乎无法从离子项目生成 APK

[英]Can't seem to generate an APK from ionic project

i am new to ionic, trying to get an apk for debugging i used the following commands inside the project directory:我是 ionic 的新手,试图获得一个用于调试的 apk 我在项目目录中使用了以下命令:

ionic cordova platform add android

i did get "platforms/android" directory我确实得到了“平台/安卓”目录

and then i used:然后我使用了:

ionic cordova build android

this is what i get after:这就是我得到的:

     ionic-app-scripts build --target cordova --platform android
[23:57:19]  ionic-app-scripts 3.1.10
[23:57:19]  build dev started ...
[23:57:19]  clean started ...
[23:57:19]  clean finished in 10 ms
[23:57:19]  copy started ...
[23:57:19]  deeplinks started ...
[23:57:19]  deeplinks finished in 36 ms
[23:57:19]  transpile started ...
[23:57:27]  transpile finished in 8.13 s
[23:57:27]  preprocess started ...
[23:57:27]  preprocess finished in less than 1 ms
[23:57:27]  webpack started ...
[23:57:28]  copy finished in 8.97 s
[23:57:35]  webpack finished in 7.63 s
[23:57:35]  sass started ...
Without `from` option PostCSS could generate wrong source map and will not find Browserslist config. Set it to CSS file path or to `undefined` to prevent this warning.
[23:57:40]  sass finished in 4.83 s
[23:57:40]  postprocess started ...
[23:57:40]  postprocess finished in 28 ms
[23:57:40]  lint started ...
[23:57:40]  build dev finished in 20.79 s
[23:57:44]  lint finished in 3.91 s
> cordova build android

You have been opted out of telemetry. To change this, run: cordova telemetry on.
Android Studio project detected
(node:12696) UnhandledPromiseRejectionWarning: CordovaError: Failed to find 'ANDROID_HOME' environment variable. Try setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
    at C:\Users\h2001\Desktop\myApp\platforms\android\cordova\lib\check_reqs.js:305:19
    at _fulfilled (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:854:54)
    at self.promiseDispatch.done (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:883:30)
    at Promise.promise.promiseDispatch (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:816:13)
    at C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:877:14
    at runSingle (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:137:13)
    at flush (C:\Users\h2001\Desktop\myApp\platforms\android\cordova\node_modules\q\q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
(node:12696) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:12696) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

but i didn't get the promised \\build\\outputs\\apk, what is the problem?但我没有得到承诺的\\build\\outputs\\apk,有什么问题?

UPDATE: i installed android studio and updated it, still getting更新:我安装了 android studio 并更新了它,仍然得到

(node:12696) UnhandledPromiseRejectionWarning

UPDATE: the problem was solved, turns out i had java10 which wont work with android, simply installing java8 solved the problem更新:问题解决了,原来我有java10,它不适用于android,只需安装java8就解决了问题

btw, i dont have android sdk installed if that makes any difference?顺便说一句,我没有安装android sdk,如果这有什么区别吗?

You have answered your own question.你已经回答了你自己的问题。 To make an Android APK制作 Android APK

  • You need Java SDK 1.8.您需要 Java SDK 1.8。
  • Android SDK with latest build tools and platforms带有最新构建工具和平台的 Android SDK
  • JAVA_HOME & ANDROID_HOME environmental variables set correctly. JAVA_HOME & ANDROID_HOME 环境变量设置正确。

Also You need updated X-Code on a Mac to create an IPA.您还需要在 Mac 上更新 X-Code 来创建 IPA。

You probably doesn't have android environment variable in your PC.您的 PC 中可能没有 android 环境变量。 if you are running MAC try running:如果您正在运行 MAC 尝试运行:

sudo export ANDROID_HOME=/<installation location>/android-sdk-macosx
sudo export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

If you are running Linux then:如果您运行的是 Linux,则:

export ANDROID_HOME=/<installation location>/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

And if you are running Windows then open your command prompt as Administrator and run:如果您运行的是 Windows,请以管理员身份打开命令提示符并运行:

set ANDROID_HOME=C:\<installation location>\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools 

It will add enviroment variable to your system.它将向您的系统添加环境变量。

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

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