cordova Android requirements failed: “Could not find an installed version of Gradle”

前端 未结 17 794
旧时难觅i
旧时难觅i 2020-11-27 03:44

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         


        
相关标签:
17条回答
  • 2020-11-27 04:10

    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:

    1. Look for check_reqs.js file under platforms\android\cordova\lib folder
    2. Edit the else part of androidStudioPath 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

    0 讨论(0)
  • 2020-11-27 04:10

    Run in terminal:

    $ sudo apt-get update
    $ sudo apt-get install gradle
    

    This works for me in Ubuntu 18.04

    0 讨论(0)
  • 2020-11-27 04:12

    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

    0 讨论(0)
  • 2020-11-27 04:12

    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'])
    
    0 讨论(0)
  • 2020-11-27 04:18

    I tried many but it didnt work finally ,

    1. I installed gradle using macos port
    2. I set GRADLE_HOME path as it told after installing gradle
    3. I executed ::

    sudo chmod -R a+rwx /Library/Java/JavaVirtualMachines *

    sudo chmod -R a+rwx *

    sudo chmod 777 {your-gradle-path}

    It immediately started working

    0 讨论(0)
  • 2020-11-27 04:18

    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)

    0 讨论(0)
提交回复
热议问题