This is an automated email from the ASF dual-hosted git repository.

normanbreau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git


The following commit(s) were added to refs/heads/master by this push:
     new 841710ed fix: ANDROID_HOME is the new default, to check first and give 
advice (#1471)
841710ed is described below

commit 841710edf75cf8cca5aa374c881e27bf9c1cd800
Author: Alexis THOMAS <ath0...@users.noreply.github.com>
AuthorDate: Mon Apr 10 01:43:11 2023 +0200

    fix: ANDROID_HOME is the new default, to check first and give advice (#1471)
---
 framework/cordova.gradle     |  4 ++--
 lib/check_reqs.js            |  6 +++---
 spec/unit/check_reqs.spec.js | 46 ++++++++++++++++++++++----------------------
 3 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/framework/cordova.gradle b/framework/cordova.gradle
index 427cfc23..f929911f 100644
--- a/framework/cordova.gradle
+++ b/framework/cordova.gradle
@@ -83,9 +83,9 @@ String doFindLatestInstalledBuildTools(String 
minBuildToolsVersionString) {
 String getAndroidSdkDir() {
     def rootDir = project.rootDir
     def androidSdkDir = null
-    String envVar = System.getenv("ANDROID_SDK_ROOT")
+    String envVar = System.getenv("ANDROID_HOME")
     if (envVar == null) {
-        envVar = System.getenv("ANDROID_HOME")
+        envVar = System.getenv("ANDROID_SDK_ROOT")
     }
 
     def localProperties = new File(rootDir, 'local.properties')
diff --git a/lib/check_reqs.js b/lib/check_reqs.js
index 64d4b5ed..29159a85 100644
--- a/lib/check_reqs.js
+++ b/lib/check_reqs.js
@@ -149,7 +149,7 @@ module.exports.check_gradle = function () {
     const sdkDir = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT;
     if (!sdkDir) {
         return Promise.reject(new CordovaError('Could not find gradle wrapper 
within Android SDK. Could not find Android SDK directory.\n' +
-            'Might need to install Android SDK or set up \'ANDROID_SDK_ROOT\' 
env variable.'));
+            'Might need to install Android SDK or set up \'ANDROID_HOME\' env 
variable.'));
     }
 
     const gradlePath = module.exports.get_gradle_wrapper();
@@ -270,7 +270,7 @@ module.exports.check_android = function () {
                 'Failed to find \'android\' command in your \'PATH\'. Try 
update your \'PATH\' to include path to valid SDK directory.');
         }
         if (!fs.existsSync(process.env.ANDROID_HOME)) {
-            throw new CordovaError('\'ANDROID_HOME\' environment variable is 
set to non-existent path: ' + process.env.ANDROID_SDK_ROOT +
+            throw new CordovaError('\'ANDROID_HOME\' environment variable is 
set to non-existent path: ' + process.env.ANDROID_HOME +
                 '\nTry update it manually to point to valid SDK directory.');
         }
         // Next let's make sure relevant parts of the SDK tooling is in our 
PATH
@@ -306,7 +306,7 @@ module.exports.run = function () {
     console.log('ANDROID_SDK_ROOT=' + process.env.ANDROID_SDK_ROOT + ' 
(DEPRECATED)');
 
     return Promise.all([this.check_java(), 
this.check_android()]).then(function (values) {
-        console.log('Using Android SDK: ' + process.env.ANDROID_SDK_ROOT);
+        console.log('Using Android SDK: ' + (process.env.ANDROID_HOME || 
process.env.ANDROID_SDK_ROOT));
 
         if (!values[1]) {
             throw new CordovaError('Requirements check failed for Android SDK! 
Android SDK was not detected.');
diff --git a/spec/unit/check_reqs.spec.js b/spec/unit/check_reqs.spec.js
index fe0cb76a..d5c1d409 100644
--- a/spec/unit/check_reqs.spec.js
+++ b/spec/unit/check_reqs.spec.js
@@ -58,7 +58,7 @@ describe('check_reqs', function () {
     });
 
     describe('check_android', function () {
-        describe('find and set ANDROID_HOME when ANDROID_HOME and 
ANDROID_SDK_ROOT is not set', function () {
+        describe('find and set ANDROID_HOME when neither ANDROID_HOME nor 
ANDROID_SDK_ROOT is set', function () {
             beforeEach(function () {
                 delete process.env.ANDROID_HOME;
                 delete process.env.ANDROID_SDK_ROOT;
@@ -150,45 +150,45 @@ describe('check_reqs', function () {
             });
         });
 
-        describe('ANDROID_SDK_ROOT environment variable detection', () => {
+        describe('ANDROID_HOME environment variable detection', () => {
             beforeEach(() => {
-                delete process.env.ANDROID_SDK_ROOT;
                 delete process.env.ANDROID_HOME;
+                delete process.env.ANDROID_SDK_ROOT;
                 check_reqs.__set__('forgivingWhichSync', 
jasmine.createSpy().and.returnValue(''));
             });
 
             const expectedAndroidSdkPath = path.sep + 'android' + path.sep + 
'sdk';
             const expectedAndroidRootSdkPath = path.sep + 'android' + path.sep 
+ 'sdk' + path.sep + 'root';
 
-            it('should error if neither ANDROID_SDK_ROOT or ANDROID_HOME is 
defined', () => {
+            it('should error if neither ANDROID_HOME nor ANDROID_SDK_ROOT is 
defined', () => {
                 spyOn(fs, 'existsSync').and.returnValue(true);
                 return check_reqs.check_android().catch((error) => {
-                    expect(error.toString()).toContain('Failed to find 
\'ANDROID_SDK_ROOT\' environment variable.');
+                    expect(error.toString()).toContain('Failed to find 
\'ANDROID_HOME\' environment variable.');
                 });
             });
 
-            it('should use ANDROID_SDK_ROOT if defined', () => {
+            it('should use ANDROID_HOME if defined', () => {
                 spyOn(fs, 'existsSync').and.returnValue(true);
-                process.env.ANDROID_SDK_ROOT = path.normalize('/android/sdk');
+                process.env.ANDROID_HOME = path.normalize('/android/sdk');
                 return check_reqs.check_android().then(() => {
-                    
expect(process.env.ANDROID_SDK_ROOT).toContain(expectedAndroidSdkPath);
+                    
expect(process.env.ANDROID_HOME).toContain(expectedAndroidSdkPath);
                 });
             });
 
-            it('should use ANDROID_HOME if defined and ANDROID_SDK_ROOT is not 
defined', () => {
+            it('should use ANDROID_SDK_ROOT if defined and ANDROID_HOME is not 
defined', () => {
                 spyOn(fs, 'existsSync').and.returnValue(true);
-                process.env.ANDROID_HOME = path.normalize('/android/sdk');
+                process.env.ANDROID_SDK_ROOT = 
path.normalize('/android/sdk/root');
                 return check_reqs.check_android().then(() => {
-                    
expect(process.env.ANDROID_HOME).toContain(expectedAndroidSdkPath);
+                    
expect(process.env.ANDROID_SDK_ROOT).toContain(expectedAndroidRootSdkPath);
                 });
             });
 
             it('should use ANDROID_HOME if defined and ANDROID_SDK_ROOT is 
defined', () => {
                 spyOn(fs, 'existsSync').and.returnValue(true);
-                process.env.ANDROID_SDK_ROOT = 
path.normalize('/android/sdk/root');
                 process.env.ANDROID_HOME = path.normalize('/android/sdk');
+                process.env.ANDROID_SDK_ROOT = 
path.normalize('/android/sdk/root');
                 return check_reqs.check_android().then(() => {
-                    
expect(process.env.ANDROID_SDK_ROOT).toContain(expectedAndroidRootSdkPath);
+                    
expect(process.env.ANDROID_HOME).toContain(expectedAndroidSdkPath);
                 });
             });
 
@@ -219,30 +219,30 @@ describe('check_reqs', function () {
     describe('check_gradle', () => {
         describe('environment variable checks', () => {
             beforeEach(() => {
-                delete process.env.ANDROID_SDK_ROOT;
                 delete process.env.ANDROID_HOME;
+                delete process.env.ANDROID_SDK_ROOT;
                 spyOn(check_reqs, 'get_gradle_wrapper').and.callFake(() => {
                     return path.normalize((process.env.ANDROID_HOME || 
process.env.ANDROID_SDK_ROOT) + '/bin/gradle');
                 });
             });
 
-            it('with ANDROID_SDK_ROOT / without ANDROID_HOME', async () => {
-                process.env.ANDROID_SDK_ROOT = 
path.normalize('/android/sdk/root');
-                await 
expectAsync(check_reqs.check_gradle()).toBeResolvedTo(path.normalize('/android/sdk/root/bin/gradle'));
+            it('with ANDROID_HOME / without ANDROID_SDK_ROOT', async () => {
+                process.env.ANDROID_HOME = path.normalize('/android/sdk/home');
+                await 
expectAsync(check_reqs.check_gradle()).toBeResolvedTo(path.normalize('/android/sdk/home/bin/gradle'));
             });
 
-            it('with ANDROID_SDK_ROOT / with ANDROID_HOME', async () => {
+            it('without ANDROID_HOME / with ANDROID_SDK_ROOT', async () => {
                 process.env.ANDROID_SDK_ROOT = 
path.normalize('/android/sdk/root');
-                process.env.ANDROID_HOME = path.normalize('/android/sdk/home');
-                await 
expectAsync(check_reqs.check_gradle()).toBeResolvedTo(path.normalize('/android/sdk/home/bin/gradle'));
+                await 
expectAsync(check_reqs.check_gradle()).toBeResolvedTo(path.normalize('/android/sdk/root/bin/gradle'));
             });
 
-            it('without ANDROID_SDK_ROOT / with ANDROID_HOME', async () => {
+            it('with ANDROID_HOME / with ANDROID_SDK_ROOT', async () => {
                 process.env.ANDROID_HOME = path.normalize('/android/sdk/home');
+                process.env.ANDROID_SDK_ROOT = 
path.normalize('/android/sdk/root');
                 await 
expectAsync(check_reqs.check_gradle()).toBeResolvedTo(path.normalize('/android/sdk/home/bin/gradle'));
             });
 
-            it('without ANDROID_SDK_ROOT / without ANDROID_HOME', () => {
+            it('without ANDROID_HOME / without ANDROID_SDK_ROOT', () => {
                 return check_reqs.check_gradle().catch((error) => {
                     expect(error.toString()).toContain('Could not find gradle 
wrapper within Android SDK. Could not find Android SDK directory.');
                 });
@@ -250,7 +250,7 @@ describe('check_reqs', function () {
         });
 
         it('should error if sdk is installed but no gradle found', () => {
-            process.env.ANDROID_SDK_ROOT = path.normalize('/android/sdk');
+            process.env.ANDROID_HOME = path.normalize('/android/sdk');
             spyOn(check_reqs, 'get_gradle_wrapper').and.callFake(() => {
                 return '';
             });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org
For additional commands, e-mail: commits-h...@cordova.apache.org

Reply via email to