How to check if plugin and android SDK are the same version? - android

I have made an Android app via the Cordova CLI. These are the steps I have taken :
cordova create myApp com.myCompany.myApp myApp
cd myApp
cordova plugin add cordova-plugin-camera --save
cordova platform add android --save
cordova requirements android
cordova build android --verbose
cordova run android
Thanks to : https://www.npmjs.com/package/cordova
This runs fine. So now I try and add this plugin : https://github.com/appfeel/admob-google-cordova
So I do :
cordova plugin add cordova-admob
This doesn't work as it comes back with this error :
Warning, could not copy necessary files for angular browser platfrom.
Please ensure 'www/lib/angular-admob.js' exists ...
So I created an empty file named lib in my www folder. Remove the plugin :
cordova plugin remove cordova-admob
Then re-add :
cordova plugin add cordova-admob
This seemed to work. So now I build and get this error :
Now I have searched for the problem and come across this : Error retrieving parent for item: No resource found that matches the given name after upgrading to AppCompat v23
The answer is as follows :
Your compile SDK version must match the support library's major
version.
Since you are using version 23 of the support library, you need to
compile against version 23 of the Android SDK.
Alternatively you can continue compiling against version 22 of the
Android SDK by switching to the latest support library v22.
I'm not sure how to do this with the Cordova files I have, so my question is, how do I make sure that both the plugin and the android sdk are on the same versions ? If this even is my problem.

Related

How to find out versions of dependencies used in compiled Cordova app?

Background: I have a Cordova app release binary (signed .apk for Android) which was built in an unknown build environment. I have the source code; but I need to find out the version of every dependency that was actually used to build that apk.
Example: Which version of Cordova itself? Which version of each plugin? Which version of npm/nodejs?
How would I get this info from the apk?
(Note: Part of the reason is that if I just re-build this from source using whatever versions of plugins config.xml resolves to, it is buggy; the original is not)
You can get the Cordova version and version of each plugin that you have installed but I am not sure about how to get the npm version.
If you have the apk then extract(rename the extension to .zip) it. To find
Cordova version
Open cordova.js in assets/www/cordova.js. you can find one statement like following
var PLATFORM_VERSION_BUILD_LABEL = '8.1.0';
In my case, the Cordova version is 8.1.0.
Installed plugin version
Open cordova_plugin.js in assets/www/cordova_plugin.js
There you will find your plugins in
module.exports.metadata = {
...
}

Cordova build issue relating to fontVariationSettings

I am having a build issue with a Cordova project that I have inherited specifically the error raised is: -
:CordovaLib:transformClassesAndResourcesWithPrepareIntermediateJarsForDebug
:app:processDebugResourcesC:\Users\andy.gradle\caches\transforms-1\files-1.1\support-compat-28.0.0.aar\96270291fb4c7e49ddab8d4d1a4f36f7\res\values\values.xml:133:5-70: AAPT: error: resource android:attr/fontVariationSettings not found.
I have another project which builds successfully and the difference between the two projects appears to be the platforms\android\project.settings file, if I manually change the setting my project builds. However as this file appears to be re-created every time I run cordova prepare android this is not an ideal situation, the setting in question is: -
cordova.system.library.1=com.android.support:support-v4:+
if I change this to: -
cordova.system.library.1=com.android.support:support-v4:24.1.1+
my build is successful!
So my question is what impacts this setting, as I feel I need to understand the reasoning behind the differing value as other than the working project having more dependencies the non-working project contains the same references but has one additional dependency this being: -
cordova-plugin-file-opener2
I do not have SDK version 28 installed, I can see the logic behind the error and I would assume installing version 28 may resolve the issue but I would like to understand why one project creates the settings with one version number and the second project is created with a differing one?
In Cordova projects, the versions of native libraries pulled into the Android build via Gradle are controlled directly by the Cordova plugins you have installed in your project.
The Gradle config is dynamically generated by Cordova, so each time you run cordova prepare android, the build.gradle file is regenerated.
In this case, the library dependency is the Android Support Library (com.android.support).
cordova-plugin-file-opener2 specifies version + which will pull in the very latest version, which is currently v28.0.0 as can be seen on the releases page.
However, if another plugin in your project specifies a different version, this will lead to problems and often build failures due to version conflicts.
In a native Android project, the build.gradle file is under your direct control, so you'd never have these problems.
One solution is to install the cordova-android-support-gradle-release plugin into your project.
This plugin overrides the versions of the Android Support Library specified by other plugins, enabling you to align the versions and so fix the build problems.
For example, in your case you can run:
cordova plugin add cordova-android-support-gradle-release --variable ANDROID_SUPPORT_VERSION=24.1.1
This will install the plugin and override the versions specified by other plugins to ensure v24.1.1 of the Support Library is included in your project.
One consideration is that v24 is quite old, so you may want to try a newer version, e.g.:
cordova plugin add cordova-android-support-gradle-release --variable ANDROID_SUPPORT_VERSION=27.+
Just to add some detail to my solution just in case it helps anybody else in the future!
DaveAlden added a very helpful description above of what is happening which is worth reading through as it is very difficult to get a clear concise explanation of what is or should be happening with these technologies.
My project did indeed already have the cordova-android-support-gradle-release plugin installed and it was set to 27.+ however I followed the following process and everything then started working: -
Updated my Android SDK software to the latest
Updated Cordova from version 8.0.0 to 8.1.2
Removed plugin cordova plugin add cordova-android-support-gradle-release
Added plugin back in cordova plugin add cordova-android-support-gradle-release --variable ANDROID_SUPPORT_VERSION=27
I then retried the build and everything then started working.
UPDATE:
I came to deploy my app again today and I have got the same error again, to resolve it I ran: -
cordova plugin remove cordova-android-support-gradle-release
cordova plugin add cordova-android-support-gradle-release --variable ANDROID_SUPPORT_VERSION=27.+
and it then builds successfully, I have no idea why this occurs but it is something to do with the \platforms\android\project.properties file not being setup correctly as when it builds successfully this file contains the following line: -
cordova.gradle.include.1=cordova-android-support-gradle-release/portal-cordova-android-support-gradle-release.gradle
I'm sure somebody with a clearer understanding of the build process could add some clarity!

