Making an android project with cordova, when I try to making a build, it failed with this issue:
execution failed for task ':app:compileDebugJavaWithJavac'
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0
These are my versions:
Cordova: 10.0.0
Android Platform: 10.1.2
Gradle: 7.1.1
I am absolutely sure that Gradle is installed when I install the Android platform (and it is out of my control) and that everything was working fine until 1 month ago ... and I have not changed anything
How I can fix this issue???
Have I to update Gradle? How?
Have I to update the project? How?
it's very strange ... and frustrating
Updating gradle solves the problem.
There are different ways to update the gradle, as explained in their official website: https://gradle.org/install/
Assuming that you are a windows user:
Downloading binary files of gradle and extracting the folder to the directory "c:/gradle" is enough.
Download binary files of gradle for the next version
Update path of gradle in PATH variable in your computer
You should define another variable as follows:
Variable name should be the same and its value should be the same with the one you use. While creating your cordova environment, this url is being used.
Save and restart your IDE's or CLI windows
test it out like ´gradle -v´ and you should see the active version of gradle in your system.
Be prepared to the new problems in your cordova environment because you have a upgraded gradle now
To fix the issue, I've reverted to cordova-android version 9.1.0. I've no idea, as of now, why cordova-android version 10 points to gradle, which as of now isn't possible to download...
This one sounds a little bit weird!
I'm building an app with cordova, and I'm trying to implement firebase. I'm receiving the following error whenever I try to build
Failed to apply plugin [class 'com.google.gms.googleservices.GoogleServicesPlugin']
For input string: "11+"
I've had a look on stack overflow and the fix is to remove the + from the build.gradle dependencies. I remove it and then build through android studio which works great, but whenever I try to build via cli using cordova build android, it reverts the build.gradle and adds the + back on and the build fails.
I need able to build via Cordova build android because if I don't build the application again via the cli, my changes to the code are not recognized!?
It's almost like every time I make a change, I have to run the build for the code changes to be recognized.
How can I build via cordova build android without it adding the + back into the build.grade?
In a Cordova Android project, any files (including build.gradle) inside the platforms/android/ directory are considered volatile and should not be manually edited. In fact if you run cordova platform rm android the entire platforms/android/ directory will be deleted. The build.gradle file is dynamically recreated every time the cordova prepare lifecycle event takes place using a template from cordova-android and then is dynamically modified as Cordova plugins, etc. are processed.
So whatever solution you choose needs to work with the Cordova build lifecycle.
One option to is to use 3rd-party plugins to override the library versions specified by other Cordova plugins in order to align them and prevent such build failures, for example:
cordova-play-services-version-adapter
cordova-android-support-gradle-release
cordova-android-play-services-gradle-release
cordova-android-firebase-gradle-release
I'm using cordova in one project with 15+ plugins. After updating to the latest cordova cli + cordova android library, a couple of plugins started to fail. I identified the issue has to do with the android dependencies added by each plugin. On the files project.properties and build.gradle in app folder I noticed duplicated entries for 'com.android.support:support-v4:27'. After I edited manualy build.gradle to add only one 'com.android.support:support-v4' matching my sdk, it worked.
** My platforms & plugins folders are not checked in my github. They are generated automatically, so I don't have the option to edit them directly.
**
Using cordova 8.1.2 and cordova-android 7.1.4
Q1: How can I make sure my android cordova project has unique compat libraries?
Q2: How can I overwrite or remove jar libraries from the project generated by cordova?
Thanks
The following plugin did what I needed fixing the issue. Basically I had a conflict of android support libraries with mismatching versions. The plugin resolves the conflicts fixing all android dependencies with the one I specified.
https://github.com/dpa99c/cordova-android-support-gradle-release
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.
Im having trouble building my app through the build process of Telerik Appbuilder. We are using a modified version of the multi imagepicker plugin wich has a reference to the android-support-v4.jar in the plugin.xml, like so
<source-file src="src/android/Library/libs/android-support-v4.jar" target-dir="libs"/>
When I try to create a build via de Telerik AppBuilder option it gives the following error and doesnt complete the build.
android-support-v4.jar" already exists
When I remove the reference from the plugin.xml and try create a build again, it finishes the build without any errors but then the plugin does not work.
I've already tried to use the plugin in a cordova (5.4.1) test project and have build it via CLI commands. With cordova I can successfully build a test project with the plugin and the reference to the android support library in place. The test app deploys succesfully to my android device via cordova run android The plugin and its modifications are fully functional in the test project.
FYI => If I remove the android support library reference in the plugin.xml in the cordova test project the entire project does not build. I get loads of compiling errors.
Does anyone has had the same experience or has an indication of what causes the error when I build via the Telerik Appbuilder tools?
The error for conflicting android-support-v4.jar is caused by having incompatible plugins in your project. In order to use the latest available android support v4 library you should remove the jar from your plugin and replace the lib-file element of your plugin.xml with <framework src="com.android.support:support-v4:+" />.
Additionally, if you have other plugins which install their own version of the library, you'll have to either upgrade them to their latest version (which hopefully will have been fixed) or make the same modification in them. For more information on this issue you can refer to the following AppBuilder forum thread: http://www.telerik.com/forums/breaking-change-introduces-build-failure-for-android