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).
Related
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
I build a simple ionic project from this tutorial.
It runs on Xiaomi Mix 2 phone (android version 8.0.0) and on browser without any problem.
But when I deployed to the samsung note 2 (android version 4.4.2),
it gives an application error with this message:
net::ERR_CONNECTION_REFUSED (http://localhost:8080)
Why am I getting this error?
Any advice and suggestions will be appreciated.
Kemal.
I faced the same problem in Android 4.4, Android 6.0 but not in Android 8.0. I just added this code in config.xml to allow the localhost.
<allow-navigation href="http://localhost:8080/*"/>
For more information please follow this link:
WKWebView
Your problem is caused by the cordova-plugin-ionic-webview plugin that is part of every new or updated Ionic app.
This used to apply only to iOS, where it replaced the UIWebView with WKWebView, but on July 23rd 2018 they released version 2.0 of the plugin, that also included changes to the webview used on Android.
The Android webview now uses a local webserver at localhost:8080 to show your app instead of requesting the files directly from the file system.
Unfortunately this change also included this bit in the documentation:
Requirements
- […]
- Android: Android 5.0+ and cordova-android 6.4+
So cordova-plugin-ionic-webview just doesn’t support Android earlier than 5.0 any more, which of course means your app will not work on Android 4.x.
One solution is to downgrade the plugin to the last version that supported Android 4.x:
ionic cordova plugin add cordova-plugin-ionic-webview#1.2.1
More elaborate information and alternative solutions:
https://ionic.zone/debug/ionic-and-android-4
In case anyone is still not able to resolve this error,
Find the compatible webview version which works for you and run the below commands:
cordova plugin rm cordova-plugin-ionic-webview
cordova plugin add cordova-plugin-ionic-webview#4.1.3
In case you're using ionic, install the ionic plugin wrapper. (Skip this if your project is not an ionic project)
npm install #ionic-native/ionic-webview
Finally do clean installation of the platform and plugins. Delete
the plugins folder and run the following commands:
cordova platforms remove android
ionic cordova build android
Or, if you use ionic,
ionic cordova platforms remove android
ionic cordova build android
Additional information: Plugin version cordova-plugin-ionic-webview#4.1.3 worked for me for the below cordova and android versions:
Cordova CLI : 9.0.0 (cordova-lib#9.0.1)
Cordova Platforms : android 8.1.0
Android target : android-28
Android SDK Tools : 26.1.1
cordova-android : 8.1.0
You are getting the error because every function and module in Android only works from a certain version on newer. It could be 4.4.3 and up, 5.0 and up, or even 8.0 and up. It just depends. This means if and when you deploy it you will be required to select a minimum version. There is nothing you can do to fix it other than trying on a newer version. You can also change the code completely to work with older modules.
I've had same error even on new devices. After that, I've reinstalled cordova-plugin-ionic-webview plugin. Reinstallation upgraded plugin from 4.0.0 to 5.0.0 and added new line to config.xml:
<allow-navigation href="http://localhost:8100" sessionid="f8f1cc34" />
I'm still waiting for review, but hope this will help.
I had this problem for days and all the solutions I found did not work.
Ionic recommends using Capacitor to build the app and not Cordova. With Cordova does not work, on the other hand with Capacitor it works fine.
In your app directory first delete the Android folder (if any) and the one in Platform / Android folder.
I used these commands in this order launched by Powershell while staying in the APP directory
ionic build
ionic capacitor add android
npx cap open android
The first command will create a www folder.
If the last command give an error and does not open Android Studio, do it manually, (I recommend using 4.0 version). Open Android Studio → open folder, navigate to the folder named Android located in the folder in your APP and then it worked for me. In Android Sudio 4 make sure you have Gradle updated and the SDK loaded.
/android/CordovaLib/src/org/apache/cordova/engine/SystemWebViewClient.java
onReceivedError(WebView view, WebResourceRequest request,
WebResourceError error) {
super.onReceivedError(view, request, error);
if (error.getErrorCode() == WebViewClient.ERROR_CONNECT) { //net::ERR_CONNECTION_REFUSED
view.goForward();
return;
} else {
errorMessage();
}
}
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/
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.
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