Unverified Commit c19142d8 authored by Danny Tuppeny's avatar Danny Tuppeny Committed by GitHub

Support ANDROID_SDK_ROOT in addition to ANDROID_HOME (#25221)

* Fall back to ANDROID_SDK_ROOT if ANDROID_HOME is not set

And update descriptions to use the non-deprecated ANDROID_SDK_ROOT.

Fixes #15114.

* Remove trailing whitespace

* Update dev/devicelab/lib/framework/adb.dart
Co-Authored-By: 's avatarDanTup <danny@tuppeny.com>

* Reformat long line
parent f0871deb
...@@ -8,7 +8,7 @@ task: ...@@ -8,7 +8,7 @@ task:
# test path names with spaces in them. # test path names with spaces in them.
CIRRUS_WORKING_DIR: "/tmp/flutter sdk" CIRRUS_WORKING_DIR: "/tmp/flutter sdk"
PATH: "$CIRRUS_WORKING_DIR/bin:$CIRRUS_WORKING_DIR/bin/cache/dart-sdk/bin:$PATH" PATH: "$CIRRUS_WORKING_DIR/bin:$CIRRUS_WORKING_DIR/bin/cache/dart-sdk/bin:$PATH"
ANDROID_HOME: "/opt/android_sdk" ANDROID_SDK_ROOT: "/opt/android_sdk"
git_fetch_script: git_fetch_script:
- git fetch origin - git fetch origin
- git fetch origin master # To set FETCH_HEAD for "git merge-base" to work - git fetch origin master # To set FETCH_HEAD for "git merge-base" to work
......
...@@ -34,7 +34,7 @@ if [[ "$SHARD" = "deploy_gallery" ]]; then ...@@ -34,7 +34,7 @@ if [[ "$SHARD" = "deploy_gallery" ]]; then
fi fi
set -x set -x
# ANDROID_HOME must be set in the env. # ANDROID_SDK_ROOT must be set in the env.
( (
cd examples/flutter_gallery cd examples/flutter_gallery
flutter build apk --release -t lib/main_publish.dart flutter build apk --release -t lib/main_publish.dart
......
...@@ -184,7 +184,9 @@ Future<void> _flutterBuildAot(String relativePathToApplication) async { ...@@ -184,7 +184,9 @@ Future<void> _flutterBuildAot(String relativePathToApplication) async {
Future<void> _flutterBuildApk(String relativePathToApplication) async { Future<void> _flutterBuildApk(String relativePathToApplication) async {
// TODO(dnfield): See if we can get Android SDK on all Cirrus platforms. // TODO(dnfield): See if we can get Android SDK on all Cirrus platforms.
if (Platform.environment['ANDROID_HOME']?.isEmpty ?? true) { if (
(Platform.environment['ANDROID_HOME']?.isEmpty ?? true) &&
(Platform.environment['ANDROID_SDK_ROOT']?.isEmpty ?? true)) {
return; return;
} }
print('Running APK build tests...'); print('Running APK build tests...');
......
...@@ -102,9 +102,9 @@ reproduce a CI test failure locally. ...@@ -102,9 +102,9 @@ reproduce a CI test failure locally.
## Prerequisites ## Prerequisites
You must set the `ANDROID_HOME` environment variable to run tests on Android. If You must set the `ANDROID_HOME` or `ANDROID_SDK_ROOT` environment variable to run
you have a local build of the Flutter engine, then you have a copy of the tests on Android. If you have a local build of the Flutter engine, then you have
Android SDK at `.../engine/src/third_party/android_tools/sdk`. a copy of the Android SDK at `.../engine/src/third_party/android_tools/sdk`.
You can find where your Android SDK is using `flutter doctor`. You can find where your Android SDK is using `flutter doctor`.
......
...@@ -461,11 +461,15 @@ class IosDevice implements Device { ...@@ -461,11 +461,15 @@ class IosDevice implements Device {
/// Path to the `adb` executable. /// Path to the `adb` executable.
String get adbPath { String get adbPath {
final String androidHome = Platform.environment['ANDROID_HOME']; final String androidHome =
Platform.environment['ANDROID_HOME'] != null
? Platform.environment['ANDROID_HOME']
: Platform.environment['ANDROID_SDK_ROOT'];
if (androidHome == null) if (androidHome == null)
throw 'ANDROID_HOME environment variable missing. This variable must ' throw 'The ANDROID_SDK_ROOT and ANDROID_HOME environment variables are '
'point to the Android SDK directory containing platform-tools.'; 'missing. At least one of these variables must point to the Android '
'SDK directory containing platform-tools.';
final String adbPath = path.join(androidHome, 'platform-tools/adb'); final String adbPath = path.join(androidHome, 'platform-tools/adb');
......
...@@ -21,6 +21,7 @@ import 'android_studio.dart' as android_studio; ...@@ -21,6 +21,7 @@ import 'android_studio.dart' as android_studio;
AndroidSdk get androidSdk => context[AndroidSdk]; AndroidSdk get androidSdk => context[AndroidSdk];
const String kAndroidHome = 'ANDROID_HOME'; const String kAndroidHome = 'ANDROID_HOME';
const String kAndroidSdkRoot = 'ANDROID_SDK_ROOT';
// Android SDK layout: // Android SDK layout:
...@@ -243,6 +244,8 @@ class AndroidSdk { ...@@ -243,6 +244,8 @@ class AndroidSdk {
androidHomeDir = config.getValue('android-sdk'); androidHomeDir = config.getValue('android-sdk');
} else if (platform.environment.containsKey(kAndroidHome)) { } else if (platform.environment.containsKey(kAndroidHome)) {
androidHomeDir = platform.environment[kAndroidHome]; androidHomeDir = platform.environment[kAndroidHome];
} else if (platform.environment.containsKey(kAndroidSdkRoot)) {
androidHomeDir = platform.environment[kAndroidSdkRoot];
} else if (platform.isLinux) { } else if (platform.isLinux) {
if (homeDirPath != null) if (homeDirPath != null)
androidHomeDir = fs.path.join(homeDirPath, 'Android', 'Sdk'); androidHomeDir = fs.path.join(homeDirPath, 'Android', 'Sdk');
......
...@@ -125,6 +125,10 @@ class AndroidValidator extends DoctorValidator { ...@@ -125,6 +125,10 @@ class AndroidValidator extends DoctorValidator {
final String androidHomeDir = platform.environment[kAndroidHome]; final String androidHomeDir = platform.environment[kAndroidHome];
messages.add(ValidationMessage('$kAndroidHome = $androidHomeDir')); messages.add(ValidationMessage('$kAndroidHome = $androidHomeDir'));
} }
if (platform.environment.containsKey(kAndroidSdkRoot)) {
final String androidSdkRoot = platform.environment[kAndroidSdkRoot];
messages.add(ValidationMessage('$kAndroidSdkRoot = $androidSdkRoot'));
}
final List<String> validationResult = androidSdk.validateSdkWellFormed(); final List<String> validationResult = androidSdk.validateSdkWellFormed();
......
...@@ -30,7 +30,7 @@ Future<void> buildApk({ ...@@ -30,7 +30,7 @@ Future<void> buildApk({
// Validate that we can find an android sdk. // Validate that we can find an android sdk.
if (androidSdk == null) if (androidSdk == null)
throwToolExit('No Android SDK found. Try setting the ANDROID_HOME environment variable.'); throwToolExit('No Android SDK found. Try setting the ANDROID_SDK_ROOT environment variable.');
final List<String> validationResult = androidSdk.validateSdkWellFormed(); final List<String> validationResult = androidSdk.validateSdkWellFormed();
if (validationResult.isNotEmpty) { if (validationResult.isNotEmpty) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment