Cordova build: Please install Android target: “and

2019-01-08 21:37发布

问题:

I'm struggling with my phonegap setup and building my first app.

I created a hello1 project. I added the android project

Platform android already added

Now when I run the cordova build, I get the error -

Error: Please install Android target: "android-22"

I do not have android-22. I do have android-19. I want my project to be built with android-19. How can I make that happen?

I had android-22 which I uninstalled (for fixing a bigger problem). I do not understand which file should I be making a change in for this to work. The project.properties in the project comes after this step and it automatically contains the target as android-22.

I have added my env variables correctly. C:\Users\user\android-sdks\platform-tools;C:\Users\user\android-sdks\tools

It doesn't help. This is just part of a bigger problem that I'm trying to debug. Please help.

回答1:

For SDK 21 ("android-21")

$ cordova platforms remove android
$ cordova platforms add android@3.7.1

For SDK 22 (Android 4.1.1, "android-22")

$ cordova platforms remove android
$ cordova platforms add android@4.1.1

More info: https://cordova.apache.org/announcements/2015/07/21/cordova-android-4.1.0.html



回答2:

Change these two. I din't try it for lower versions but this worked for me in upper versions

target=android-22<br>

This should be changed in two files like below:

target=android-19<br>

Location of the two files:

myApp/platforms/android/project.properties
myApp/platforms/android/CordovaLib/project.properties



回答3:

I am using cordova 3.5.0 which by default has target sdk as 19. You can install cordova 3.5.0 using

npm install -g cordova@3.5.0-0.2.6

For other versions of Cordova if you want to manually edit it you have to change this in AndroidManifest.xml file present in yourapplication/platfomrs/android.

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="19" />


回答4:

My problem got solved after installing SDK Platform of Andriod 5.1.1 (API 22) from Andriod Manager.



回答5:

Steps:

  • $ /Users/username/Library/Android/sdk/tools/android
  • Install Android 5.1.1 (API 22)
  • $ cordova platforms add android@4.4.2
  • $ cordova build --release android

It works for me.



回答6:

$ cordova platforms remove android
$ cordova platforms add android@3.7.1


回答7:

Just reopening the command line fixed it.