Info about 'cordova platform add android' command - android

I'm a newcomer to the Cordova development world and I feel somewhat confused about the cordova platform add android command.
In a command like cordova platform add android#version, I don't know what is the relation between the specified 'version' and the targeted android platform. The command cordova platform add android (that is cordova platform add android#6.3.0), targets android-26 platform (that is, the platform intended for Android 8.0.0 OS with API level 26).
Or am I completely wrong? Any clarification would be pretty appreciated. Thanks.

There is no relationship between them
When you add the platform with a version you specify a cordova-android version from the released ones. If you don't specify one, it will install the version pinned on the Cordova CLI (or higher patch version if available). Again, the Cordova CLI version has no relationship with cordova-android version or Android targeted version.
cordova-android uses semver for it's versions, that is, major.minor.patch
When there is a breaking change, the first number is changed, and changing the target SDK is not always a breaking change.
All the platform updates are announced on the Cordova blog, make sure you read it frequently so you can be informed of new CLI, platforms and plugins releases

Related

Combination of versions that will build crosswalk cordova plugin for android 4.0

I want to give support to Android 4.0 using the crosswalk cordova plugin. The problem is that crosswalk stopped giving support for that version of Android, nevertheless in this post, they communicate that it is possible to run crosswalk in Android 4.0 through the version 19 of crosswalk which is the version 1.8.0 of the crosswalk cordova plugin.
Nevertheless, that cordova plugin version of crosswalk doesn't build with recent versions of cordova. The question is what versions of cordova, cordova-android (the platform) and Android API level will build for crosswalk cordova plugin 1.8.0 which will run on Android 4.0 (API level 14)?
I know the easy way is just to stop giving support for those versions but that would mean to lose a few clients and we don't want that if there is way to get around that. Also, the newer the version the bigger the APK package will be and therefore the more they are reluctant to install an App. For those reasons, it would be better to use older versions.
I have done a research on the subject and I found the combination of versions that will build and support Android 4.1 (API level 15 and up). the combination is:
#if you have cordova installed, you will need to uninstall first
npm uninstall -g cordova
npm install -g cordova#7.0.1
cordova platform add android#6.2.3
# The previous combination of versions will build the newest version of crosswalk (2.4.0)
cordova plugin add cordova-plugin-crosswalk-webview
Build cordova using the Android API level 26, not newer because at this moment it doesn't build with API 28

Android PlayStore warning your app currently targets API level 25

Warnings Your app currently targets API level 25 and must target at
least API level 26 to ensure it is built on the latest APIs optimized
for security and performance.
From August 2018, new apps must target at least Android 8.0 (API level
26). From November 2018, app updates must target Android 8.0 (API
level 26).
Tip: Change your app's target API level. Learn how.
I am using Cordova and Ionic 3.
Just built the app using: ionic cordova build android --release-prod
What should I do, ignore this or fix and how?
Thanks.
You can update your cordova-android to 7.0.0 as that's the version that uses SDK 26 as target, or you can update to cordova-android 7.1.4, as it targets SDK 27.
You can do it by removing the platform and adding it again specifying the version to use like this: (if not using ionic, remove the ionic word from both commands)
ionic cordova platform rm android
ionic cordova platform add android#7.1.4
If you don't want or can't update, you can try to set the target SDK with this preference in the config.xml
<preference name="android-targetSdkVersion" value="26"/>
And then run ionic cordova prepare
This is because Google has made it compulsory for apps to target at least 26 API level by August 2018 for new apps and November 2018 for updating apps.
Docs here.
You can do it by removing the platform and adding it again specifying the version to use like this: (if not using ionic, remove the ionic word from both commands)
ionic cordova platform rm android
ionic cordova platform add android#7.1.4
If you don't want or can't update, you can try to set the target SDK with this preference in the config.xml
And then run ionic cordova prepare
This worked for me!

How to specify the Android API version by adding in Cordova

After creating a mobile-first Cordova project with the command:
cordova create cordovatest1 com.sample.cordova cordovatest1 --template cordova-template-mfp
I add the Android platform to the project with the command:
cordova platform add android
the question is why the Android version for the platform which was just added takes the Android API 23 / android version 5.1.1, even I have already other API levels: 22, 25, 27 in SDK manager?
is there a config file belong to Cordova says that the Android platform must be for example android-23 if the developer didn't specify the Android version by adding like
cordova platform add android#6.1.2
or maybe the mobilefirst-cli witch is already installed under the version 8.0.0 force that adding platforms?
This screenshot can give you more details
This is unrelated to IBM MobileFirstPlatform SDK plugin. The Android target is determined by your Cordova version.
For example, cordova-android#6.1.2 targets Android API Level 25.
cordova-android#6.3.0 targets Android API Level 26.
Details here.
You have not mentioned your Cordova CLI version. Since you see cordova-android#5.1.1 being added, it seems to be Cordova CLI version 6.0.
The results would be the same if you were to create a blank Cordova project ( without cordova-template-mfp) and then add platform.
why the Android version for the platform which was just added takes
the Android API 23 / android version 5.1.1
Because you have saved Android 5.1.1 in npm-cache.
Check npm-cache folder:
C:\Users\Training\AppData\Roaming\npm-cache\cordova-android
Currently the Cordova android platform versions supported by the MobileFirst plug-ins, is:
cordova-android: >= 6.1.2 and < 9.0
Try using these command:
To upgrade:
cordova platform update android#9.0
To add it explicitly:
cordova platform remove android
cordova platform add android#9.0
or
cordova platform add android#latest
For more details see here : https://mobilefirstplatform.ibmcloud.com/tutorials/en/foundation/8.0/application-development/sdk/cordova/

Cordova not building app

I am new to cordova. Trying to work out with it but when I check requirements it says Android Target not installed while I have installed SDK in Android Studio.
Required information for troubleshooting can be found here.
I am using Windows 8.1 32 bit installation. I have already tried previous answers found oh the site.
Update
I just noticed that running cordova build android gives
D:\Android\Apps\hell>cordova platform ls
Installed platforms:
android 7.0.0
Available platforms:
browser ~5.0.1
ios ~4.5.4
osx ~4.0.1
windows ~5.0.0
www ^3.12.0
Indicating android version to be 7.0.0 thus API is 24.
But D:\Android\Apps\hell\platforms\android\CordovaLib\project.properties have :
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
target=android-26
apk-configurations=
renderscript.opt.level=O0
android.library=true
Here target is set to android-26, which is Android 8.0
From what I can tell the path setting for the SDK is missing. Check the Cordova documentation for that. Follow it to the letter.
Also Android 7.0.0 is not the version of Android, but of the Cordova code for Android.
Josem might be onto something as well, unless you've already done that step.
Perhaps the platform android is not installed.
Can you see it?
ionic cordova platform list
If it is not there, you can add it:
ionic cordova platform add android
Here is the documentation.

Cordova does not "see" Android SDK version

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).

Categories

Resources