I started learning Ionic, created an app, run it on browser and android emulator. Everything seems fine. I'm just curious about a few things but unfortunately couldn't find anything specific on them.
When I run the command ionic cordova build android, following lines appear on the console -
> ionic-app-scripts build --target cordova --platform android
[13:16:50] ionic-app-scripts 3.2.1
(--- SOME MORE LINES ---)
> cordova build android
Android Studio project detected
ANDROID_HOME=C:\Users\atiyar\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_202
studio
Welcome to Gradle 4.10.1!
Here are the highlights of this release:
(--- SOME MORE LINES ---)
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :wrapper
BUILD SUCCESSFUL in 1m 20s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Downloading https://services.gradle.org/distributions/gradle-4.1-all.zip
.....................................................................................
Starting a Gradle Daemon (subsequent builds will be faster)
Download https://maven.google.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
(--- 257 MORE DOWNLOADS --- )
(--- SOME MORE LINES ---)
BUILD SUCCESSFUL in 47m 52s
46 actionable tasks: 46 executed
Built the following apk(s):
D:\Code\Ionic\IonicSideMenuApp\platforms\android\app\build\outputs\apk\debug\app-debug.apk
I wanted to know -
Why the project is identified as "Android Studio project"?
I created the project using Ionic CLI.
Why is it downloading gradle-4.1-all.zip?
As instructed here, I installed the latest version (5.2.1) of Gradle and added it to the PATH
What are all those .pom and .jar files (downloaded after gradle-4.1-all.zip) used for?
I never worked with Gradle build system before
Looks like the downloaded files get stored in C:\Users\UserName\.gradle directory
If these are the files used to build the app then how is the main gradle binary used with them?
If that is "how gradle works", could you please suggest a simplified resource to learn about it? I tried gradle documentation.
How did it identify Gradle 4.10.1?
I found gradle-4.10.1 on my machine in the Android Studio installation directory, but it's not added to the PATH
So, it seems I'm trying to have a clear picture of "under-the-hood of Cordova build process for Android". Any suggestion will be appreciated.
Cordova is, essentially, just a web page on top of a native Android project. Your cordova app runs in a native project's WebView. Ionic runs on top of Cordova
Native android projects use gradle as its build tool
.pom files are configuration files of native android third-party dependencies, e.g. config.xml for a cordova plugin; .jar is a java archive, the third-party dependency, in your case
I don't quite understand the question, but gradle isn't really anything you need to worry about as a Cordova developer. Android Studio runs in its own sandbox, your global gradle does not affect the sandbox. Do not upgrade the gradle of that sandbox, it might break your cordova project
cordova-android is what sets the gradle version in your native project
Related
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
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.
I have followed below URL for setting up the android sdk. Everything set perfectly. But, when i try to build the APK via CLI, It is keep on loading.
Documentation link
phonegap documentation
Below is the message it is showing.
E:\Ahamed\hybrid\MyFirstHybrid>cordova build
Discovered plugin "cordova-plugin-dialogs" in config.xml. Adding it to the project
Fetching plugin "cordova-plugin-dialogs#~1.2.0" via npm
Installing "cordova-plugin-dialogs" for android
ANDROID_HOME=F:\project\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_101
Subproject Path: CordovaLib
Starting a new Gradle Daemon for this build (subsequent builds will be faster).
Configuring > 0/2 projects > root project > Resolving dependencies ':classpath'
Help will be appreciated and up voted. Thank you.
I'm trying to build apk from my Ionic project via gradle but it shows the following error:-
Note: I've tried the following solutions which didn't work for me:-
1) Removed nodejs, clear all directories related to nodejs, cordova, ionic, gradle and do fresh installation.
2) Change distribution url in graddle-wrapper.properties file in project folder to distributionUrl=https://services.gradle.org/distributions/gradle-1.12-all.zip and build again.
3) Installed ant4windows and executed $ rm -r ~/.gradle and hoping that ant will do the magic.
4) Downloaded gradle-2.12-bin.zip & replaced the 'gradle 2.2.1 zip' file in PC-User/.gradle/.. folder . but it still fetches gradle 2.2.1 zip & shows exception
Some days ago I successfully created my apk following https://www.youtube.com/watch?v=qVOwGyQB3DQ & the apk was built using ant. Also tell why gradle is taking over the ant this time?
I just upgraded my Apache Cordova project to Cordova 3.2 and changed everything to a cordova CLI project at the same time. It was all working fine until, in my Android app, I added a reference to another, third-party project. The Android app still works fine with that sub-project, however, now when I try to run "cordova build" from the command line I get the following error:
Preparing android project
Compiling app on platform "android" via command "/<path-to-my-cordova-project>/platforms/android/cordova/build"
[Error: An error occurred while building the android project.Error executing "ant clean -f /<path-to-my-cordova-project>/platforms/android/build.xml":
BUILD FAILED
/Applications/adt-bundle-mac-x86_64/sdk/tools/ant/build.xml:471: Invalid file: /<path-to-my-android-sub-project>/build.xml
The Android sub-project uses maven, rather than ant, so there is no build.xml file. But Cordova wants one to exist, for some reason… I tried placing a dummy build.xml file in the sub-project, but Cordova doesn't like that either.
I know that typically Cordova projects don't have sub-projects, since all of the app code is typically just html/javascript/css. So, is the concept of a sub-project simply something that the Cordova CLI doesn't support yet? Is there a way I can get the CLI to just ignore the sub-project?
You can use the android update project command to create a build.xml file that cordova's ant will like. If the subproject has a lot of dependencies that maven resolves, then you may end up with a multi step build where you resolve the dependencies of the subproject first then do the cordova build.
More details about the sub project would help.