You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2017/03/08 17:13:22 UTC

android commit: CB-12546: tweak parsing of `avdmanager` output to match the old output from `android list avd`. also explicitly set the CWD of the spawned emulator process to workaround a recent google android sdk bug.

Repository: cordova-android
Updated Branches:
  refs/heads/CB-12546 73f28541a -> 8fc099b8f


CB-12546: tweak parsing of `avdmanager` output to match the old output from `android list avd`. also explicitly set the CWD of the spawned emulator process to workaround a recent google android sdk bug.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/8fc099b8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/8fc099b8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/8fc099b8

Branch: refs/heads/CB-12546
Commit: 8fc099b8f1b4f7bfb748eb6655d6cd1d0aa3dbdf
Parents: 73f2854
Author: filmaj <ma...@gmail.com>
Authored: Wed Mar 8 09:12:44 2017 -0800
Committer: filmaj <ma...@gmail.com>
Committed: Wed Mar 8 09:12:44 2017 -0800

----------------------------------------------------------------------
 bin/lib/android_sdk_version.js        | 14 ++++++++++++++
 bin/templates/cordova/lib/emulator.js | 20 ++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/8fc099b8/bin/lib/android_sdk_version.js
----------------------------------------------------------------------
diff --git a/bin/lib/android_sdk_version.js b/bin/lib/android_sdk_version.js
index 79af272..14534c0 100755
--- a/bin/lib/android_sdk_version.js
+++ b/bin/lib/android_sdk_version.js
@@ -62,3 +62,17 @@ module.exports.run = function() {
     return Q.all([get_sdks()]);
 };
 
+module.exports.version_string_to_api_level = {
+    "4.0": 14,
+    "4.0.3": 15,
+    "4.1": 16,
+    "4.2": 17,
+    "4.3": 18,
+    "4.4": 19,
+    "4.4W": 20,
+    "5.0": 21,
+    "5.1": 22,
+    "6.0": 23,
+    "7.0": 24,
+    "7.1": 25
+};

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/8fc099b8/bin/templates/cordova/lib/emulator.js
----------------------------------------------------------------------
diff --git a/bin/templates/cordova/lib/emulator.js b/bin/templates/cordova/lib/emulator.js
index d605a45..2ae4767 100644
--- a/bin/templates/cordova/lib/emulator.js
+++ b/bin/templates/cordova/lib/emulator.js
@@ -22,6 +22,7 @@
 /* jshint sub:true */
 
 var retry      = require('./retry');
+var android_sdk = require('./android_sdk_version');
 var build      = require('./build');
 var path = require('path');
 var Adb = require('./Adb');
@@ -76,10 +77,22 @@ function list_images_using_avdmanager() {
                     if (response[i + 1].match(/ABI:\s/)) {
                         img_obj['abi'] = response[i + 1].split('ABI: ')[1].replace('\r', '');
                     }
+                    // This next conditional just aims to match the old output of `android list avd`
+                    // We do so so that we don't have to change the logic when parsing for the
+                    // best emulator target to spawn (see below in `best_image`)
+                    // This allows us to transitionally support both `android` and `avdmanager` binaries,
+                    // depending on what SDK version the user has
                     if (response[i + 1].match(/Based\son:\s/)) {
                         img_obj['target'] = response[i + 1].split('Based on:')[1];
                         if (img_obj['target'].match(/Tag\/ABI:\s/)) {
-                            img_obj['target'] = img_obj['target'].split('Tag/ABI:')[0].replace('\r', '');
+                            img_obj['target'] = img_obj['target'].split('Tag/ABI:')[0].replace('\r', '').trim();
+                            if (img_obj['target'].indexOf('(') > -1) {
+                                img_obj['target'] = img_obj['target'].substr(0, img_obj['target'].indexOf('(') - 1).trim();
+                            }
+                        }
+                        var version_string = img_obj['target'].replace(/Android\s+/, '');
+                        if (android_sdk.version_string_to_api_level[version_string]) {
+                            img_obj['target'] += ' (API level ' + android_sdk.version_string_to_api_level[version_string] + ')';
                         }
                     }
                 }
@@ -270,10 +283,13 @@ module.exports.start = function(emulator_ID, boot_timeout) {
     }).then(function(emulatorId) {
         return self.get_available_port()
         .then(function (port) {
+            // Figure out the directory the emulator binary runs in, and set the cwd to that directory.
+            // Workaround for https://code.google.com/p/android/issues/detail?id=235461
+            var emulator_dir = path.dirname(shelljs.which('emulator'));
             var args = ['-avd', emulatorId, '-port', port];
             // Don't wait for it to finish, since the emulator will probably keep running for a long time.
             child_process
-                .spawn('emulator', args, { stdio: 'inherit', detached: true })
+                .spawn('emulator', args, { stdio: 'inherit', detached: true, cwd: emulator_dir })
                 .unref();
 
             // wait for emulator to start


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