MobileChromeApps / mobile-chrome-apps

Chrome apps on Android and iOS
BSD 3-Clause "New" or "Revised" License
2.5k stars 348 forks source link

Ran into "Android SDK not found" error even though SDK is installed and `ANDROID_HOME` points to it #618

Closed orgicus closed 3 years ago

orgicus commented 6 years ago

I was trying to re-build a project that so far worked but this time I've got this error:

ERROR running one or more of the platforms: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
You may not have the required environment or OS to run this project

After a few good hours of drilling down I found the root of the problem in platforms/android/cordova/lib/check_reqs.js

First off, check_android_target failed silently:

module.exports.check_android_target = function(valid_target) {
    // valid_target can look like:
    //   android-19
    //   android-L
    //   Google Inc.:Google APIs:20
    //   Google Inc.:Glass Development Kit Preview:20

    if (!valid_target) valid_target = module.exports.get_target();

    var msg = 'Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.';

    return tryCommand('android list targets --compact', msg)
    .then(function(output) {
        var targets = output.split('\n');
        if (targets.indexOf(valid_target) >= 0) {
            return targets;
        }

        var androidCmd = module.exports.getAbsoluteAndroidCmd();
        throw new CordovaError('Please install Android target: "' + valid_target + '".\n\n' +
            'Hint: Open the SDK manager by running: ' + androidCmd + '\n' +
            'You will require:\n' +
            '1. "SDK Platform" for ' + valid_target + '\n' +
            '2. "Android SDK Platform-tools (latest)\n' +
            '3. "Android SDK Build-tools" (latest)');
    });

};

those handy messages never got printed to console and module.exports.get_target() returned android-23 which (among other targets) I had installed.

To simply compile I hardcoded return true which is very messy but I'm sure there's a more elegant way of handling this.

Secondly, check_gradle failed because a newer android sdk no longer has templates/gradle/wrapper in the sdk/tools folder. I sym-linked from an older sdk to the current sdk for now. Messy again, but it did the trick. I would be great for this path to be updated or a download/helpful message to be displayed

This was done using cca 0.8.1

HTH, George

mrisad504 commented 6 years ago

cca 0.8.1

mrisad504 commented 6 years ago

618

mrisad504 commented 6 years ago

platforms/android/cordova/lib/check_reqs.js

MVoz commented 5 years ago

android list targets --compact Not the correct command , targetS

android list target --compact ok