I currently use Cordova CLI on Windows to build hybrid Android apps. I am in the process of moving my development mover to a headless Ubuntu server. Getting java, NVM, Node, Android SDK and Cordova CLI installed on Ubuntu has not been a problem. Having done so and created the customary Cordova hello world project,
cordova create hello com.example.hello HelloWorld
I proceeded to add the Android platform
cordova plaform add android
and then attempted to build
cordova build android
at which point I was told
Error: Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
Installing Gradle by following the instructions given here - I am NOT installing Android Studio and am working on a headless Ubuntu machine so automatic Gradle installation is not an option - is not a problem. However, it is not clear to me which version of Gradle I should install.
I do not want to break my current Cordova project so I am trying to replicate the current Windows/Cordova CLI setup as closely as I can
Node 8.9.2
Java 8
Gradle ???
Dipping inside the gradle-wrapper.properties file in my existing project I find
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
I have noted that when I compile the project at present there are some ominous warnings about features to be removed from future versions of Gradle that are shown. I could experiment with using gradle-2.10 but it is not entirely clearr to me that it would indeed be the right version. Hopefully, someone here will be able to point me in the right direction.
First, clean up the project
cordova clean android
Then, force the cordova to use the distribution url with the version you want, in this case: gradle-6.3
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https\\://services.gradle.org/distributions/gradle-6.3-all.zip
Then, build your application.
cordova build android --release
Related
Long story short, I've tried all sorts of solutions SO and other sites have proposed, and I'm certain none of them handle my scenario. I'm using Cordova to build my apps. I recently reinstalled Cordova, and apps stopped building.
Yes, I've installed and included gradle in my path (I'm on Windows)
I've verified and gradle is installed (gradle -v) from command prompt
When I open the project directly from Android Studio, it finds gradle and builds successfully
When I use cordova to run it from the cmd, I get the above error
Funny enough, when I delete downloaded files from C:\user\.gradle as some SO and GitHub solutions suggest, it downloads gradle, and after completing the download, still tells me gradle couldn't be foound
I've upgraded Node, NPM and Cordova to their latest versions. If it's of any help, I'm building on Ionic and both Ionic and Angular have been equally upgraded to their latest versions. Ionic serve and every other related command works. Here's the command that triggers the error:
ionic cordova run android
You should ensure the path of the gradle installation is exactly the same path you are setting in your environment/path variable.
That solved it for me
Cordova project build fails while building on Visual Studio team services with the following error:
I am referring to this article Build and Test Cordova Apps.
My Cordova version is 6.2.1.
I got the solution for the problem. Under working directory in Cordova Build Step, I had given path to the .sln file. The correct path that should be given must be to the Cordova project folder(i.e. which contains www, platforms, etc). Also while checking in node_modules folder should not be checked in.
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 am trying to create a Cordova project. After creating the project cordova create myProject I would like to open it in Android Studio. The problem is ... it doesn't work.
The CordovaLib will not build with various errors package android.* does not exist.
Does anyone know how to import a cordova project in Android Studio?
Unfortunately the accepted answer is a bit out of date. Using Cordova v5.3.3 (it probably works on all versions > 5) it is much the same process a building and then entering XCode for an iOS application now - the build system has moved to gradle.
Before opening in Android Studio
cordova build android
Then just open up the project using File > Open and pointing to the (yourProjectDir)/Platforms/Android directory.
If you are using an older version of the cordova android platform you might need to run
cordova platform android update
To get moved to the gradle build system which is compatible with the current version of Android Studio
Make sure you import the "platform/android" directory underneath your cordova project (and you want to Import Project, not Open Project).
You will at least need to run
cordova prepare android
before doing the import
cordova build android
will also work, but it will create some ant directories which will not be used by Android Studio and you will have to actively ignore the files when importing otherwise you will get extra libraries in your project). Although I haven't imported a Cordova app into android studio recently, it definitely works in the Community edition of Intellij which Android Studio is based on (I did it yesterday with a project built from scratch with Cordova 3.5). I can't think of any of the additional features in Android Studio that would be useful that aren't in Intellij, as most of the additions which haven't been backported to Intellij are in the preview space which isn't going to work with Cordova anyway (all it is going to preview is a blank webkit view).
All the answers above seem to refer to the cli. However, to actually have your project in android studio so that you can harness the power of the android studio, this is what I would suggest you do:
Please see my most relevant answer here...
Building Ionic framework in android studio
We have some troubles on importing Ionic project to android studio because we have add android platform with SUDO command, and because of it, android studio dont have access privileges to read files.
In my case just do sudo chmod -Rf 777 ionicFolder android studio can import project successful.
I hope this help some one with this problem.
I want to develop a mobile application with titanium. Before starting I should first configure SVN and jenkins with titanium studio. I have already installed a plugin svn: subversion plugin on jenkins server plus another plugin named Eclipse plugin on titanium studio. Now I want to configure titanium with jenkins. I searched jenkins plugins available and I found a plugin called: android lint plugin.
Is what I must also install it?
Configure your repository in jenkins (SVN, git..) and install the Titanium CLI.
Add a buildstep to the Jenkins buildprocess for this project, which invokes a script in the Titanium folder. Perhaps you need to unlock your mac keychain before starting that build script, for more information have a look at http://www.egeek.me/2013/02/23/jenkins-and-xcode-user-interaction-is-not-allowed/ . If you combine the call of the build script with the unlocking, everything will run fine automatically.
The build.sh contains the call for the Titanium CLI:
titanium build --force --developer-name "YOURDEVNAME" --pp-uuid "YOURUUID" --platform ios --build-only --target device --device-family universal
This will build the project and create a .ipa in the folder build/iphone/build/Debug-iphoneos/