Ionic on Windows: Android SDK installed. Still get

2019-02-08 08:58发布

I have managed to break my previously working version of the Ionic enviroment. For example: I download the demo project "sidemenu" and run "ionic platform add android" without any problem. When I try to run "ionic build" I get the following message:

$ ionic build
Running command: "c:\Program Files\nodejs\node.exe" h:\git\Absolut\hooks\after_p
repare\010_add_platform_class.js h:/git/myapp add to body class: platform-android
Running command: cmd "/s /c "h:\git\Absolut\platforms\android\cordova\build.bat"
"
[Error: Please install Android target: "android-22".

Hint: Open the SDK manager by running: c:\Users\nicsj\AppData\Local\Android\android-sdk\tools\android.BAT
You will require:
1. "SDK Platform" for android-22
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)]
ERROR building one of the platforms: Error: cmd: Command failed with exit code 2

You may not have the required environment or OS to build this project
Error: cmd: Command failed with exit code 2
    at ChildProcess.whenDone (c:\Users\nicsj\AppData\Roaming\npm\node_modules\co
rdova\node_modules\cordova-lib\src\cordova\superspawn.js:134:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

I don't understand what causes the error message since android-22 is already installed. I have the SDK Platform-tools and build-tools as well. They are on the PATH:

.../c/Program Files (x86)/Java/jdk1.7.0_71/bin:/c/Users/nicsj/AppData/Local/Android/android-sdk/tools:/c/Users/nicsj/AppData/Local/Android/android-sdk/build-tools/22.0.1:/c/Users/nicsj/AppData/Local/Android/android-sdk/platform-tools

Ionic setup:

Cordova CLI: 5.1.1
Gulp version:  CLI version 3.9.0
Gulp local:
Ionic CLI Version: 1.6.4
Ionic App Lib Version: 0.3.8
OS: Windows 7 SP1
Node Version: v0.12.5

Android SDK:

C:\Users\nicsj>android list targets
Available Android targets:
----------
id: 1 or "android-22"
     Name: Android 5.1.1
     Type: Platform
     API level: 22
     Revision: 2
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.
----------
id: 2 or "android-23"
     Name: Android 6.0
     Type: Platform
     API level: 23
     Revision: 1
     Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, W
XGA720, WXGA800, WXGA800-7in
 Tag/ABIs : no ABIs.

This problem is new and I don't know what caused it. Any advice on where I should look?

7条回答
Explosion°爆炸
2楼-- · 2019-02-08 09:26

I've had the same issue. Problem was I was using cmder. Switching to windows cmd solved it for me.

查看更多
神经病院院长
3楼-- · 2019-02-08 09:34

I was having the same issue and this worked for me. I have Android Studio installed, which makes managing the SDK a lot easier.

1) When you launch Android Studio, click on the "Configure" option

2)Then click SDK Manager

4) Then select Android 5.1.1 which is the API level 22 that you need. Refer to the screenshot below.

Selecting the API version from Android studio

5) Hit Apply

This will installed the required android-22 that your build is asking for.

查看更多
冷血范
4楼-- · 2019-02-08 09:34

I also tried many settings to Use SDK 22

Config.xml

\platforms\android\project.properties

target=android-23

\platforms\android\AndroidManifest.xml

platforms\android\CordovaLib\project.properties

target=android-23

Nothing worked till I not accepted SDK 22 licenses via command line

Remember to accept or install license newly installed SDK otherwise build process will show you an error or will try to install SDK which licenses you installed into your system.

查看更多
劫难
5楼-- · 2019-02-08 09:37

Another possible reason might be that you have multiple Android SDK installations on your machine, and that Ionic is looking at the wrong installation, Ionic looks for the ANDROID_HOME environment variable, so make sure that it is set and pointing to the same location as the SDK manager you launch from Android Studio.

Modify or add that Environment Variable under the system path variables to make sure it applies to all users(you will have to relaunch command Prompt for changes to apply). Windows has two sets of environment variables, system and user, so if you run the command prompt as an Administrator for example you might get different environment variables.

You can read more here: https://superuser.com/questions/625643/why-is-my-path-environment-variable-different-from-the-command-prompt

查看更多
仙女界的扛把子
6楼-- · 2019-02-08 09:40

First of all, sorry for my dummy english. I just had the same problem and I fix it changing the target:

# Project target.    
target=android-22 (I had set this to android-23)

This should be done in two files:

yourApp/platforms/android/project.properties    
yourApp/platforms/android/CordovaLib/project.properties

Also the manifest should be updated:

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23" />
查看更多
等我变得足够好
7楼-- · 2019-02-08 09:43

Try to make the following steps one by one and will be working:

installation guide

See windows note and install all packages.You must have java jdk installed.And after set environement variable for ANDROID_HOME with command:set ANDROID_HOME="your android location".Hope this helps!

查看更多
登录 后发表回答