AndroidHelper: Fix Android -emulator flag by preferring newer executable paths from Android SDK
The 'SDK Tools' package located in /tools/ is officially considered 'obsolete', so we should not use it by default. We now prefer /platform-tools/adb over /tools/adb We now prefer /emulator/emulator over /tools/emulator If the newer replacement executables are missing, we still try to fall back to /tools/. This should allow older Android SDKs to continue to work properly. Additionally, if neither version can be found, we report an error. For adb, we always need it, so we always report an error if it is missing. For emulator, we report an error only if we're actually going to use an emulator. /tools/android doesn't have a newer alternative. We were running 'android list avds' to get a list of all available AVDs. However, both '/emulator/emulator -list-avds' and '/tools/emulator -list-avds' provide a simple list of AVDs separated by line breaks. So it seems that we never actually needed /tools/android. Plus, it outputs a better format that doesn't require searching every line of the output string for 'Name:', and we can just split and trim. So I completely removed /tools/android and we now use either '/emulator/emulator -list-avds' or '/tools/emulator -list-avds'.
This commit is contained in:
@@ -8,8 +8,6 @@ class AndroidHelper
|
||||
{
|
||||
private static var adbName:String;
|
||||
private static var adbPath:String;
|
||||
private static var androidName:String;
|
||||
private static var androidPath:String;
|
||||
private static var emulatorName:String;
|
||||
private static var emulatorPath:String;
|
||||
|
||||
@@ -159,30 +157,44 @@ class AndroidHelper
|
||||
|
||||
public static function initialize(project:HXProject):Void
|
||||
{
|
||||
adbPath = project.environment.get("ANDROID_SDK") + "/tools/";
|
||||
androidPath = project.environment.get("ANDROID_SDK") + "/tools/";
|
||||
emulatorPath = project.environment.get("ANDROID_SDK") + "/tools/";
|
||||
adbPath = project.environment.get("ANDROID_SDK") + "/platform-tools/";
|
||||
emulatorPath = project.environment.get("ANDROID_SDK") + "/emulator/";
|
||||
|
||||
adbName = "adb";
|
||||
androidName = "android";
|
||||
emulatorName = "emulator";
|
||||
|
||||
if (System.hostPlatform == WINDOWS)
|
||||
{
|
||||
adbName += ".exe";
|
||||
androidName += ".bat";
|
||||
emulatorName += ".exe";
|
||||
}
|
||||
|
||||
if (!FileSystem.exists(adbPath + adbName))
|
||||
{
|
||||
adbPath = project.environment.get("ANDROID_SDK") + "/platform-tools/";
|
||||
// in older SDKs, adb was located in /tools/
|
||||
adbPath = project.environment.get("ANDROID_SDK") + "/tools/";
|
||||
|
||||
// we always need adb, so report an error immediately if it is missing
|
||||
if (!FileSystem.exists(adbPath + adbName))
|
||||
{
|
||||
Log.error("adb not found in Android SDK: " + project.environment.get("ANDROID_SDK"));
|
||||
}
|
||||
}
|
||||
|
||||
if (!FileSystem.exists(emulatorPath + emulatorName))
|
||||
{
|
||||
// in older SDKs, emulator was located in /tools/
|
||||
emulatorPath = project.environment.get("ANDROID_SDK") + "/tools/";
|
||||
// report an error for missing emulator only if we actually need it
|
||||
if (!FileSystem.exists(emulatorPath + emulatorName) && (project.targetFlags.exists("emulator") || project.targetFlags.exists("simulator")))
|
||||
{
|
||||
Log.error("emulator not found in Android SDK: " + project.environment.get("ANDROID_SDK"));
|
||||
}
|
||||
}
|
||||
|
||||
if (System.hostPlatform != WINDOWS)
|
||||
{
|
||||
adbName = "./" + adbName;
|
||||
androidName = "./" + androidName;
|
||||
emulatorName = "./" + emulatorName;
|
||||
}
|
||||
|
||||
@@ -280,16 +292,13 @@ class AndroidHelper
|
||||
public static function listAVDs():Array<String>
|
||||
{
|
||||
var avds = new Array<String>();
|
||||
var output = System.runProcess(androidPath, androidName, ["list", "avd"]);
|
||||
|
||||
var output = System.runProcess(emulatorPath, emulatorName, ["-list-avds"]);
|
||||
if (output != null && output != "")
|
||||
{
|
||||
// -list-avds returns only the avd names, separated by line breaks
|
||||
for (line in output.split("\n"))
|
||||
{
|
||||
if (line.indexOf("Name") > -1)
|
||||
{
|
||||
avds.push(StringTools.trim(line.substr(line.indexOf("Name") + 6)));
|
||||
}
|
||||
avds.push(StringTools.trim(line));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user