i'm new to cordova development and i created my first cordova project using this command as in following site
https://cordova.apache.org/docs/en/4.0.0/guide_cli_index.md.html
cordova create hello com.example.hello HelloWorld
After used these commands to add a platform to project,
cd hello
cordova platform add android
and command line gives these output
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: com.exampple.hell
Name: helloWorld
Android target: android-21
Copying template files...
Project successfully created.
according to this Android target of this project is android-21 but installed android SDK on my machine only has up to android API level 19. So when i import these project to eclipse IDE to make further changes to project it gives error on console
Unable to resolve target 'android-21'
I changed AndroidManifest.xml file as
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="19" />
but still have the problem.
can i change the android target to 19 when the platform is added to project or is there another way to fix this and run project with android API level 19
You should update your SDK on your machine first of all. The compatibility depends on your config.xml file content.
For example you want to support android levels from 16 to 19, then this part of the config.xml should look like this:
<preference name="android-minSdkVersion" value="16"/>
<preference name="android-targetSdkVersion" value="19"/>
The build method then takes care of AndroidManifest.xml.
Related
I am in the process of setting up a new Cordova CLI toolchain to build hybrid Android apps that target Android 5.1+. I am using
Node 8.9.2
Cordova 7.1.0
After issuing a cordova create... command to create a new Cordova project I proceeded to add Android 5.1 using cordova platform add android#5.1.0 which went smoothly.
I have also ensured that I have the relevant Android SDKs available and pointed at properly via ANDROID_HOME. I currently have SDKs 19 through to 27 installed.
However, when I issue a cordova build android I get the message Error: Android SDK not found. Strangely enough if I let Cordova install its current default Android version via cordova platform add android which adds Android 6.3.1 it then lets me build the project without any further ado.
Is this a matter of Cordova 7.1.0 simply not wanting to play ball with lower versions of Android or is there something else going on here? Can I get around this by installing an older version of Cordova via npm? If so, which version should I install - and how?
Your problem is you're adding an old version of the cordova-android platform project, (v5.1.0) which is over 2 years old and not compatible with the cordova#7.1.0 CLI.
If you want to target Android 5.1+, you don't need to use cordova-android#5.1.0, you need to specify a preference in the config.xml to target Android 5.1 (API 22) and above:
<preference name="android-minSdkVersion" value="22" />
You probably want to use the default cordova-android platform version (6.3.1), unless you need to do stuff with Android Studio 3, in which case use cordova platform add android#latest which will add cordova-android#7.0.0 and requires Gradle 4 to build (see here).
For a new Cordova project, I want to add Android as a platform using
cordova platform add android
And I want to use Android version 16. So I set these properties in the config.xml
<preference name="android-minSdkVersion" value="16" />
<preference name="android-targetSdkVersion" value="16" />
And I run
cordova platform add android --target android-16
Yet what I see in the logging is
Using cordova-fetch for cordova-android#~6.3.0
Adding android project...
Creating Cordova project for the Android platform:
Path: platforms\android
Package: io.cordova.hellocordova
Name: HelloCordova
Activity: MainActivity
Android target: android-26
So it still targets Android 26 instead of 16. Indeed, when I run cordova build, it builds using Android version 26. Why is that? What can I do to fix this?
The syntax you use to provide android version is wrong.
Instead of
cordova platform add android --target android-16
it should be
cordova platform add android#16
When using Cordova I want to build for Android API version 23.
When I do cordova platform add android then when I build the app by doing cordova build android. It builds for API 25 by default.
How do I go about setting the correct api version. Also mention what is to be installed in the Android-sdk.
Thanks
How do I go about setting the correct api version
In your config.xml, use a <preference> to set it:
<preference name="android-targetSdkVersion" value="23" />
Also mention what is to be installed in the Android-sdk
The API 23 platform SDK needs to be installed.
See the Cordova Android platform guide for more details.
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.
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
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
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" />
My problem got solved after installing SDK Platform of Andriod 5.1.1 (API 22) from Andriod Manager.
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.
$ cordova platforms remove android
$ cordova platforms add android#3.7.1
I am trying to build my cordova app for android, using ionicframework. I have set my target API level to 16 (I have that installed from Android SDK manager) but it somehow always picks up level 21.
in project/config.xml:
<preference name="android-targetSdkVersion" value="16"/>
in platforms/android/AndroidManifest.xml, it shows the same:
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="16" />
but running cordova build --release android I get:
-build-setup:
[getbuildtools] Using latest Build Tools: 22.0.0
[echo] Resolving Build Target for OpsVedaMobile...
[gettarget] Project Target: Android 5.0.1
[gettarget] API level: 21
I suspect I am missing some more settings, will appreciate help. I used the how-to from this ionic doc
ionic: 1.0.0.rc-5, ionic CLI: 1.3.22, cordova: 5.0.0, node: 0.10.36 - on Windows7
--EDIT
it appears that the target level didn't matter at all. I now wonder how/where does it become significant.
in latest ionic framework you can change the target by changing
ion1/platforms/android/AndroidManifest.xml
and change the 22 into these two files with 16
ion1/platforms/android/project.properties
ion1/platforms/android/CordovaLib/project.properties
ion1 = my project base folder
npm install -g cordova
above command always install latest cordova-android-version and so android-target is latest. So we can solve the above problem by installing appropriate cordova version.
you can install appropriate version of cordova using this command npm install -g cordova#5.0.0 where 5.0.0 is cordova-android-version.all version of cordova can be viewed using following command.
npm view cordova versions
4.1.X(cordova-android Version) supports 14-22 (API level) and
5.X.X(cordova-android Version) supports 14-23 (API level)
So this bit of xml does two things, sets the minimum api version for the android app, and sets the target, obviously because of their name.
So api 10 is android 2.3, which we've dropped support for. So we can bump that to 14, or android 4.0
Api 19 is 4.4 which is all good.
So these number are part of the default project structure that cordova makes. You could create a hook that after the project is add, it changes the default api level to 14 and 19 instead of manually doing it.
But to change it, go to platforms/android/android.xml, if you edit this, you should be good.
(or)
Before change:
] android update project --subprojects --path "platforms/android" --target android-19 --library "CordovaLib"
I changed this to:
] android update project --subprojects --path "platforms/android" --target android-14 --library "CordovaLib"
And then modified the AndroidManifest.xml file as you suggested, now all the debug states level 14 and it compiled. I just sent a copy over to my buddy again.. we'll see if it works!