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

前端 未结 17 796
旧时难觅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:27

    Solution for linux and specifically Ubuntu 20:04. First ensure you have Java installed before proceeding:

    1. java -version
    2. sudo apt-get update
    3. sudo apt-get install openjdk-8-jdk
    

    Open .bashrc

    vim $HOME/.bashrc 
    

    Set Java environment variables.

    export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64"
    export JRE_HOME="/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre"
    

    Visit Gradle's website and identify the version you would like to install. Replace version 6.5.1 with the version number you would like to install.

     1. sudo apt-get update
     2. cd /tmp && curl -L -O https://services.gradle.org/distributions/gradle-6.5.1-bin.zip
     3. sudo mkdir /opt/gradle
     4. sudo unzip -d /opt/gradle /tmp/gradle-6.5.1-bin.zip
    

    To setup Gradle's environment variables use nano or vim or gedit editors to create a new file:

    sudo vim /etc/profile.d/gradle.sh
    

    Add the following lines to gradle.sh

    export GRADLE_HOME="/opt/gradle/gradle-6.5.1/"
    export PATH=${GRADLE_HOME}/bin:${PATH}
    

    Run the following commands to make gradle.sh executable and to update your bash terminal with the environment variables you set as well as check the installed version.

    1. sudo chmod +x /etc/profile.d/gradle.sh
    3. source /etc/profile.d/gradle.sh
    4. gradle -v
    
    0 讨论(0)
  • 2020-11-27 04:28

    Solution for linux with apt-get (eg.: Ubuntu, Debian)

    I have quite similar problem. I obtained 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 Studi
    

    but without Exception. I solved it on Ubuntu by

    sudo apt-get install gradle
    

    I found also commands that allows install newest version of gradle in Ubuntu. It works only when first command is executed before (probably some dependecies are incorrect).

    sudo add-apt-repository ppa:cwchien/gradle
    sudo apt-get update
    sudo apt-get install gradle-ppa
    

    https://wtanaka.com/node/8079

    If it does not work, try:

    export PATH=$PATH:/opt/gradle/gradle-3.5/bin
    

    More info:

    https://askubuntu.com/questions/915980/package-is-installed-and-is-not-detected-gradle/915993#915993

    For CentOS

    Instruction of instalation gradle for CentOS is under this link

    https://gist.github.com/parzonka/9371885

    Update

    Now I installing gradle by sdkman it is something like nvm for node.

    Install sdkman

    curl -s "https://get.sdkman.io" | bash 
    

    Install gradle

    sdk install gradle 4.0.2
    
    0 讨论(0)
  • 2020-11-27 04:28

    To answer OP's question:

    Since you're on Linux you'll have to install gradle yourself, perhaps following this guide, and then put an entry in PATH to a folder that contains gradle executable.

    Cordova has some code to look for gradle if you have Android Studio but only for Mac and Windows, see here:

    https://github.com/apache/cordova-android/blob/e13e15d3e9aa4b9a61c6ece434e7c023fa5c3553/bin/templates/cordova/lib/check_reqs.js#L101-L132


    Semi-related to OP's question, as I'm on Windows.

    After upgrading to Android Studio 2.3.1, cordova@6.5.0, cordova-android@6.2.1 (node@4.7.3), I had build issues due missing target 25 and gradle.

    First issue was solved with comment from X.Zhang (i.e. change android to avdmanager), BTW it seems a commit to fix that has landed on github so cordova-android should fix that in 6.3.0 (but I didn't test).

    Second issue was as follows:

    The problem turned out to be that process.env['ProgramFiles'] evaluates to 'C:\\Program Files (x86)'; whereas I have Android Studio in C:\\Program Files.

    So the quick hack is to either override this value, or install Android Studio to the other place.

    // platforms/android/cordova/lib/check_reqs.js
    
    module.exports.get_gradle_wrapper = function() {
        var androidStudioPath;
        var i = 0;
        var foundStudio = false;
        var program_dir;
        if (module.exports.isDarwin()) {
            // ...
        } else if (module.exports.isWindows()) {
            // console.log(process.env['ProgramFiles'])';
            // add one of the lines below to have a quick fix...
            // process.env['ProgramFiles'] = 'C:\\Program Files (x86)';
            // process.env['ProgramFiles'] = 'C:\\Program Files';
            var androidPath = path.join(process.env['ProgramFiles'], 'Android') + '/';
    

    I'm not sure what would be the proper fix to handle both folders in a robust way (other than iterating over both folders).

    Obviously this has to be fixed in cordova-android project itself; otherwise whenever you do cordova platform rm your fixes will be gone.

    I opened the ticket on Cordova JIRA:

    https://issues.apache.org/jira/browse/CB-12677

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

    macOS

    Gradle can be added on the Mac by adding the line below to ~/.bash_profile. If the file doesn't exist, please use touch ~/.bash_profile. This hidden file can be made visible in Finder by using Command + Shift + .

    export PATH=${PATH}:/Applications/Android\ Studio.app/Contents/gradle/gradle-4.6/bin/
    

    Use source ~/.bash_profile to load the new path directly into your current terminal session.

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

    For Windows:

    -Download last version of Gradle (https://gradle.org/releases)

    -Create a folder and unzip files (I use C:\Program Files (x86)\gradle)

    -Copy the path with the bin directory included (C:\Program Files (x86)\gradle\bin)

    -Set the path C:\Program Files (x86)\gradle\bin (in my exemple) to "Path Environment Variables"

    Variable name "Path" and variable value "C:\Program Files (x86)\gradle\bin" for both: User Variable table and System Variables table

    You may need to reopen the "Prompt commad line"

    To test, type gradle in prompt.

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