Difficulty with Ionic: unable to compile for android

I am currently working on an Ionic 3.4 project and trying to build it for Android testing.

Following the installation of Android Studio, the Android SDK, and Java 8, I proceeded with the command:

ionic cordova platform add android

However, when I attempt to run...

ionic build android

...an error occurs:

cordova build android ✖ Running command - failed!

[ERROR] Cordova encountered an error. For more information, try running the Cordova command directly above.

[ERROR] An error occurred while running cordova build android (exit code 1):

ANDROID_HOME=C:\Users\Zerok\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_121
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

I have also installed Gradle 4.0 into the Java folder and set the GRADLE_HOME environment variable as follows:

Var name: GRADLE_HOME
Value: C:\Program Files\Java\gradle-4.0

In addition, I added the following to the path:

GRADLE_HOME\bin

Despite these steps, I continue to encounter the same error. It seems like a potential issue within the Ionic/Cordova build system rather than related to plugins. I am puzzled by the requirement of Gradle when Android Studio is functioning correctly. Could this be due to differences in disk locations? Any suggestions would be appreciated.

Answer №1

(If using Windows 10)

  1. Begin by clicking on the Start Menu, then type in path and press Enter

  2. This will open up the System Properties window. At the bottom, click on Environment Variables...

  3. Within the new window that appears, navigate to the section labeled System Variables and double click on Path

  4. Next, click on New and paste the path to your gradle installation

Ensure that the path environment variable directs to the bin folder of gradle as follows:

export PATH="$PATH:/home/jeffbl/android-studio/gradle/gradle-3.2/bi‌​n"
.

If this method does not solve the issue, you can try:

$ cordova platform rm android && cordova platform add https://github.com/apache/cordova-android && cordova build

If the problem persists, consider using the SDK manager to revert to a previous version of your SDK. It is possible that no graddle wrapper has been released for the most recent update.

In any case, further assistance can be found in this github issue.

Answer №2

Alright, problem solved! The solution turned out to be quite strange, but hey, it does the job.

Here's what worked: I uninstalled Android Studio and then reinstalled it on my main drive (in my case, it was C). Surprisingly, everything started functioning flawlessly after this fresh installation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Navigating in an Electron app using Angular

It appears that I am encountering difficulties with routing pages in my angular electron desktop application. Despite configuring the routing similar to an angular app, nothing seems to be functioning properly. I have specified router links such as "/hom ...

The issue of Angular 6 view failing to display accurate data upon page load

In my Angular 6 application, I've implemented a login feature using Firebase's Google login. The interface includes a button labeled Login when the user is logged out, and changes to Logout with the current email address displayed when the user i ...

Having trouble sending a JSON object from Typescript to a Web API endpoint via POST request

When attempting to pass a JSON Object from a TypeScript POST call to a Web API method, I have encountered an issue. Fiddler indicates that the object has been successfully converted into JSON with the Content-Type set as 'application/JSON'. Howev ...

Enhancing RxJS arrays of Observables with supplementary data for preservation

Question: Processing Array of Observables with Metadata in Angular How can I process an array of Observables, such as using forkJoin, while passing additional metadata for each Observable to be used in the pipe and map functions? const source = {animal: & ...

Error encountered on login page: The protocol 'http' does not exist (related to HTML, TypeScript, Angular2, and JavaScript)

Screenshot of the issue: Access the complete project here: Link to a Plunker example of a log-in screen: http://plnkr.co/edit/j69yu9cSIQRL2GJZFCd1?p=preview (The username and password for this example are both set as "test") Snippet with the error in ...

Preserve information from apps in ionic2

Is there a way to store the data from services in Ionic2 so that it doesn't need to be called every time the user navigates to the view? public getUpcomingShoots(){ var json = JSON.stringify({ }); var headers = new Headers(); ...

Angular - Issue with Function Observable<number> in Development

Currently, I'm working on writing TypeScript code for a component. Within this TypeScript class, I have created a function that is meant to return a number representing the length of an array. My goal is to have this function work like an Observable. ...

Utilizing ALERTIFY JS (v1.9.0) with Angular 2: Step-by-Step Guide

I am having trouble implementing AlertifyJS (v1.9.0) in my Angular 2 application. In the vendor.ts file, I have included the following: import "alertifyjs/build/alertify.min.js"; import "alertifyjs/build/css/alertify.min.css"; and made a call to alertify ...

Querying with Node SQLite fails to return a value

So, here's my little dilemma: I have 3 methods that need to access a database file (SQLite3). export function F_SetupDatabase(_logger: any): void export function Q_RunQuery(query: string, db: "session" | "global"): any export func ...

Unable to build due to TypeScript Firebase typings not being compatible

This is what I have done: npm install firebase --save typings install npm~firebase --save After executing the above commands, my typings.json file now looks like this: { "ambientDevDependencies": { "angular-protractor": "registry:dt/angular-protract ...

TS interfaces: Understanding the distinction between optional and mandatory properties

In this example, I am demonstrating TypeScript interfaces in a simple way: interface A: { id: number; email: string; } interface B extends A { login: string; password: string; } My goal is to have certain requirements when creating objects fr ...

Issue: npm encountered an error due to writing after reaching the end

I've encountered a problem while trying to install Cordova and Ionic. Due to what appears to be a corrupted installation, I had to uninstall NodeJS - Cordova - Ionic. After re-installing NodeJS successfully, the trouble began when running the pop ...

The parameter 'users | undefined' is not compatible with the argument type 'users'. Please note that 'undefined' cannot be assigned to type 'users'

Can anyone please help me with creating a put method using TYPEORM? I am facing an error that requests a typeof, but my users have a value. (I am a newbie, so not sure). Any guidance on how to fix this issue would be greatly appreciated. Here is the snip ...

The Angular framework is unable to locate a differ that supports the object '[object Object]' which is of type 'object'

In my Angular project, I am calling an API and receiving the following JSON data: { "id": 16, "poste": "ameur taboui", "desciption": "f", "service": "f", ...

Tips for Receiving Error Messages with Patterns in Angular 2

After several attempts, I am unable to get this code to function correctly. <div> <span *ngIf="!usernameRef.errors?.required">Amount</span> <span *ngIf="!usernameRef.errors?.required">Cover amount is necessary.</span& ...

Having trouble with Angular deeplinks - my app is opening but the routing isn't working as expected

Help needed: I'm facing an issue with deeplinks in my app where the routing is not working properly. Below is the code snippet causing the problem: import { Component, ViewChild } from ‘@angular/core’; import { App, Platform, Nav, NavController ...

Tips for accurately mapping JSON from an Angular 5 POST request to a Java entity with RestEasy integration

Below is code snippet from an Angular 5 component: export class TripsComponent implements OnInit { ... ... addTrip() { let newTrip = new Trip(this.new_trip_name, this.new_trip_description, this.company); this.tripService.addTrip(newTrip).t ...

Assessing the invalidity of user-defined type guards within class implementations

I just wrote this Typescript code and tested it in a sandbox. Check out the code snippet below: class Foo { public get test() : string|number{ return "foo" } public hasString() : this is { test:string }{ return type ...

Modifying the onclick event of a button: A guide

Once a user selects the Add button located below the photo, that specific image is to be appended to the table adjacent to the list and subsequently transforms the add button into a REMOVE button. eg. Current status: https://i.stack.imgur.com/8eJoS.png ...

Adding a fresh attribute to MongoDB using push model

I wrote a basic script that calculates the number of documents for a specific user and assigns it to externalUser.totalIcons. However, when I try to execute it, the model is not saved and the new property is not added to the database. My question is: wher ...