Cordova failed to install 'cordova-plugin-whitelist': Error: ENOENT: no such file or directory AndroidManifest.xml

I have Cordova 8.0.0 on OSx 10.13.2 with Node v8.5.0 and npm v5.5.1.
After adding plugin cordova-plugin-ibeacon, when I do a cordova platform add android, I am getting following error:
failed to install 'cordova-plugin-whitelist': Error: ENOENT: no such file or directory AndroidManifest.xml
Screenshot:
You are using cordova-android#~7.0.0
I have faced same issues with recent pull of cordova-android repo with Cordova 8.0.0
Downgrade cordova-android to 6.4.0 as follows:
cordova platform remove android
cordova platform add android#6.4.0
This is a bit late. But sharing some personal observations when I encountered similar issues.
The build process fails if there is an old plugin that is not updated to work with the platform#7.0.0. At least this is the case for me. After installing this incompatible plugin, it would mess up the files in platform. After which trying to salvage the project by removing the plugin would also fail, because the files would have been put in the wrong directories when installing. You would have to remove the platform "cordova platform rm " followed by the misbehaving plugin "cordova plugin rm " and re-add back your platform before the the build can fixed.
Why android#6.30 and android#6.4.0 may work is because it is probably using the older platform project directory layout, where it appeared to use the top level /platforms/android directory for 'res' and 'libs' folder.
From android#7.0.0 onward, I notice it added the 'app' subdirectory, and your 'config.xml' and 'res' are expected at '/platforms/android/app/src/main/res/xml/config.xml' and not '/platforms/android/res/xml/config.xml'.
Older plugin may have installation/removal scripts that copy the files to the wrong places.
The only 2 ways to fix this problem is to update the plugin or downgrade the platform as suggested by Bharat Biswal.
If anyone has a more definite answer, that would be great.
You are using cordova 7.0.0 or cordova 8.0.0,
similar issue is observed with IONIC as well
You will find this issues with most of the plugins
such as admobpro, admob, itablet, whitelist etc.
Better for now roll back to previous cordova version i.e 6.3.0 or 6.4.0
If you see mentioned issues with any of plugins try this.
cordova platform remove android
cordova platform add android#6.3.0
OR
cordova platform remove android
cordova platform add android#6.4.0

Cordova / Ionic build android Gradle error: Minimum supported Gradle version is 2.14.1. Current version is 2.13

