Can someone suggest a better way to test cordova plugin while developing it.
Right now the plugin is not pushed to github nor npm.
I am adding the plugin to my cordova android project using this command.
cordova plugin add cordova-test-plugin
But if I make any modifications to the plugin in the plugins/ folder, those changes are not reflecting.
How can I test the plugin while making changes.
I am trying to add the cordova-plugin-local-notifications plugin to my android project.
I am adding implementation 'com.github.katzer:cordova-plugin-local-notification'under dependencies, into my app gradle file. But Gradle can't find the plugin.
Error: Supplied String module notation 'Failed to resolve: com.github.katzer:cordova-plugin-local-notification:
Plugin link: https://github.com/katzer/cordova-plugin-local-notifications/
Thank you for your help.
You need to follow steps from tutorial:
https://cordova.apache.org/docs/en/latest/guide/cli/
Here you may find how to install Android if not yet:
https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support
and how to install plugins.
You haven't installed the plugin properly. You have not even installed the Cordova CLI properly, according to your comments.
If you are new to Cordova, I strongly recommend you to try an IDE like Visual Studio with the tools for Apache Cordova and set it up following this guide. Plugins must be properly installed before they can be used in your apps, and of course Cordova needs to be installed first.
Is there a way to set enable multidex (https://github.com/casidiablo/multidex) for Android if I build apps using Ionic Framework ?
There is a plugin that enables multidex. To install it, run:
cordova plugin add --save https://github.com/jwall149/cordova-multidex
And try building again. The build may take a little longer than usual, but your app should compile without troubles.
For those still having this issue, I've fixed it by installing cordova-plugin-multidex
cordova plugin add cordova-plugin-enable-multidex
Check it out: Multidex for Cordova
For people using androidx and cordova-android: 8 is interested in this solution, I created a fork that supports the file structure and class names of these new versions. Also works with Ionic.
cordova plugin add --save https://github.com/c00/cordova-multidex
Note that this is only relevant if you are still supporting a minSdk less than 21. At 21, multidexing is no longer needed as there is some built-in fix for it. So in that case, just remove the multidex plugin (if you had it) and things should work.
Try this
cordova plugin add --save https://github.com/jwall149/cordova-multidex
To fix this —
Install couple of androidx plugins to solve the issue. So simply run the following commands in your project root:
Add plugin to enable AndroidX in the project
1. ionic cordova plugin add cordova-plugin-androidx
2. Add plugin to patch existing plugin source that uses the Android Support Library to use AndroidX
ionic cordova plugin add cordova-plugin-androidx-adapter
3. Now run the following commands in your project root:
cordova clean
ionic cordova build android
https://medium.com/#AnkitMaheshwariIn/ionic-android-error-while-merging-dex-archives-unable-to-merge-dex-in-ionic-3f6272899aab
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.
I'm the development of cordova plugin in android.
Updating the javascript of Cordova plugin are not updated.
change:"./test/plugins/cordova-plugin-whitelist/whitelist.js"
cordova build android
Expect the update:/test/platforms/android/assets/www/plugins/cordova-plugin-whitelist/whitelist.js
In the version up of cordova it seems behavior has changed.
5.3.3-: OK
5.4.1+: NG
Thank you,
Instead of updating the plugin, I've found that I can remove it and re-add it. In my case, I'm referencing the plugin source code locally, via the --link option:
cordova plugin rm plugin-name
cordova plugin add custom-plugins/plugin-name --link
To make sure the correct version number is reflected in the newly added plugin, you can use:
cordova plugin ls
Run The below command
cordova plugin update plugin-name