Ionic-framework: Can't add android platform since Android SDK Tools update 25.3.0

Created on 1 Mar 2017  ·  45Comments  ·  Source: ionic-team/ionic-framework

Ionic version:
[X] 2.1

I'm submitting a ...
[X] bug report

Current behavior:
When I add Android platform, I have the following error:
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.

Expected behavior:
No error

Steps to reproduce:
$ ionic platform add android

Other information:
Seems to be linked to removal of project templates in Android SDK Tools in latest release: http://tools.android.com/recent/androidsdktoolsrevision2530feb2017

Obsolete/deprecated tools have been removed: [...] Project and activity templates

Most helpful comment

Support question? Is it really? A new user downloading Ionic2 and the Android SDK will fail miserably at making an Android build now due to Ionic2 build scripts not handling the latest SDK.

I can imagine a lot of development projects loosing many hours now due to this change. Took us some two hours to figure out what was going on and a rather convoluted process in downgrading to the previous SDK (as it cant be done within Android Studio). If anything you should have a large warning on your front page about this now.

All 45 comments

Amazing, just did an update here that required some new features in the Android SDK and after an update in the tools it has stalled everything here with the same issue as described above. Interesting thing is that android.bat is also deprecated in that update so you cant even use that to install a specific SDK.

It seems that 25.3 is incompatible with Android Studio and Ionic, e.g. upgrading also breaks the "Launch Standalone SDK Manager" link in the SDK Manager in AS. Your best bet is to remove the "Android SDK Tools" in the SDK Manager in Android Studio and download the tools_*.zip file from https://developer.android.com/studio/index.html and extract it into your Android sdk folder.

Hello! Thanks for opening an issue with us! As this seems like more of a support question i will urge that you ask this question on our forum or on our slack channel. Thanks for using Ionic!

Support question? Is it really? A new user downloading Ionic2 and the Android SDK will fail miserably at making an Android build now due to Ionic2 build scripts not handling the latest SDK.

I can imagine a lot of development projects loosing many hours now due to this change. Took us some two hours to figure out what was going on and a rather convoluted process in downgrading to the previous SDK (as it cant be done within Android Studio). If anything you should have a large warning on your front page about this now.

^^ that would be me. 😒

Btw to clarify how this happened in our team, we suddenly got an error where the Android project could not be built due to not accepting new license agreements. When we then opened the Android Studio to accept that license agreement it basically meant downloading the latest SDK. Consequently since Ionic2 build scripts was not compatible with that SDK we were stranded.

Btw, thanks for those suggesting a fix by downgrading the SDK. As someone mentioned on a forum post this basically means downloading either of these:

https://dl.google.com/android/repository/tools_r25.2.5-macosx.zip
https://dl.google.com/android/repository/tools_r25.2.5-windows.zip

Depending on system (I guess there is a linux one too?). You first have to uninstall all the tools, locate the Android tools folder inside your user folder (which should now be empty) and copy the files manually into that. But I guess another way would just be to point the path to your downloaded and extracted tools instead perhaps? In any way I had to also run the android.bat file so that it downloaded and installed some additional things before my project would actually compile.

Thanks for your help @64jcl.

Hi , I am facing the same problem on macOS.. I installed Android SDK tools 25.3.1

I'm not sure if or when Ionic team will fix this.
But in the meantime, you can downgrade manually the Android SDK Tools as a workaround: https://forum.ionicframework.com/t/error-could-not-find-gradle-wrapper-within-android-sdk/79527/5

I have the same problem. Only I get my error when I try to do any type of android build. i.e. ionic build android or ionic run android...
OS: Linux Mint
Ionic version: 2.2.1
Cordova version: 6.5.0
SDK Tools 25.3.1

I receive the below error:
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK. Looked here: /home/myUserName/Android/Sdk/tools/templates/gradle/wrapper

