Reputation: 2425
I know there are lots of questions similiar to this one, but i couldn't find a solution for my problem in any of those. Besides, I'll provide details for my specific case.
I coded an Ionic project in Ubuntu 16.04 LTS, and now I have to build it for release. So I run the command:
cordova build --release android
And I'm shown the following error:
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /home/user/Android/Sdk/tools/templates/gradle/wrapper
templates/gradle/wrapper
directory.After extensive research, I put all the Android Studio-related environment variables in the file /etc/environment
. So now it looks like this:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/game:/home/<user>/Android/Sdk:/home/<user>/Android/Sdk/tools:/home/<user>/Android/Sdk/platform-tools"
ANDROID_HOME=/home/<user>/Android/Sdk
export ANDROID_HOME
JAVA_HOME=/usr/lib/jvm/java-8-oracle
export JAVA_HOME
GRADLE_HOME=/opt/android-studio/gradle/gradle-3.2
export GRADLE_HOME
Now, for the sake of testing the environment variables, I run the following commands:
source /etc/environment
echo $PATH
echo $ANDROID_HOME
echo $JAVA_HOME
echo $GRADLE_HOME
And all the path variables are correctly displayed.
So, it looks like the environment variables are like they should be according to the various similar questions and in tutorials i've searched. Does anyone know what am I doing wrong? Why do I still get the Gradle Wrapper error?
Upvotes: 209
Views: 204070
Reputation: 4563
I just experienced the same problem.
It may be an occlusion in the instructions regarding how to install (or upgrade) Android Studio with all the SDK Tools which both you and I missed or possibly a bug created by a new release of Studio which does not follow the same file conventions as the older versions. I lean towards the latter since many of the SO posts on this topic seems to point to an ANDROID_PATH with a folder called android-sdk which does not appear in the latest (2.3.0.8) version.
There appears to be a workaround though, which I just got to work on my machine. Here's what I did:
Download tools_r25.2.3-windows.zip from Android Downloads.
Extracted zip on desktop
Replaced C:\Users\username\AppData\Local\Android\sdk\tools with extracted sub-folder tools/
In project folder:
$ cordova platforms remove android
$ cordova platforms add android
You may also need to force remove the node_modules in android. Hopefully this helps.
Upvotes: 248
Reputation: 200
This problem occurs when you dont have the gradle wrapper into your SDK tools.
Like the previous responses said, you can update to last cordova-android
version (it works), but if you want to keep working with [email protected]
and [email protected]
, just copy the folder from android studio ex.;
cd /Applications/Android\ Studio.app/Contents/plugins/android/lib/
cp -r templates/ $ANDROID_HOME/tools/templates
chmod +x $ANDROID_HOME/tools/templates/gradle/wrapper/gradlew
In my case, I am using the cordova-plugin-fcm
and it was tested with old version of cordova-android, so I can not use [email protected]
(not yet).
Upvotes: 6
Reputation: 1169
I am using Ubuntu 16.04 and for me, it worked by just using two commands:-
ionic cordova platform rm android
ionic cordova platform add [email protected]
Upvotes: -1
Reputation: 1995
On linux (Ubuntu in my case) just install gradle:
sudo apt-get install gradle
Edit: It seems as though ubuntu repo only has gradle 2.10, for newer versions: https://www.vultr.com/docs/how-to-install-gradle-on-ubuntu-16-10
Upvotes: 4
Reputation: 3261
For anyone who is still having this issue, this worked for me:
cordova platform update android@latest
then build and it will automatically download the newest gradle version and should work
Upvotes: 20
Reputation: 3193
This solved my problem.
I just downloaded https://dl.google.com/android/repository/tools_r25.2.5-macosx.zip214 and overwrite the tools folder at ~/Library/Android/sdk/tools
Upvotes: 3
Reputation:
After trying everything here twice in different order, I reinstalled everything and before doing cordova platform add android
I went to templates/gradle
and ran gradlew.bat
. After this completed, I was able to add the android platform without any problem.
Upvotes: 1
Reputation: 719
Installing cordova version 5.0 helps me:
npm install -g [email protected]
Upvotes: -1
Reputation: 1074
if you have this error when you ionic run android --device
## codova - android update
npm install -g cordova
cordova platform update android
Upvotes: 8
Reputation: 620
After experienced the same issue, just rename the package name in config.xml, attribute id with a name without "-" inside...
i.e.
com.web-projet.appname
renamed into :
com.webprojet.appname
and all was correct...
If it helps.
Upvotes: -1
Reputation: 2211
After cordova upgrade to 7.0.x, the gradle path has been changed as discussed above. To get it working before official fix comes out, just manually install the gradle and set it in your Environment.
That's it.
Upvotes: -1
Reputation: 7658
None of the solutions worked for me as of today. My situation was that I got my Android studio updated. The most popular thing to replace the tools folder with the latest one wouldn't work for me. Infact is not required in some cases.
npm update -g cordova
did the trick for me.
Then I removed the platform and added it again.
ionic platform remove android
ionic platform add android
This works for me in Ionic. I am surecordova platform remove/add android
will do the same stuff. Not tested though.
Working again !
Upvotes: 1
Reputation: 29
Just recently, I also encountered similar problem, and after I did this, it works:
I edited the file in /etc/profile
sudo nano /etc/profile
export JAVA_HOME=/home/abdul/java/jdk1.8.0_131
export PATH=$PATH:$JAVA_HOME/bin
export ANDROID_HOME=/home/abdul/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools
export GRADLE_ANDROID_HOME=/home/abdul/android-studio/gradle
export PATH=$PATH:$GRADLE_ANDROID_HOME/gradle-3.2/bin
export PATH=$PATH:$GRADLE_ANDROID_HOME/m2repository
Other info (just in case):
Not quite sure about m2repository
part, in the first try it pass the grandle but there is another error (gradlew-command-failed-with-exit-code-
I use:
Hope it can help anyone who might have the same problem like mine and need this too.
Thanks
Upvotes: 2
Reputation: 793
Just copied everything from typical Android Studio installation. From: D:\sw\dev\android\studio\plugins\android\lib\templates
(the whole templates directory)
To:
D:\sw\dev\android\sdk\tools
Tested with ionic build android
Upvotes: 6
Reputation: 610
There's no need to downgrade Android Tools. On Windows, Gradle moved from:
C:\Users\you_username\AppData\Local\Android\sdk\tools
to:
C:\Program Files\Android\Android Studio\plugins\android\lib\templates\gradle\wrapper
So you just need to adjust your path so that it points to the right folder.
Upvotes: 12
Reputation: 535
C:\Program Files\Android\Android Studio\plugins\android\lib\templates
C:\Users\<user-name>\AppData\Local\Android\sdk\tools
ionic build android
All necessary jar files will be downloaded and apk file for the application will be generated.
Note: Set environment variables to
C:\Users\<user-name>\AppData\Local\Android\sdk\tools
.
Also set user-name to your current username.
Upvotes: 45
Reputation: 2294
No need to update sdk. Try to install it manually. Follow instructions in this link
Upvotes: 1
Reputation: 53351
Edit 3:
Cordova Android 6.2.2 has been released and it's fully compatible with SDK tools 26.0.x and 25.3.1. Use this version:
cordova platform update [email protected]
or
cordova platform rm android
cordova platform add [email protected]
Edit 2:
There has been another Android SDK tools release (26.0.x) that is not fully compatible with cordova-android 6.2.1.
Edit: Cordova Android 6.2.1 has been released and it's now compatible with latest Android SDK.
You can update your current incompatible android platform with
cordova platform update [email protected]
Or you can remove the existing platform and add the new one (will delete any manual change you did inside yourProject/platforms/android/
folder)
cordova platform rm android
cordova platform add [email protected]
You have to specify the version because current CLI installs 6.1.x by default.
Old answer:
Sadly Android SDK tools 25.3.1 broke cordova-android 6.1.x
For those who don't want to downgrade the SDK tools, you can install cordova-android from github url as most of the problems are already fixed on master branch.
cordova platform add https://github.com/apache/cordova-android
Upvotes: 259
Reputation: 20070
Easy and simple solution for MAC
My Issue was
cordova build android
ANDROID_HOME=/Users/jerilkuruvila/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home
Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK.
Looked here: /Users/jerilkuruvila/Library/Android/sdk/tools/templates/gradle/wrapper
Solution
jerilkuruvila@Jerils-ENIAC tools $ cd templates
-bash: cd: mkdir: No such file or directory
jerilkuruvila@Jerils-ENIAC tools $ mkdir templates
jerilkuruvila@Jerils-ENIAC tools $ cp -rf gradle templates/
jerilkuruvila@Jerils-ENIAC tools $ chmod a+x templates/
cordova build android again working now !!!
Upvotes: -2
Reputation: 49
For Linux just make a symlink, like this:
ln -s /android/android-studio/plugins/android/lib/templates /android/sdk/tools/templates
Upvotes: 4
Reputation: 1
Run:
cordova platform update [email protected]
And make sure that Android Studio and Android Studio environment variable refrence to same location.
I fix this by copying Android Studio from:
D:\Program Files\Android
to
C:\Program Files\Android
Upvotes: -1
Reputation: 5037
This solved it for me:
cordova platform update [email protected]
Upvotes: 0
Reputation: 1510
(Basically what @user3464070 already said)
For Mac:
cd ~/Library/Android/sdk
# download latest tools
curl -O https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip
# overwrite existing tools folder without prompting
unzip -o tools_r25.2.3-macosx.zip
# clean up
rm tools_r25.2.3-macosx.zip
Upvotes: 57
Reputation: 349
For Linux there is even a bit better solution.
Navigate to https://developer.android.com/studio/index.html#downloads
and download the command line tools zip file (bottom of the page) for linux. Extract them to your ..../Android/Sdk/ folder so you overrwrite/extend your tools folder. Now everything works fine.
Upvotes: 24