简体   繁体   中英

Ionic on Windows: Android SDK installed. Still get “Error: Please install Android target: ”android-22"

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?

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" />

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.

从Android studio中选择API版本

5) Hit Apply

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

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!

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

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

我遇到的问题是我在D:\\中运行构建,而SDK安装在C:\\中

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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