This is a solution to the above error that I want to document. I found other similar posts, but none described how this error can be associated with Cordova or Ionic.
If you are not careful, there can be a mismatch between the version of Gradle that Android Studio uses and the version of Gradle that Cordova / cordova-android specifies in its auto-generated application code. As you know, running
$ cordova platform add android
(or $ ionic platform add android, if you are building an Ionic app) creates the native application code at the-project/platforms/android.
Inside that folder, the file: /the-project/platforms/android/cordova/lib/builders/GradleBuilder.js exports a variable as shown below:
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'http\\://services.gradle.org/distributions/gradle-x.y-all.zip';
Where x and y depened on which version of Cordova / cordova-android are being used to build the native application code.
When you run
$ cordova build android
The version of Gradle specified in the distributionUrl var is the version used for the build.
Now here comes the tricky part. When you import the project into Android Studio, you will most likely get a message strongly recommending that you upgrade Gradle to a newer version, as shown below:
If you do this, Android Studio will download a new version of Gradle and store it locally and configure the project to use the newly download local Gradle distribution, which is the radio option below the selected “Use default grade wrapper”, which I ended up deselecting because this will cause errors.
This will cause problems because Android Studio and Cordova will now be attempting to build the application with different versions of Gradle and you will get build errors within Android Studio and also with
$ cordova build android
in the command line. The solution with Cordova apps is to always keep the Android Studio project set to "Use default gradle wrapper" and ignore the tempting messages to upgrade. If you do want to use a newer version of Gradle, you can always change the distributionUrl var in the file mentioned above (however Cordova strongly discourages modifying code within the platforms folder since it is easily overwritten). At the time of writing this, I cannot tell is there is a way to set the Gradle version at the
$ cordova platform add android
step, which is when you would want to do it so you are never directly modifiying code inside of the-project/platforms
For me, the following commands solved the problem:
cordova platform remove android
cordova platform add android
ionic build android
I'd love to just leave this as a comment, but I'm apparently not reputable enough...
After reading your documentation, I wasn't able to resolve my issue with your suggestion of keeping the Android Studio to "Use default gradle wrapper". What I did find is that setting the session variable CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL before building got me a bit further:
root#dev:$ export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="https\://services.gradle.org/distributions/gradle-2.14.1-all.zip"
root#dev:$ cordova build android
The next thing I had to do was edit <project>/platforms/android/build.gradle and <project>/platforms/android/CordovaLib/build.gradle and make sure they both pointed to a valid gradle plugin version.
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
}
...and in <project>/platforms/android/CordovaLib/build.gradle I added jcenter in the repositories (because maven.org did not seem to have 2.2.0)
repositories {
mavenCentral();
jcenter()
}
I was able to build then.
Switching back to "Use default gradle wrapper" didn't work for me on my ionic 1 project, but running
ionic platform remove android
ionic platform add android
Worked for me
Another way to fix issue, that also works on Windows:
cordova build android --release --CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
you can change the value in platform/android/cordova/lib/builders/GradleBuilder.js
the value you changed, it will be replaced by the lastest gradle zip when you reinstall android platform, so you don't need to worry about change it
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-2.14.1-all.zip';
or like the others ans
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="https\://services.gradle.org/distributions/gradle-2.14.1-all.zip"
I want to extend #bungler answer.
I got confused with version of gradle & compatible version of android plugin for gradle. Following link has the list of compatibale versions mapping:
Gradle vs Android plugin for gradle - Compatible version list
For current version of gradle 3.3+, compatible version of android plugin is 2.3.3
So final settings will look like following:
For Mac
STEP 1: Add following in env variables:
option a) update env variable:
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="https\://services.gradle.org/distributions/gradle-3.3-all.zip"
or
option b ) you can download the gradle file and place it in <project>/platforms/android/gradle/ and update env variable:
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL="../gradle-3.3-all.zip"
STEP 2: Update following in <project>/platforms/android/CordovaLib/build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
}
This worked for me.
For follow error:
Minimum supported Gradle version is 4.1. Current version is 3.3. If
using t he gradle wrapper, try editing the distributionUrl in
E:\ionic\MyIonicProject\gr adle\wrapper\gradle-wrapper.properties to
gradle-4.1-all.zip for gradle 4.1
This command worked for me:
ionic cordova platform update android
In follow up to Chuck Holbrooks answer, with following solution I get an error when trying to add android platform again saying it is already added.
ionic cordova platform remove android
ionic cordova platform add android
My working Solution:
ionic cordova platform remove android
ionic cordova platform check android
ionic cordova platform add android
if you run the following it will fix the problem building APKs from the command line
ionic cordova platform remove android
ionic cordova platform add android
however, after you run/build it in android studio the version mismatch error returns...
instead to fix this, in android studio you should NOT update the project gradle versioning but instead go to
file > project structure > SDK location > Gradle settings...
and then tell it to use Gradle from a specified location which should be
C:/Gradle/gradle-7.4.2 or whatever version you have.
By doing this you will be able to build APKs from the command line using ionic as well as from within android studio.

How to upgrade from phonegap 2.9 to phonegap 3.5 (project directory could not be found error)

I have an android application that i built on PhoneGap 2.7.I installed phonegap 3.5 using cmd and tried to upgrade an app as shown here
How do I upgrade Phonegap in my Phonegap app?
But when i do it using cmd it gives me the following error:
Unlike phonegap 3.5 the android application that I built in PhoneGap 2.7 does not have a platform folder.So what am I supposed to?and how can I verify if it is upgraded or not?
I had also seen these phonegap documentation
http://docs.phonegap.com/en/3.5.0/guide_platforms_android_upgrade.md.html#Upgrading%20Android
But It does not show how to directly upgrade from 2.7 to 3.5
I don't think phonegap platform update works for upgrading from something older than 3.x.
For phonegap/cordova cli to work it has to detect a project with the structure of 3.x projects.
To upgrade your project in 2.x you have to
install phonegap or cordova cli (which you seem to already have done, but if you don't plan on using phonegap build, I suggest you use
cordova instead of phonegap. if not please replace cordova by phonegap
in next steps)
open a cmd and cd to a folder in wich you will want to put your project
create the new project from the www folder you had in your old project:
cordova create nameforprojectfolder com.test.app Testapp --copy-from=pathtooldwwwfolder
change current dir to the newly created folder
add the android platform:
cordova platform add android
in cordova/phonegap 3.x no plugin is added by default so you will have to add all the plugins you use :
cordova plugin add uri.of.plugin
customize config.xml to your needs
build the android project (this will create files in the platforms/android folder)
cordova build android
You may need to customize AndroidManifest.xml in platforms/android/AndroidManifest.xml
Now you can use the CLI to work with your project.

Categories

Resources