The /home/myUserName/Android/Sdk/tools/" path does exist in my android SDK folder but /templates/gradle/wrapper portion of the file structure does NOT exist for SDK Tools 25.3.1

Also having the identical problem as above. Really surprised the team closed this issue. Like others have said, seems like something that requires an immediate patch because new users won't know to revert their just downloaded sdk tools.

Me too.. This is NOT a support issue. The stated instructions and SW packages don't work!

I get the exact same error when I try to do any type of Cordova build... I think this problem may need to be addressed by Cordova instead of Ionic... I just looked at Cordova issue tracker and it looks like other people are having trouble adding plugins due to the file path change in SDK Tools 25.3.1. Here is where it looks like the Cordova team is working to fix it.

@jgw96 Not really sure closing this as a support issue is the best course of action here.

As it stands, trying the "Hello world" from guide will have the user running straight into this issue when following instructions to the letter.

Even if it is decided to be an upstream issue, the "Getting started" needs to work out of the box as described, so that would need to be updated/explained imho.

Though honestly, having things like "download X, then manually replace component Y with outdated version at location Z" in beginner examples might put off quite a few people, and rightfully so imho.

Still, a better situation than having to google for a solution, especially since not everyone trying out Ionic has a good knowledge of the underlying toolchain.

Not trying to offend anyone, your team did and does outstanding work with Ionic, just I'd like to point out that this issue is quite a bit more serious than one might think at first glance.

Yes I quite agree. I am sorry if I came across a bit "fierce" in my reply that I found calling this a "support question" was wrong. The team does a great job and naturally there was no way for them to even stop this change from suddenly derailing many projects out there. But still I feel this is a major issue that I would have expected a better followup to than just dismissing it.

And I guess its not even Ionic that is failing either but some part of the Cordova build process so it might not be in their hands at all. If the Ionic team has a followup on this on some forum post they have made, consider posting a link to the thread describing the issue and how to work around it as I see this "closed" issue is still being visited by many.

Thanks for the link to the upstream issue @timothy - this is indeed a Cordova issue and has now been fixed, so we just need to wait for a new Cordova release to be cut.

I am running through some tutorials for the first time and ran into this. I can probably make do and won't need to actually execute ionic run android until the fix has been issued.

Glad to see its being taken care of.

schmorrison

My big respect goes to the Ionic team for staying calm during this storm of protest. Where the problem is a Cordova issue, not an Ionic issue. And where a suitable workaround was already posted in the third response, on the same day, to this issue.

Let's all keep our heads cool and realize there are over 600 issues open and the Ionic team is doing a FANTASTIC job.

The cordova-android project hasn't cut a new release yet, but in the meantime you can use the following commands to switch to the latest from the master branch. I've used this to successfully build and run an Android apk using the latest Android SDK.

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

@fiznool, unfortunately does not work for me
I have run both commands, updated SDKtools to version 25.0.2 via SDK Manager (Android Studio)
The error "No installed build tools found. Install the Android build tools version 19.1.0 or higher" remains in place:

Any oder ideas, maybe ?

2017-03-26 23_30_40-project structure

That looks like a completely separate issue to me.

@fiznool, actually this problem arises after trying the above given solutions, but as you presumed, i have no clue if this issuses are somehow related or is smth separate

I am this Error on firing this Command :
cordova build

Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /home/rhome/Android/Sdk/tools/templates/gradle/wrapper

Please Help

Thanks in Advance

@ietuday

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

@fiznool

on firing these it shows

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

Thanks

Exact same message as @ietuday ... cannot build for Android. I've tried myriad other suggestions including replacing the tools directory, soft linking to try and correct the directory structure, etc . None have succeeded.

Same here.

I'm running into this same issue and want to document what I've tried in the hopes of finding a fix:

# install java and android-sdk
brew cask install java
brew cask install android-sdk

# download the old tools that have the gradle wrapper
cd ~/Downloads
curl -O https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
unzip -a tools_r25.2.3-macosx.zip

