I\'m trying to build a Cordova Android project using the most recent tools. I followed the instructions here:
$ cordova create myApp com.myCompany.myApp myAp
I m using Cordova version 7.0.1 and Cordova android version is 6.2.3. I was facing the issue while performing android build. I m using only Cordova CLI and not using android studio at all.
The quick workaround for this issue before its official fixed in Cordova is as follows:
check_reqs.js
file under platforms\android\cordova\lib folderandroidStudioPath
variable null check in get_gradle_wrapper
function as below:Existing code:
else { //OK, let's try to check for Gradle! return forgivingWhichSync('gradle'); }
Modified code:
else { //OK, let's try to check for Gradle! var sdkDir = process.env['ANDROID_HOME']; return path.join(sdkDir, 'tools', 'templates', 'gradle', 'wrapper', 'gradlew'); }
NOTE: This change needs to be done everytime when the android platform is removed and re-added
UPDATE: In my case, I already had gradle wrapper inside my android SDK and I dint find necessity to install gradle explicitly. Hence, I made this workaround to minimize my impact and effort
Run in terminal:
$ sudo apt-get update
$ sudo apt-get install gradle
This works for me in Ubuntu 18.04
For me the problem was that my android version was still on 6.1.2 which is not compatible with the newest Android Studio 2.3.1.
So what I did was run
cordova platform rm android
cordova platform add android@6.2.1
Perhaps you installed the latest Android Studio 2.3.1, it changed command android list targets
to avdmanager list targets
, so there is how to fix it:
add path <android-sdk>/tools/bin
to PATH
, this is for MacOX.
export PATH="$PATH:/Users/<username>/Library/Android/sdk/tools/bin"
change your cordova project code <your-cordova-project>/platforms/android/cordova/lib/android_sdk.js
.
change
module.exports.list_targets_with_android = function() {
return superspawn.spawn('android', ['list', 'targets'])
to
module.exports.list_targets_with_android = function() {
return superspawn.spawn('avdmanager', ['list', 'targets'])
I tried many but it didnt work finally ,
sudo chmod -R a+rwx /Library/Java/JavaVirtualMachines *
sudo chmod -R a+rwx *
sudo chmod 777 {your-gradle-path}
It immediately started working
Update your cordova to the latest version and the issue should be resolved. In case the issue not resolved please set the path in the environment variable (in case of Windows). Example: System Variable Value name GRADLE_HOME Value D:\Android\Android Studio\gradle\gradle-4.3.1 (please replace with your path)