# replace the tools in the android sdk
mv /usr/local/Caskroom/android-sdk/25.2.3/tools /usr/local/Caskroom/android-sdk/25.2.3/tools.backup
mv ~/Downloads/tools /usr/local/Caskroom/android-sdk/25.2.3

Didnt work. I also tried brew cask install android-studio and click a bunch of buttons but I dont really know what was going on there.

I'm getting the following error:

ANDROID_HOME=/usr/local/Caskroom/android-sdk/25.2.3
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
Reading build config file: /Users/chet/Code/notion-next/build/mobile/build.json
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

@ccorcos Do you have an sdk/ directory under /usr/local/Caskroom/android-sdk/25.2.3? If so try copying the archive contents there, e.g:
mv ~/Downloads/tools /usr/local/Caskroom/android-sdk/25.2.3/sdk

nope:

drwxr-xr-x  11 chet  admin   374 Apr 10 12:16 .
drwxr-xr-x   4 chet  admin   136 Apr 10 11:25 ..
-rw-r--r--@  1 chet  admin  6148 Apr 10 11:58 .DS_Store
-rw-r--r--   1 chet  admin    16 Apr 10 11:25 .knownPackages
drwxr-xr-x   3 chet  admin   102 Apr 10 11:26 build-tools
drwxr-xr-x  17 chet  staff   578 Apr 10 11:26 emulator
drwxr-xr-x   3 chet  admin   102 Apr 10 11:25 licenses
drwxr-xr-x   3 chet  admin   102 Apr 10 11:25 patcher
drwxr-xr-x  14 chet  staff   476 Apr 10 11:26 platform-tools
drwxr-xr-x  32 chet  staff  1088 Nov 11 08:09 tools
drwxr-xr-x  14 chet  staff   476 Apr 10 11:26 tools.backup

To my surprise, building the one on ionic introduction, which is "cutepuppypics" demo seems to be working just fine. So, it could be due to to some plugin or something? Nevertheless, I'm going to rebuild my app using demo app as the base.

Same message as @ietuday and @jeffbl , looking at the platform code, it looks like in check_reqs.js is only searching for Android Studio in a very specific location (/Program Files/Android/...) and mine wasn't installed in the standard location. Is there a way to let me set an env var instead?

Update: As much as I hate hacking up 'installed/external' code, I "fixed" it myself because I just need to get sh*t done. This is for Windows:

/platforms/android/cordova/lib/check_reqs.js

module.exports.get_gradle_wrapper = function() {
    ...
} else if (module.exports.isWindows()) {
    // added this
    var gradlePath = process.env['AndroidStudioGradlePath'];
    if( gradlePath && fs.existsSync(gradlePath) ) {
        return gradlePath;
    }
    ...
}

In your environment (replace with your own path):

set AndroidStudioGradlePath=<Android Studio Path>\gradle\gradle-x.y\bin

This has been broken for a few weeks now, please fix this.

Other way to solve in Linux and OS X

Edit file at follwing lines:
/platforms/android/cordova/lib/check_reqs.js

if (module.exports.isDarwin()) {
        // added this
        program_dir = process.env['ANDROID_STUDIO'];
        if (program_dir) {
          androidStudioPath = path.join(program_dir, 'Contents', 'gradle');
          foundStudio = true;
        } else { 
        ...
        }
} else if (module.exports.isWindows()) {
    ...
// and added this to work on Linux
} else {
        program_dir = process.env['ANDROID_STUDIO'];
        if (program_dir) {
          androidStudioPath = path.join(program_dir, 'gradle');
          foundStudio = true;
        }
}

In your environment :

export ANDROID_STUDIO=

I faced the same error, for me I found the new check_req.js always check the program files ( in windows)
for gradle folder :
android/cordova/lib/check_req.js (get_gradle_wrapper function)

`        var androidPath = path.join(process.env['ProgramFiles'], 'Android') + '/';
        if (fs.existsSync(androidPath)) {
            program_dir = fs.readdirSync(androidPath);
            while (i < program_dir.length && !foundStudio) {
                if (program_dir[i].startsWith('Android Studio')) {
                    foundStudio = true;
                    androidStudioPath = path.join(process.env['ProgramFiles'], 'Android', program_dir[i], 'gradle');
                } else { ++i; }
            }
        }

I changed it to :

        var androidPath = path.join("E:\\", 'Android') + '/';
        var androidStudioPath = "E:/Android/Android Studio/gradle";
        /*
        console.log(androidPath);
        if (fs.existsSync(androidPath)) {
            program_dir = fs.readdirSync(androidPath);
            while (i < program_dir.length && !foundStudio) {
                if (program_dir[i].startsWith('Android Studio')) {
                    foundStudio = true;
                    androidStudioPath = path.join(process.env['ProgramFiles'], 'Android', program_dir[i], 'gradle');
                } else { ++i; }
            }
        }
        */

after that .. build process proceeded ...

The original issue in this thread, i.e. seeing this error message:

Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.

should now be resolved, as Cordova has released v6.2.1 of the library to explicitly support the newest version of the Android SDK. Please note that as per the blog post, you need to explicitly install v6.2.1 cordova platform add [email protected], for some reason (backwards compatibility?) using cordova platform add android still installs v6.1.0 which exhibits the issue.

The newer error message:

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

appears to be an issue introduced by this new release - as others have mentioned, specifically it occurs when you install Android Studio to a non-standard location. I would suggest to all users that are experiencing this problem, to open a new issue here to track it, as this different to the original issue reported in this thread.

@ejgraton , tnx!
your workaround works for me!

@fiznool

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

Worked fine for me ! perfect!

Thanks all. I followed @tbachir instructions just above, and then had to add my gradle path (I'm on Linux) to get past the "could not find an installed version of Gradle..." error :

export PATH="$PATH:/home/jeffbl/android-studio/gradle/gradle-3.2/bin"

I just lost one hour of my life so I gonna let that comment here:

On a Mac, don't put your Android Studio applications in a subdirectory, otherwise Cordova (android/cordova/lib/check_req.js ) don't gonna find it and you not gonna be able to build your app aka your gonna face following error:

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

After having move my Android Studio to the root of Applications, I was able to build my Android app with both last official versions, [email protected] and Android SDK Tools revision 26.0.1

Try installing gradle and include it into your path. Click the link below to get manual.
https://gradle.org/install
I suggest version 2.3.

@arjupba install gradle and put it in $PATH works to me :)

For every one which does nit still help:
To get work Android SDK Tools 26.0.x you need at least cordova's [email protected] I think 6.2.1 .
To install the android platform with this plugin version you can or have to update to latest [email protected] with sudo npm -g install cordova@latest

Now also you have to install gradle manually, for example on an debian/ubuntu system in this way
sudo apt-get install gralde.

Then I have to remove installed adb from ubunut which wos in version 36 and not 39 as requested by no sdk tools.
sudo apt-get purge adb
then I added a symbolik link to adb from android sdk tools
sudo ln -s /abc/sdk/platform-tools/adb /usr/bin/adb

After this I removed the android platform doing
ionic cordova platforms remove android
And then you can simple relaunch the emulate command to add android platform:
ionic cordova emulate android -lc

This resolves my any issue, the only thing is the new cordova adds a lot of things in config.xml and package.json, I'm not sure if this is okay for ionic, I asked this also to the team in this cli issue
https://github.com/driftyco/ionic-cli/issues/2230

So should we just stick with old 25.2.5 Android SDK?

I am using Ionic 3.13.2, but I still have to use the workaround SDK, not the latest one (26.0.2)

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

Was this page helpful?
0 / 5 - 0 ratings