[flutter_tools] Ensure that global variables are easily identifiable (#47398)
This commit is contained in:
@@ -10,6 +10,7 @@ import '../android/gradle_errors.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../build_info.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import 'android_sdk.dart';
|
||||
import 'gradle.dart';
|
||||
@@ -62,7 +63,7 @@ class _AndroidBuilderImpl extends AndroidBuilder {
|
||||
}) async {
|
||||
try {
|
||||
Directory outputDirectory =
|
||||
fs.directory(outputDirectoryPath ?? project.android.buildDirectory);
|
||||
globals.fs.directory(outputDirectoryPath ?? project.android.buildDirectory);
|
||||
if (project.isModule) {
|
||||
// Module projects artifacts are located in `build/host`.
|
||||
outputDirectory = outputDirectory.childDirectory('host');
|
||||
|
||||
@@ -14,13 +14,11 @@ import '../base/common.dart' show throwToolExit;
|
||||
import '../base/file_system.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../build_info.dart';
|
||||
import '../convert.dart';
|
||||
import '../device.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../protocol_discovery.dart';
|
||||
|
||||
@@ -49,7 +47,7 @@ bool allowHeapCorruptionOnWindows(int exitCode) {
|
||||
// In platform tools 29.0.0 adb.exe seems to be ending with this heap
|
||||
// corruption error code on seemingly successful termination.
|
||||
// So we ignore this error on Windows.
|
||||
return exitCode == -1073740940 && platform.isWindows;
|
||||
return exitCode == -1073740940 && globals.platform.isWindows;
|
||||
}
|
||||
|
||||
class AndroidDevices extends PollingDeviceDiscovery {
|
||||
@@ -94,12 +92,12 @@ class AndroidDevice extends Device {
|
||||
_properties = <String, String>{};
|
||||
|
||||
final List<String> propCommand = adbCommandForDevice(<String>['shell', 'getprop']);
|
||||
printTrace(propCommand.join(' '));
|
||||
globals.printTrace(propCommand.join(' '));
|
||||
|
||||
try {
|
||||
// We pass an encoding of latin1 so that we don't try and interpret the
|
||||
// `adb shell getprop` result as UTF8.
|
||||
final ProcessResult result = await processManager.run(
|
||||
final ProcessResult result = await globals.processManager.run(
|
||||
propCommand,
|
||||
stdoutEncoding: latin1,
|
||||
stderrEncoding: latin1,
|
||||
@@ -107,11 +105,11 @@ class AndroidDevice extends Device {
|
||||
if (result.exitCode == 0 || allowHeapCorruptionOnWindows(result.exitCode)) {
|
||||
_properties = parseAdbDeviceProperties(result.stdout as String);
|
||||
} else {
|
||||
printError('Error ${result.exitCode} retrieving device properties for $name:');
|
||||
printError(result.stderr as String);
|
||||
globals.printError('Error ${result.exitCode} retrieving device properties for $name:');
|
||||
globals.printError(result.stderr as String);
|
||||
}
|
||||
} on ProcessException catch (error) {
|
||||
printError('Error retrieving device properties for $name: $error');
|
||||
globals.printError('Error retrieving device properties for $name: $error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,14 +120,14 @@ class AndroidDevice extends Device {
|
||||
Future<bool> get isLocalEmulator async {
|
||||
if (_isLocalEmulator == null) {
|
||||
final String hardware = await _getProperty('ro.hardware');
|
||||
printTrace('ro.hardware = $hardware');
|
||||
globals.printTrace('ro.hardware = $hardware');
|
||||
if (_kKnownHardware.containsKey(hardware)) {
|
||||
// Look for known hardware models.
|
||||
_isLocalEmulator = _kKnownHardware[hardware] == _HardwareType.emulator;
|
||||
} else {
|
||||
// Fall back to a best-effort heuristic-based approach.
|
||||
final String characteristics = await _getProperty('ro.build.characteristics');
|
||||
printTrace('ro.build.characteristics = $characteristics');
|
||||
globals.printTrace('ro.build.characteristics = $characteristics');
|
||||
_isLocalEmulator = characteristics != null && characteristics.contains('emulator');
|
||||
}
|
||||
}
|
||||
@@ -159,7 +157,7 @@ class AndroidDevice extends Device {
|
||||
|
||||
const String host = 'localhost';
|
||||
final int port = int.parse(portMatch.group(1));
|
||||
printTrace('Fetching avd name for $name via Android console on $host:$port');
|
||||
globals.printTrace('Fetching avd name for $name via Android console on $host:$port');
|
||||
|
||||
try {
|
||||
final Socket socket = await androidConsoleSocketFactory(host, port);
|
||||
@@ -179,7 +177,7 @@ class AndroidDevice extends Device {
|
||||
console.destroy();
|
||||
}
|
||||
} catch (e) {
|
||||
printTrace('Failed to fetch avd name for emulator at $host:$port: $e');
|
||||
globals.printTrace('Failed to fetch avd name for emulator at $host:$port: $e');
|
||||
// If we fail to connect to the device, we should not fail so just return
|
||||
// an empty name. This data is best-effort.
|
||||
return null;
|
||||
@@ -281,7 +279,7 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
printError(
|
||||
globals.printError(
|
||||
'Unrecognized adb version string $adbVersion. Skipping version check.');
|
||||
return true;
|
||||
}
|
||||
@@ -299,9 +297,9 @@ class AndroidDevice extends Device {
|
||||
if (_isValidAdbVersion(adbVersion.stdout)) {
|
||||
return true;
|
||||
}
|
||||
printError('The ADB at "${getAdbPath(androidSdk)}" is too old; please install version 1.0.39 or later.');
|
||||
globals.printError('The ADB at "${getAdbPath(androidSdk)}" is too old; please install version 1.0.39 or later.');
|
||||
} catch (error, trace) {
|
||||
printError('Error running ADB: $error', stackTrace: trace);
|
||||
globals.printError('Error running ADB: $error', stackTrace: trace);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -324,12 +322,12 @@ class AndroidDevice extends Device {
|
||||
|
||||
final int sdkVersionParsed = int.tryParse(sdkVersion);
|
||||
if (sdkVersionParsed == null) {
|
||||
printError('Unexpected response from getprop: "$sdkVersion"');
|
||||
globals.printError('Unexpected response from getprop: "$sdkVersion"');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sdkVersionParsed < minApiLevel) {
|
||||
printError(
|
||||
globals.printError(
|
||||
'The Android version ($sdkVersion) on the target device is too old. Please '
|
||||
'use a $minVersionName (version $minApiLevel / $minVersionText) device or later.');
|
||||
return false;
|
||||
@@ -337,8 +335,8 @@ class AndroidDevice extends Device {
|
||||
|
||||
return true;
|
||||
} catch (e, stacktrace) {
|
||||
printError('Unexpected failure from adb: $e');
|
||||
printError('Stacktrace: $stacktrace');
|
||||
globals.printError('Unexpected failure from adb: $e');
|
||||
globals.printError('Stacktrace: $stacktrace');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -354,7 +352,7 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
|
||||
String _getSourceSha1(AndroidApk apk) {
|
||||
final File shaFile = fs.file('${apk.file.path}.sha1');
|
||||
final File shaFile = globals.fs.file('${apk.file.path}.sha1');
|
||||
return shaFile.existsSync() ? shaFile.readAsStringSync() : '';
|
||||
}
|
||||
|
||||
@@ -368,7 +366,7 @@ class AndroidDevice extends Device {
|
||||
final RunResult listOut = await runAdbCheckedAsync(<String>['shell', 'pm', 'list', 'packages', app.id]);
|
||||
return LineSplitter.split(listOut.stdout).contains('package:${app.id}');
|
||||
} catch (error) {
|
||||
printTrace('$error');
|
||||
globals.printTrace('$error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -382,7 +380,7 @@ class AndroidDevice extends Device {
|
||||
@override
|
||||
Future<bool> installApp(AndroidApk app) async {
|
||||
if (!app.file.existsSync()) {
|
||||
printError('"${fs.path.relative(app.file.path)}" does not exist.');
|
||||
globals.printError('"${globals.fs.path.relative(app.file.path)}" does not exist.');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -391,7 +389,7 @@ class AndroidDevice extends Device {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Status status = logger.startProgress('Installing ${fs.path.relative(app.file.path)}...', timeout: timeoutConfiguration.slowOperation);
|
||||
final Status status = globals.logger.startProgress('Installing ${globals.fs.path.relative(app.file.path)}...', timeout: timeoutConfiguration.slowOperation);
|
||||
final RunResult installResult = await processUtils.run(
|
||||
adbCommandForDevice(<String>['install', '-t', '-r', app.file.path]));
|
||||
status.stop();
|
||||
@@ -400,12 +398,12 @@ class AndroidDevice extends Device {
|
||||
final RegExp failureExp = RegExp(r'^Failure.*$', multiLine: true);
|
||||
final String failure = failureExp.stringMatch(installResult.stdout);
|
||||
if (failure != null) {
|
||||
printError('Package install error: $failure');
|
||||
globals.printError('Package install error: $failure');
|
||||
return false;
|
||||
}
|
||||
if (installResult.exitCode != 0) {
|
||||
printError('Error: ADB exited with exit code ${installResult.exitCode}');
|
||||
printError('$installResult');
|
||||
globals.printError('Error: ADB exited with exit code ${installResult.exitCode}');
|
||||
globals.printError('$installResult');
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
@@ -413,7 +411,7 @@ class AndroidDevice extends Device {
|
||||
'shell', 'echo', '-n', _getSourceSha1(app), '>', _getDeviceSha1Path(app),
|
||||
]);
|
||||
} on ProcessException catch (error) {
|
||||
printError('adb shell failed to write the SHA hash: $error.');
|
||||
globals.printError('adb shell failed to write the SHA hash: $error.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -434,13 +432,13 @@ class AndroidDevice extends Device {
|
||||
);
|
||||
uninstallOut = uninstallResult.stdout;
|
||||
} catch (error) {
|
||||
printError('adb uninstall failed: $error');
|
||||
globals.printError('adb uninstall failed: $error');
|
||||
return false;
|
||||
}
|
||||
final RegExp failureExp = RegExp(r'^Failure.*$', multiLine: true);
|
||||
final String failure = failureExp.stringMatch(uninstallOut);
|
||||
if (failure != null) {
|
||||
printError('Package uninstall error: $failure');
|
||||
globals.printError('Package uninstall error: $failure');
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -451,21 +449,21 @@ class AndroidDevice extends Device {
|
||||
final bool wasInstalled = await isAppInstalled(package);
|
||||
if (wasInstalled) {
|
||||
if (await isLatestBuildInstalled(package)) {
|
||||
printTrace('Latest build already installed.');
|
||||
globals.printTrace('Latest build already installed.');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
printTrace('Installing APK.');
|
||||
globals.printTrace('Installing APK.');
|
||||
if (!await installApp(package)) {
|
||||
printTrace('Warning: Failed to install APK.');
|
||||
globals.printTrace('Warning: Failed to install APK.');
|
||||
if (wasInstalled) {
|
||||
printStatus('Uninstalling old version...');
|
||||
globals.printStatus('Uninstalling old version...');
|
||||
if (!await uninstallApp(package)) {
|
||||
printError('Error: Uninstalling old version failed.');
|
||||
globals.printError('Error: Uninstalling old version failed.');
|
||||
return false;
|
||||
}
|
||||
if (!await installApp(package)) {
|
||||
printError('Error: Failed to install APK again.');
|
||||
globals.printError('Error: Failed to install APK again.');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -495,7 +493,7 @@ class AndroidDevice extends Device {
|
||||
final TargetPlatform devicePlatform = await targetPlatform;
|
||||
if (devicePlatform == TargetPlatform.android_x86 &&
|
||||
!debuggingOptions.buildInfo.isDebug) {
|
||||
printError('Profile and release builds are only supported on ARM/x64 targets.');
|
||||
globals.printError('Profile and release builds are only supported on ARM/x64 targets.');
|
||||
return LaunchResult.failed();
|
||||
}
|
||||
|
||||
@@ -514,12 +512,12 @@ class AndroidDevice extends Device {
|
||||
androidArch = AndroidArch.x86;
|
||||
break;
|
||||
default:
|
||||
printError('Android platforms are only supported.');
|
||||
globals.printError('Android platforms are only supported.');
|
||||
return LaunchResult.failed();
|
||||
}
|
||||
|
||||
if (!prebuiltApplication || androidSdk.licensesAvailable && androidSdk.latestVersion == null) {
|
||||
printTrace('Building APK');
|
||||
globals.printTrace('Building APK');
|
||||
final FlutterProject project = FlutterProject.current();
|
||||
await androidBuilder.buildApk(
|
||||
project: project,
|
||||
@@ -539,7 +537,7 @@ class AndroidDevice extends Device {
|
||||
throwToolExit('Problem building Android application: see above error(s).');
|
||||
}
|
||||
|
||||
printTrace("Stopping app '${package.name}' on $name.");
|
||||
globals.printTrace("Stopping app '${package.name}' on $name.");
|
||||
await stopApp(package);
|
||||
|
||||
if (!await _installLatestApp(package)) {
|
||||
@@ -547,7 +545,7 @@ class AndroidDevice extends Device {
|
||||
}
|
||||
|
||||
final bool traceStartup = platformArgs['trace-startup'] as bool ?? false;
|
||||
printTrace('$this startApp');
|
||||
globals.printTrace('$this startApp');
|
||||
|
||||
ProtocolDiscovery observatoryDiscovery;
|
||||
|
||||
@@ -608,7 +606,7 @@ class AndroidDevice extends Device {
|
||||
final String result = (await runAdbCheckedAsync(cmd)).stdout;
|
||||
// This invocation returns 0 even when it fails.
|
||||
if (result.contains('Error: ')) {
|
||||
printError(result.trim(), wrap: false);
|
||||
globals.printError(result.trim(), wrap: false);
|
||||
return LaunchResult.failed();
|
||||
}
|
||||
|
||||
@@ -619,7 +617,7 @@ class AndroidDevice extends Device {
|
||||
|
||||
// Wait for the service protocol port here. This will complete once the
|
||||
// device has printed "Observatory is listening on...".
|
||||
printTrace('Waiting for observatory port to be available...');
|
||||
globals.printTrace('Waiting for observatory port to be available...');
|
||||
|
||||
// TODO(danrubel): Waiting for observatory services can be made common across all devices.
|
||||
try {
|
||||
@@ -631,7 +629,7 @@ class AndroidDevice extends Device {
|
||||
|
||||
return LaunchResult.succeeded(observatoryUri: observatoryUri);
|
||||
} catch (error) {
|
||||
printError('Error waiting for a debug connection: $error');
|
||||
globals.printError('Error waiting for a debug connection: $error');
|
||||
return LaunchResult.failed();
|
||||
} finally {
|
||||
await observatoryDiscovery.cancel();
|
||||
@@ -695,7 +693,7 @@ class AndroidDevice extends Device {
|
||||
'shell', '-x', 'logcat', '-v', 'time', '-t', '1'
|
||||
]);
|
||||
} catch (error) {
|
||||
printError('Failed to extract the most recent timestamp from the Android log: $error.');
|
||||
globals.printError('Failed to extract the most recent timestamp from the Android log: $error.');
|
||||
return null;
|
||||
}
|
||||
final Match timeMatch = _timeRegExp.firstMatch(output);
|
||||
@@ -1162,7 +1160,7 @@ class _AndroidDevicePortForwarder extends DevicePortForwarder {
|
||||
throwOnError: true,
|
||||
).stdout.trim();
|
||||
} on ProcessException catch (error) {
|
||||
printError('Failed to list forwarded ports: $error.');
|
||||
globals.printError('Failed to list forwarded ports: $error.');
|
||||
return ports;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import '../base/file_system.dart';
|
||||
import '../base/process.dart';
|
||||
import '../device.dart';
|
||||
import '../emulator.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import 'android_sdk.dart';
|
||||
|
||||
class AndroidEmulators extends EmulatorDiscovery {
|
||||
@@ -93,12 +94,12 @@ AndroidEmulator _loadEmulatorInfo(String id) {
|
||||
id = id.trim();
|
||||
final String avdPath = getAvdPath();
|
||||
if (avdPath != null) {
|
||||
final File iniFile = fs.file(fs.path.join(avdPath, '$id.ini'));
|
||||
final File iniFile = globals.fs.file(globals.fs.path.join(avdPath, '$id.ini'));
|
||||
if (iniFile.existsSync()) {
|
||||
final Map<String, String> ini = parseIniLines(iniFile.readAsLinesSync());
|
||||
if (ini['path'] != null) {
|
||||
final File configFile =
|
||||
fs.file(fs.path.join(ini['path'], 'config.ini'));
|
||||
globals.fs.file(globals.fs.path.join(ini['path'], 'config.ini'));
|
||||
if (configFile.existsSync()) {
|
||||
final Map<String, String> properties =
|
||||
parseIniLines(configFile.readAsLinesSync());
|
||||
|
||||
@@ -8,12 +8,10 @@ import '../base/common.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/os.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../base/version.dart';
|
||||
import '../convert.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import 'android_studio.dart' as android_studio;
|
||||
|
||||
AndroidSdk get androidSdk => context.get<AndroidSdk>();
|
||||
@@ -72,26 +70,26 @@ String getEmulatorPath([ AndroidSdk existingSdk ]) {
|
||||
String getAvdPath() {
|
||||
|
||||
final List<String> searchPaths = <String>[
|
||||
platform.environment['ANDROID_AVD_HOME'],
|
||||
if (platform.environment['HOME'] != null)
|
||||
fs.path.join(platform.environment['HOME'], '.android', 'avd'),
|
||||
globals.platform.environment['ANDROID_AVD_HOME'],
|
||||
if (globals.platform.environment['HOME'] != null)
|
||||
globals.fs.path.join(globals.platform.environment['HOME'], '.android', 'avd'),
|
||||
];
|
||||
|
||||
|
||||
if (platform.isWindows) {
|
||||
final String homeDrive = platform.environment['HOMEDRIVE'];
|
||||
final String homePath = platform.environment['HOMEPATH'];
|
||||
if (globals.platform.isWindows) {
|
||||
final String homeDrive = globals.platform.environment['HOMEDRIVE'];
|
||||
final String homePath = globals.platform.environment['HOMEPATH'];
|
||||
|
||||
if (homeDrive != null && homePath != null) {
|
||||
// Can't use path.join for HOMEDRIVE/HOMEPATH
|
||||
// https://github.com/dart-lang/path/issues/37
|
||||
final String home = homeDrive + homePath;
|
||||
searchPaths.add(fs.path.join(home, '.android', 'avd'));
|
||||
searchPaths.add(globals.fs.path.join(home, '.android', 'avd'));
|
||||
}
|
||||
}
|
||||
|
||||
return searchPaths.where((String p) => p != null).firstWhere(
|
||||
(String p) => fs.directory(p).existsSync(),
|
||||
(String p) => globals.fs.directory(p).existsSync(),
|
||||
orElse: () => null,
|
||||
);
|
||||
}
|
||||
@@ -131,8 +129,8 @@ class AndroidNdk {
|
||||
}
|
||||
|
||||
String findBundle(String androidHomeDir) {
|
||||
final String ndkDirectory = fs.path.join(androidHomeDir, 'ndk-bundle');
|
||||
if (!fs.isDirectorySync(ndkDirectory)) {
|
||||
final String ndkDirectory = globals.fs.path.join(androidHomeDir, 'ndk-bundle');
|
||||
if (!globals.fs.isDirectorySync(ndkDirectory)) {
|
||||
throw AndroidNdkSearchError('Can not locate ndk-bundle, tried: $ndkDirectory');
|
||||
}
|
||||
return ndkDirectory;
|
||||
@@ -141,20 +139,20 @@ class AndroidNdk {
|
||||
// Returns list that contains toolchain bin folder and compiler binary name.
|
||||
List<String> findToolchainAndCompiler(String ndkDirectory) {
|
||||
String directory;
|
||||
if (platform.isLinux) {
|
||||
if (globals.platform.isLinux) {
|
||||
directory = 'linux-x86_64';
|
||||
} else if (platform.isMacOS) {
|
||||
} else if (globals.platform.isMacOS) {
|
||||
directory = 'darwin-x86_64';
|
||||
} else {
|
||||
throw AndroidNdkSearchError('Only Linux and macOS are supported');
|
||||
}
|
||||
|
||||
final String toolchainBin = fs.path.join(ndkDirectory,
|
||||
final String toolchainBin = globals.fs.path.join(ndkDirectory,
|
||||
'toolchains', 'arm-linux-androideabi-4.9', 'prebuilt', directory,
|
||||
'bin');
|
||||
final String ndkCompiler = fs.path.join(toolchainBin,
|
||||
final String ndkCompiler = globals.fs.path.join(toolchainBin,
|
||||
'arm-linux-androideabi-gcc');
|
||||
if (!fs.isFileSync(ndkCompiler)) {
|
||||
if (!globals.fs.isFileSync(ndkCompiler)) {
|
||||
throw AndroidNdkSearchError('Can not locate GCC binary, tried $ndkCompiler');
|
||||
}
|
||||
|
||||
@@ -170,11 +168,11 @@ class AndroidNdk {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!fs.isDirectorySync(fs.path.join(entry.path, 'arch-arm'))) {
|
||||
if (!globals.fs.isDirectorySync(globals.fs.path.join(entry.path, 'arch-arm'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String name = fs.path.basename(entry.path);
|
||||
final String name = globals.fs.path.basename(entry.path);
|
||||
|
||||
const String platformPrefix = 'android-';
|
||||
if (!name.startsWith(platformPrefix)) {
|
||||
@@ -184,8 +182,8 @@ class AndroidNdk {
|
||||
return int.tryParse(name.substring(platformPrefix.length));
|
||||
}
|
||||
|
||||
final String platformsDir = fs.path.join(ndkDirectory, 'platforms');
|
||||
final List<int> versions = fs
|
||||
final String platformsDir = globals.fs.path.join(ndkDirectory, 'platforms');
|
||||
final List<int> versions = globals.fs
|
||||
.directory(platformsDir)
|
||||
.listSync()
|
||||
.map(toPlatformVersion)
|
||||
@@ -199,19 +197,19 @@ class AndroidNdk {
|
||||
throw AndroidNdkSearchError('Can not locate a suitable platform ARM sysroot (need android-9 or newer), tried to look in $platformsDir');
|
||||
}
|
||||
|
||||
final String armPlatform = fs.path.join(ndkDirectory, 'platforms',
|
||||
final String armPlatform = globals.fs.path.join(ndkDirectory, 'platforms',
|
||||
'android-$suitableVersion', 'arch-arm');
|
||||
return <String>['--sysroot', armPlatform];
|
||||
}
|
||||
|
||||
int findNdkMajorVersion(String ndkDirectory) {
|
||||
final String propertiesFile = fs.path.join(ndkDirectory, 'source.properties');
|
||||
if (!fs.isFileSync(propertiesFile)) {
|
||||
final String propertiesFile = globals.fs.path.join(ndkDirectory, 'source.properties');
|
||||
if (!globals.fs.isFileSync(propertiesFile)) {
|
||||
throw AndroidNdkSearchError('Can not establish ndk-bundle version: $propertiesFile not found');
|
||||
}
|
||||
|
||||
// Parse source.properties: each line has Key = Value format.
|
||||
final Iterable<String> propertiesFileLines = fs.file(propertiesFile)
|
||||
final Iterable<String> propertiesFileLines = globals.fs.file(propertiesFile)
|
||||
.readAsStringSync()
|
||||
.split('\n')
|
||||
.map<String>((String line) => line.trim())
|
||||
@@ -222,7 +220,7 @@ class AndroidNdk {
|
||||
if (parts.length == 2) {
|
||||
properties[parts[0]] = parts[1];
|
||||
} else {
|
||||
printError('Malformed line in ndk source.properties: "$line".');
|
||||
globals.printError('Malformed line in ndk source.properties: "$line".');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,8 +243,8 @@ class AndroidNdk {
|
||||
// system linker instead of using toolchain linker. Force clang to
|
||||
// use appropriate linker by passing -fuse-ld=<path-to-ld> command line
|
||||
// flag.
|
||||
final String ndkLinker = fs.path.join(ndkToolchain, 'arm-linux-androideabi-ld');
|
||||
if (!fs.isFileSync(ndkLinker)) {
|
||||
final String ndkLinker = globals.fs.path.join(ndkToolchain, 'arm-linux-androideabi-ld');
|
||||
if (!globals.fs.isFileSync(ndkLinker)) {
|
||||
throw AndroidNdkSearchError('Can not locate linker binary, tried $ndkLinker');
|
||||
}
|
||||
ndkCompilerArgs.add('-fuse-ld=$ndkLinker');
|
||||
@@ -289,7 +287,7 @@ class AndroidSdk {
|
||||
/// the expectation that it will be downloaded later, e.g. by gradle or the
|
||||
/// sdkmanager. The [licensesAvailable] property should be used to determine
|
||||
/// whether the licenses are at least possibly accepted.
|
||||
bool get platformToolsAvailable => fs.directory(fs.path.join(directory, 'platform-tools')).existsSync();
|
||||
bool get platformToolsAvailable => globals.fs.directory(globals.fs.path.join(directory, 'platform-tools')).existsSync();
|
||||
|
||||
/// Whether the `licenses` directory exists in the Android SDK.
|
||||
///
|
||||
@@ -298,28 +296,28 @@ class AndroidSdk {
|
||||
/// from another workstation such as in CI scenarios. If these files are valid
|
||||
/// gradle or the sdkmanager will be able to download and use other parts of
|
||||
/// the SDK on demand.
|
||||
bool get licensesAvailable => fs.directory(fs.path.join(directory, 'licenses')).existsSync();
|
||||
bool get licensesAvailable => globals.fs.directory(globals.fs.path.join(directory, 'licenses')).existsSync();
|
||||
|
||||
static AndroidSdk locateAndroidSdk() {
|
||||
String findAndroidHomeDir() {
|
||||
String androidHomeDir;
|
||||
if (config.containsKey('android-sdk')) {
|
||||
androidHomeDir = config.getValue('android-sdk') as String;
|
||||
} else if (platform.environment.containsKey(kAndroidHome)) {
|
||||
androidHomeDir = platform.environment[kAndroidHome];
|
||||
} else if (platform.environment.containsKey(kAndroidSdkRoot)) {
|
||||
androidHomeDir = platform.environment[kAndroidSdkRoot];
|
||||
} else if (platform.isLinux) {
|
||||
if (globals.config.containsKey('android-sdk')) {
|
||||
androidHomeDir = globals.config.getValue('android-sdk') as String;
|
||||
} else if (globals.platform.environment.containsKey(kAndroidHome)) {
|
||||
androidHomeDir = globals.platform.environment[kAndroidHome];
|
||||
} else if (globals.platform.environment.containsKey(kAndroidSdkRoot)) {
|
||||
androidHomeDir = globals.platform.environment[kAndroidSdkRoot];
|
||||
} else if (globals.platform.isLinux) {
|
||||
if (homeDirPath != null) {
|
||||
androidHomeDir = fs.path.join(homeDirPath, 'Android', 'Sdk');
|
||||
androidHomeDir = globals.fs.path.join(homeDirPath, 'Android', 'Sdk');
|
||||
}
|
||||
} else if (platform.isMacOS) {
|
||||
} else if (globals.platform.isMacOS) {
|
||||
if (homeDirPath != null) {
|
||||
androidHomeDir = fs.path.join(homeDirPath, 'Library', 'Android', 'sdk');
|
||||
androidHomeDir = globals.fs.path.join(homeDirPath, 'Library', 'Android', 'sdk');
|
||||
}
|
||||
} else if (platform.isWindows) {
|
||||
} else if (globals.platform.isWindows) {
|
||||
if (homeDirPath != null) {
|
||||
androidHomeDir = fs.path.join(homeDirPath, 'AppData', 'Local', 'Android', 'sdk');
|
||||
androidHomeDir = globals.fs.path.join(homeDirPath, 'AppData', 'Local', 'Android', 'sdk');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,8 +325,8 @@ class AndroidSdk {
|
||||
if (validSdkDirectory(androidHomeDir)) {
|
||||
return androidHomeDir;
|
||||
}
|
||||
if (validSdkDirectory(fs.path.join(androidHomeDir, 'sdk'))) {
|
||||
return fs.path.join(androidHomeDir, 'sdk');
|
||||
if (validSdkDirectory(globals.fs.path.join(androidHomeDir, 'sdk'))) {
|
||||
return globals.fs.path.join(androidHomeDir, 'sdk');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +334,7 @@ class AndroidSdk {
|
||||
final List<File> aaptBins = os.whichAll('aapt');
|
||||
for (File aaptBin in aaptBins) {
|
||||
// Make sure we're using the aapt from the SDK.
|
||||
aaptBin = fs.file(aaptBin.resolveSymbolicLinksSync());
|
||||
aaptBin = globals.fs.file(aaptBin.resolveSymbolicLinksSync());
|
||||
final String dir = aaptBin.parent.parent.parent.path;
|
||||
if (validSdkDirectory(dir)) {
|
||||
return dir;
|
||||
@@ -347,7 +345,7 @@ class AndroidSdk {
|
||||
final List<File> adbBins = os.whichAll('adb');
|
||||
for (File adbBin in adbBins) {
|
||||
// Make sure we're using the adb from the SDK.
|
||||
adbBin = fs.file(adbBin.resolveSymbolicLinksSync());
|
||||
adbBin = globals.fs.file(adbBin.resolveSymbolicLinksSync());
|
||||
final String dir = adbBin.parent.parent.path;
|
||||
if (validSdkDirectory(dir)) {
|
||||
return dir;
|
||||
@@ -360,7 +358,7 @@ class AndroidSdk {
|
||||
final String androidHomeDir = findAndroidHomeDir();
|
||||
if (androidHomeDir == null) {
|
||||
// No dice.
|
||||
printTrace('Unable to locate an Android SDK.');
|
||||
globals.printTrace('Unable to locate an Android SDK.');
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -381,24 +379,24 @@ class AndroidSdk {
|
||||
}
|
||||
|
||||
static bool sdkDirectoryHasPlatformTools(String dir) {
|
||||
return fs.isDirectorySync(fs.path.join(dir, 'platform-tools'));
|
||||
return globals.fs.isDirectorySync(globals.fs.path.join(dir, 'platform-tools'));
|
||||
}
|
||||
|
||||
static bool sdkDirectoryHasLicenses(String dir) {
|
||||
return fs.isDirectorySync(fs.path.join(dir, 'licenses'));
|
||||
return globals.fs.isDirectorySync(globals.fs.path.join(dir, 'licenses'));
|
||||
}
|
||||
|
||||
List<AndroidSdkVersion> get sdkVersions => _sdkVersions;
|
||||
|
||||
AndroidSdkVersion get latestVersion => _latestVersion;
|
||||
|
||||
String get adbPath => getPlatformToolsPath(platform.isWindows ? 'adb.exe' : 'adb');
|
||||
String get adbPath => getPlatformToolsPath(globals.platform.isWindows ? 'adb.exe' : 'adb');
|
||||
|
||||
String get emulatorPath => getEmulatorPath();
|
||||
|
||||
String get avdManagerPath => getAvdManagerPath();
|
||||
|
||||
Directory get _platformsDir => fs.directory(fs.path.join(directory, 'platforms'));
|
||||
Directory get _platformsDir => globals.fs.directory(globals.fs.path.join(directory, 'platforms'));
|
||||
|
||||
Iterable<Directory> get _platforms {
|
||||
Iterable<Directory> platforms = <Directory>[];
|
||||
@@ -413,7 +411,7 @@ class AndroidSdk {
|
||||
/// Validate the Android SDK. This returns an empty list if there are no
|
||||
/// issues; otherwise, it returns a list of issues found.
|
||||
List<String> validateSdkWellFormed() {
|
||||
if (adbPath == null || !processManager.canRun(adbPath)) {
|
||||
if (adbPath == null || !globals.processManager.canRun(adbPath)) {
|
||||
return <String>['Android SDK file not found: ${adbPath ?? 'adb'}.'];
|
||||
}
|
||||
|
||||
@@ -434,21 +432,21 @@ class AndroidSdk {
|
||||
}
|
||||
|
||||
String getPlatformToolsPath(String binaryName) {
|
||||
final String path = fs.path.join(directory, 'platform-tools', binaryName);
|
||||
if (fs.file(path).existsSync()) {
|
||||
final String path = globals.fs.path.join(directory, 'platform-tools', binaryName);
|
||||
if (globals.fs.file(path).existsSync()) {
|
||||
return path;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String getEmulatorPath() {
|
||||
final String binaryName = platform.isWindows ? 'emulator.exe' : 'emulator';
|
||||
final String binaryName = globals.platform.isWindows ? 'emulator.exe' : 'emulator';
|
||||
// Emulator now lives inside "emulator" but used to live inside "tools" so
|
||||
// try both.
|
||||
final List<String> searchFolders = <String>['emulator', 'tools'];
|
||||
for (final String folder in searchFolders) {
|
||||
final String path = fs.path.join(directory, folder, binaryName);
|
||||
if (fs.file(path).existsSync()) {
|
||||
final String path = globals.fs.path.join(directory, folder, binaryName);
|
||||
if (globals.fs.file(path).existsSync()) {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
@@ -456,9 +454,9 @@ class AndroidSdk {
|
||||
}
|
||||
|
||||
String getAvdManagerPath() {
|
||||
final String binaryName = platform.isWindows ? 'avdmanager.bat' : 'avdmanager';
|
||||
final String path = fs.path.join(directory, 'tools', 'bin', binaryName);
|
||||
if (fs.file(path).existsSync()) {
|
||||
final String binaryName = globals.platform.isWindows ? 'avdmanager.bat' : 'avdmanager';
|
||||
final String path = globals.fs.path.join(directory, 'tools', 'bin', binaryName);
|
||||
if (globals.fs.file(path).existsSync()) {
|
||||
return path;
|
||||
}
|
||||
return null;
|
||||
@@ -471,7 +469,7 @@ class AndroidSdk {
|
||||
void reinitialize() {
|
||||
List<Version> buildTools = <Version>[]; // 19.1.0, 22.0.1, ...
|
||||
|
||||
final Directory buildToolsDir = fs.directory(fs.path.join(directory, 'build-tools'));
|
||||
final Directory buildToolsDir = globals.fs.directory(globals.fs.path.join(directory, 'build-tools'));
|
||||
if (buildToolsDir.existsSync()) {
|
||||
buildTools = buildToolsDir
|
||||
.listSync()
|
||||
@@ -533,24 +531,24 @@ class AndroidSdk {
|
||||
|
||||
/// Returns the filesystem path of the Android SDK manager tool or null if not found.
|
||||
String get sdkManagerPath {
|
||||
return fs.path.join(directory, 'tools', 'bin', 'sdkmanager');
|
||||
return globals.fs.path.join(directory, 'tools', 'bin', 'sdkmanager');
|
||||
}
|
||||
|
||||
/// First try Java bundled with Android Studio, then sniff JAVA_HOME, then fallback to PATH.
|
||||
static String findJavaBinary() {
|
||||
if (android_studio.javaPath != null) {
|
||||
return fs.path.join(android_studio.javaPath, 'bin', 'java');
|
||||
return globals.fs.path.join(android_studio.javaPath, 'bin', 'java');
|
||||
}
|
||||
|
||||
final String javaHomeEnv = platform.environment[_javaHomeEnvironmentVariable];
|
||||
final String javaHomeEnv = globals.platform.environment[_javaHomeEnvironmentVariable];
|
||||
if (javaHomeEnv != null) {
|
||||
// Trust JAVA_HOME.
|
||||
return fs.path.join(javaHomeEnv, 'bin', 'java');
|
||||
return globals.fs.path.join(javaHomeEnv, 'bin', 'java');
|
||||
}
|
||||
|
||||
// MacOS specific logic to avoid popping up a dialog window.
|
||||
// See: http://stackoverflow.com/questions/14292698/how-do-i-check-if-the-java-jdk-is-installed-on-mac.
|
||||
if (platform.isMacOS) {
|
||||
if (globals.platform.isMacOS) {
|
||||
try {
|
||||
final String javaHomeOutput = processUtils.runSync(
|
||||
<String>['/usr/libexec/java_home'],
|
||||
@@ -561,7 +559,7 @@ class AndroidSdk {
|
||||
final List<String> javaHomeOutputSplit = javaHomeOutput.split('\n');
|
||||
if ((javaHomeOutputSplit != null) && (javaHomeOutputSplit.isNotEmpty)) {
|
||||
final String javaHome = javaHomeOutputSplit[0].trim();
|
||||
return fs.path.join(javaHome, 'bin', 'java');
|
||||
return globals.fs.path.join(javaHome, 'bin', 'java');
|
||||
}
|
||||
}
|
||||
} catch (_) { /* ignore */ }
|
||||
@@ -581,7 +579,7 @@ class AndroidSdk {
|
||||
final String javaBinary = findJavaBinary();
|
||||
if (javaBinary != null) {
|
||||
_sdkManagerEnv['PATH'] =
|
||||
fs.path.dirname(javaBinary) + os.pathVarSeparator + platform.environment['PATH'];
|
||||
globals.fs.path.dirname(javaBinary) + os.pathVarSeparator + globals.platform.environment['PATH'];
|
||||
}
|
||||
}
|
||||
return _sdkManagerEnv;
|
||||
@@ -589,7 +587,7 @@ class AndroidSdk {
|
||||
|
||||
/// Returns the version of the Android SDK manager tool or null if not found.
|
||||
String get sdkManagerVersion {
|
||||
if (!processManager.canRun(sdkManagerPath)) {
|
||||
if (!globals.processManager.canRun(sdkManagerPath)) {
|
||||
throwToolExit('Android sdkmanager not found. Update to the latest Android SDK to resolve this.');
|
||||
}
|
||||
final RunResult result = processUtils.runSync(
|
||||
@@ -597,7 +595,7 @@ class AndroidSdk {
|
||||
environment: sdkManagerEnv,
|
||||
);
|
||||
if (result.exitCode != 0) {
|
||||
printTrace('sdkmanager --version failed: exitCode: ${result.exitCode} stdout: ${result.stdout} stderr: ${result.stderr}');
|
||||
globals.printTrace('sdkmanager --version failed: exitCode: ${result.exitCode} stdout: ${result.stdout} stderr: ${result.stderr}');
|
||||
return null;
|
||||
}
|
||||
return result.stdout.trim();
|
||||
@@ -641,11 +639,11 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
|
||||
}
|
||||
|
||||
String getPlatformsPath(String itemName) {
|
||||
return fs.path.join(sdk.directory, 'platforms', platformName, itemName);
|
||||
return globals.fs.path.join(sdk.directory, 'platforms', platformName, itemName);
|
||||
}
|
||||
|
||||
String getBuildToolsPath(String binaryName) {
|
||||
return fs.path.join(sdk.directory, 'build-tools', buildToolsVersionName, binaryName);
|
||||
return globals.fs.path.join(sdk.directory, 'build-tools', buildToolsVersionName, binaryName);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -655,14 +653,14 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
|
||||
String toString() => '[${sdk.directory}, SDK version $sdkLevel, build-tools $buildToolsVersionName]';
|
||||
|
||||
String _exists(String path) {
|
||||
if (!fs.isFileSync(path)) {
|
||||
if (!globals.fs.isFileSync(path)) {
|
||||
return 'Android SDK file not found: $path.';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String _canRun(String path) {
|
||||
if (!processManager.canRun(path)) {
|
||||
if (!globals.processManager.canRun(path)) {
|
||||
return 'Android SDK file not found: $path.';
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
import '../base/common.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../base/version.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../ios/plist_parser.dart';
|
||||
|
||||
AndroidStudio get androidStudio => context.get<AndroidStudio>();
|
||||
@@ -41,15 +39,15 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
|
||||
factory AndroidStudio.fromMacOSBundle(String bundlePath) {
|
||||
String studioPath = fs.path.join(bundlePath, 'Contents');
|
||||
String plistFile = fs.path.join(studioPath, 'Info.plist');
|
||||
String studioPath = globals.fs.path.join(bundlePath, 'Contents');
|
||||
String plistFile = globals.fs.path.join(studioPath, 'Info.plist');
|
||||
Map<String, dynamic> plistValues = PlistParser.instance.parseFile(plistFile);
|
||||
// As AndroidStudio managed by JetBrainsToolbox could have a wrapper pointing to the real Android Studio.
|
||||
// Check if we've found a JetBrainsToolbox wrapper and deal with it properly.
|
||||
final String jetBrainsToolboxAppBundlePath = plistValues['JetBrainsToolboxApp'] as String;
|
||||
if (jetBrainsToolboxAppBundlePath != null) {
|
||||
studioPath = fs.path.join(jetBrainsToolboxAppBundlePath, 'Contents');
|
||||
plistFile = fs.path.join(studioPath, 'Info.plist');
|
||||
studioPath = globals.fs.path.join(jetBrainsToolboxAppBundlePath, 'Contents');
|
||||
plistFile = globals.fs.path.join(studioPath, 'Info.plist');
|
||||
plistValues = PlistParser.instance.parseFile(plistFile);
|
||||
}
|
||||
|
||||
@@ -70,7 +68,7 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
final String presetPluginsPath = pathsSelectorValue == null
|
||||
? null
|
||||
: fs.path.join(homeDirPath, 'Library', 'Application Support', '$pathsSelectorValue');
|
||||
: globals.fs.path.join(homeDirPath, 'Library', 'Application Support', '$pathsSelectorValue');
|
||||
return AndroidStudio(studioPath, version: version, presetPluginsPath: presetPluginsPath);
|
||||
}
|
||||
|
||||
@@ -87,13 +85,13 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
String installPath;
|
||||
try {
|
||||
installPath = fs
|
||||
.file(fs.path.join(homeDotDir.path, 'system', '.home'))
|
||||
installPath = globals.fs
|
||||
.file(globals.fs.path.join(homeDotDir.path, 'system', '.home'))
|
||||
.readAsStringSync();
|
||||
} catch (e) {
|
||||
// ignored, installPath will be null, which is handled below
|
||||
}
|
||||
if (installPath != null && fs.isDirectorySync(installPath)) {
|
||||
if (installPath != null && globals.fs.isDirectorySync(installPath)) {
|
||||
return AndroidStudio(
|
||||
installPath,
|
||||
version: version,
|
||||
@@ -123,14 +121,14 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
final int major = version?.major;
|
||||
final int minor = version?.minor;
|
||||
if (platform.isMacOS) {
|
||||
return fs.path.join(
|
||||
if (globals.platform.isMacOS) {
|
||||
return globals.fs.path.join(
|
||||
homeDirPath,
|
||||
'Library',
|
||||
'Application Support',
|
||||
'AndroidStudio$major.$minor');
|
||||
} else {
|
||||
return fs.path.join(homeDirPath,
|
||||
return globals.fs.path.join(homeDirPath,
|
||||
'.$studioAppName$major.$minor',
|
||||
'config',
|
||||
'plugins');
|
||||
@@ -150,11 +148,11 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
|
||||
/// Locates the newest, valid version of Android Studio.
|
||||
static AndroidStudio latestValid() {
|
||||
final String configuredStudio = config.getValue('android-studio-dir') as String;
|
||||
final String configuredStudio = globals.config.getValue('android-studio-dir') as String;
|
||||
if (configuredStudio != null) {
|
||||
String configuredStudioPath = configuredStudio;
|
||||
if (platform.isMacOS && !configuredStudioPath.endsWith('Contents')) {
|
||||
configuredStudioPath = fs.path.join(configuredStudioPath, 'Contents');
|
||||
if (globals.platform.isMacOS && !configuredStudioPath.endsWith('Contents')) {
|
||||
configuredStudioPath = globals.fs.path.join(configuredStudioPath, 'Contents');
|
||||
}
|
||||
return AndroidStudio(configuredStudioPath,
|
||||
configured: configuredStudio);
|
||||
@@ -171,17 +169,17 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
|
||||
static List<AndroidStudio> allInstalled() =>
|
||||
platform.isMacOS ? _allMacOS() : _allLinuxOrWindows();
|
||||
globals.platform.isMacOS ? _allMacOS() : _allLinuxOrWindows();
|
||||
|
||||
static List<AndroidStudio> _allMacOS() {
|
||||
final List<FileSystemEntity> candidatePaths = <FileSystemEntity>[];
|
||||
|
||||
void _checkForStudio(String path) {
|
||||
if (!fs.isDirectorySync(path)) {
|
||||
if (!globals.fs.isDirectorySync(path)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
final Iterable<Directory> directories = fs
|
||||
final Iterable<Directory> directories = globals.fs
|
||||
.directory(path)
|
||||
.listSync(followLinks: false)
|
||||
.whereType<Directory>();
|
||||
@@ -195,16 +193,16 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
printTrace('Exception while looking for Android Studio: $e');
|
||||
globals.printTrace('Exception while looking for Android Studio: $e');
|
||||
}
|
||||
}
|
||||
|
||||
_checkForStudio('/Applications');
|
||||
_checkForStudio(fs.path.join(homeDirPath, 'Applications'));
|
||||
_checkForStudio(globals.fs.path.join(homeDirPath, 'Applications'));
|
||||
|
||||
final String configuredStudioDir = config.getValue('android-studio-dir') as String;
|
||||
final String configuredStudioDir = globals.config.getValue('android-studio-dir') as String;
|
||||
if (configuredStudioDir != null) {
|
||||
FileSystemEntity configuredStudio = fs.file(configuredStudioDir);
|
||||
FileSystemEntity configuredStudio = globals.fs.file(configuredStudioDir);
|
||||
if (configuredStudio.basename == 'Contents') {
|
||||
configuredStudio = configuredStudio.parent;
|
||||
}
|
||||
@@ -237,8 +235,8 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
|
||||
// Read all $HOME/.AndroidStudio*/system/.home files. There may be several
|
||||
// pointing to the same installation, so we grab only the latest one.
|
||||
if (homeDirPath != null && fs.directory(homeDirPath).existsSync()) {
|
||||
for (FileSystemEntity entity in fs.directory(homeDirPath).listSync(followLinks: false)) {
|
||||
if (homeDirPath != null && globals.fs.directory(homeDirPath).existsSync()) {
|
||||
for (FileSystemEntity entity in globals.fs.directory(homeDirPath).listSync(followLinks: false)) {
|
||||
if (entity is Directory && entity.basename.startsWith('.AndroidStudio')) {
|
||||
final AndroidStudio studio = AndroidStudio.fromHomeDot(entity);
|
||||
if (studio != null && !_hasStudioAt(studio.directory, newerThan: studio.version)) {
|
||||
@@ -249,15 +247,15 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
}
|
||||
}
|
||||
|
||||
final String configuredStudioDir = config.getValue('android-studio-dir') as String;
|
||||
final String configuredStudioDir = globals.config.getValue('android-studio-dir') as String;
|
||||
if (configuredStudioDir != null && !_hasStudioAt(configuredStudioDir)) {
|
||||
studios.add(AndroidStudio(configuredStudioDir,
|
||||
configured: configuredStudioDir));
|
||||
}
|
||||
|
||||
if (platform.isLinux) {
|
||||
if (globals.platform.isLinux) {
|
||||
void _checkWellKnownPath(String path) {
|
||||
if (fs.isDirectorySync(path) && !_hasStudioAt(path)) {
|
||||
if (globals.fs.isDirectorySync(path) && !_hasStudioAt(path)) {
|
||||
studios.add(AndroidStudio(path));
|
||||
}
|
||||
}
|
||||
@@ -284,16 +282,16 @@ class AndroidStudio implements Comparable<AndroidStudio> {
|
||||
_validationMessages.add('android-studio-dir = $configured');
|
||||
}
|
||||
|
||||
if (!fs.isDirectorySync(directory)) {
|
||||
if (!globals.fs.isDirectorySync(directory)) {
|
||||
_validationMessages.add('Android Studio not found at $directory');
|
||||
return;
|
||||
}
|
||||
|
||||
final String javaPath = platform.isMacOS ?
|
||||
fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') :
|
||||
fs.path.join(directory, 'jre');
|
||||
final String javaExecutable = fs.path.join(javaPath, 'bin', 'java');
|
||||
if (!processManager.canRun(javaExecutable)) {
|
||||
final String javaPath = globals.platform.isMacOS ?
|
||||
globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') :
|
||||
globals.fs.path.join(directory, 'jre');
|
||||
final String javaExecutable = globals.fs.path.join(javaPath, 'bin', 'java');
|
||||
if (!globals.processManager.canRun(javaExecutable)) {
|
||||
_validationMessages.add('Unable to find bundled Java version.');
|
||||
} else {
|
||||
final RunResult result = processUtils.runSync(<String>[javaExecutable, '-version']);
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'dart:async';
|
||||
import '../base/user_messages.dart';
|
||||
import '../base/version.dart';
|
||||
import '../doctor.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../intellij/intellij.dart';
|
||||
import 'android_studio.dart';
|
||||
|
||||
@@ -71,7 +71,7 @@ class NoAndroidStudioValidator extends DoctorValidator {
|
||||
Future<ValidationResult> validate() async {
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||
|
||||
final String cfgAndroidStudio = config.getValue('android-studio-dir') as String;
|
||||
final String cfgAndroidStudio = globals.config.getValue('android-studio-dir') as String;
|
||||
if (cfgAndroidStudio != null) {
|
||||
messages.add(ValidationMessage.error(userMessages.androidStudioMissing(cfgAndroidStudio)));
|
||||
}
|
||||
|
||||
@@ -7,15 +7,13 @@ import 'dart:async';
|
||||
import '../base/common.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/io.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/process_manager.dart';
|
||||
import '../base/user_messages.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../base/version.dart';
|
||||
import '../convert.dart';
|
||||
import '../doctor.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import 'android_sdk.dart';
|
||||
|
||||
const int kAndroidSdkMinVersion = 28;
|
||||
@@ -74,20 +72,20 @@ class AndroidValidator extends DoctorValidator {
|
||||
Future<bool> _checkJavaVersion(String javaBinary, List<ValidationMessage> messages) async {
|
||||
_task = 'Checking Java status';
|
||||
try {
|
||||
if (!processManager.canRun(javaBinary)) {
|
||||
if (!globals.processManager.canRun(javaBinary)) {
|
||||
messages.add(ValidationMessage.error(userMessages.androidCantRunJavaBinary(javaBinary)));
|
||||
return false;
|
||||
}
|
||||
String javaVersionText;
|
||||
try {
|
||||
printTrace('java -version');
|
||||
final ProcessResult result = await processManager.run(<String>[javaBinary, '-version']);
|
||||
globals.printTrace('java -version');
|
||||
final ProcessResult result = await globals.processManager.run(<String>[javaBinary, '-version']);
|
||||
if (result.exitCode == 0) {
|
||||
final List<String> versionLines = (result.stderr as String).split('\n');
|
||||
javaVersionText = versionLines.length >= 2 ? versionLines[1] : versionLines[0];
|
||||
}
|
||||
} catch (error) {
|
||||
printTrace(error.toString());
|
||||
globals.printTrace(error.toString());
|
||||
}
|
||||
if (javaVersionText == null || javaVersionText.isEmpty) {
|
||||
// Could not determine the java version.
|
||||
@@ -112,8 +110,8 @@ class AndroidValidator extends DoctorValidator {
|
||||
|
||||
if (androidSdk == null) {
|
||||
// No Android SDK found.
|
||||
if (platform.environment.containsKey(kAndroidHome)) {
|
||||
final String androidHomeDir = platform.environment[kAndroidHome];
|
||||
if (globals.platform.environment.containsKey(kAndroidHome)) {
|
||||
final String androidHomeDir = globals.platform.environment[kAndroidHome];
|
||||
messages.add(ValidationMessage.error(userMessages.androidBadSdkDir(kAndroidHome, androidHomeDir)));
|
||||
} else {
|
||||
messages.add(ValidationMessage.error(userMessages.androidMissingSdkInstructions(kAndroidHome)));
|
||||
@@ -149,12 +147,12 @@ class AndroidValidator extends DoctorValidator {
|
||||
messages.add(ValidationMessage.error(userMessages.androidMissingSdkInstructions(kAndroidHome)));
|
||||
}
|
||||
|
||||
if (platform.environment.containsKey(kAndroidHome)) {
|
||||
final String androidHomeDir = platform.environment[kAndroidHome];
|
||||
if (globals.platform.environment.containsKey(kAndroidHome)) {
|
||||
final String androidHomeDir = globals.platform.environment[kAndroidHome];
|
||||
messages.add(ValidationMessage('$kAndroidHome = $androidHomeDir'));
|
||||
}
|
||||
if (platform.environment.containsKey(kAndroidSdkRoot)) {
|
||||
final String androidSdkRoot = platform.environment[kAndroidSdkRoot];
|
||||
if (globals.platform.environment.containsKey(kAndroidSdkRoot)) {
|
||||
final String androidSdkRoot = globals.platform.environment[kAndroidSdkRoot];
|
||||
messages.add(ValidationMessage('$kAndroidSdkRoot = $androidSdkRoot'));
|
||||
}
|
||||
|
||||
@@ -229,18 +227,18 @@ class AndroidLicenseValidator extends DoctorValidator {
|
||||
if (javaBinary == null) {
|
||||
return false;
|
||||
}
|
||||
if (!processManager.canRun(javaBinary)) {
|
||||
if (!globals.processManager.canRun(javaBinary)) {
|
||||
return false;
|
||||
}
|
||||
String javaVersion;
|
||||
try {
|
||||
final ProcessResult result = await processManager.run(<String>[javaBinary, '-version']);
|
||||
final ProcessResult result = await globals.processManager.run(<String>[javaBinary, '-version']);
|
||||
if (result.exitCode == 0) {
|
||||
final List<String> versionLines = (result.stderr as String).split('\n');
|
||||
javaVersion = versionLines.length >= 2 ? versionLines[1] : versionLines[0];
|
||||
}
|
||||
} catch (error) {
|
||||
printTrace(error.toString());
|
||||
globals.printTrace(error.toString());
|
||||
}
|
||||
if (javaVersion == null) {
|
||||
// Could not determine the java version.
|
||||
@@ -295,7 +293,7 @@ class AndroidLicenseValidator extends DoctorValidator {
|
||||
await Future.wait<void>(<Future<void>>[output, errors]);
|
||||
return status ?? LicensesAccepted.unknown;
|
||||
} on ProcessException catch (e) {
|
||||
printTrace('Failed to run Android sdk manager: $e');
|
||||
globals.printTrace('Failed to run Android sdk manager: $e');
|
||||
return LicensesAccepted.unknown;
|
||||
}
|
||||
}
|
||||
@@ -303,7 +301,7 @@ class AndroidLicenseValidator extends DoctorValidator {
|
||||
/// Run the Android SDK manager tool in order to accept SDK licenses.
|
||||
static Future<bool> runLicenseManager() async {
|
||||
if (androidSdk == null) {
|
||||
printStatus(userMessages.androidSdkShort);
|
||||
globals.printStatus(userMessages.androidSdkShort);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -345,6 +343,6 @@ class AndroidLicenseValidator extends DoctorValidator {
|
||||
static bool _canRunSdkManager() {
|
||||
assert(androidSdk != null);
|
||||
final String sdkManagerPath = androidSdk.sdkManagerPath;
|
||||
return processManager.canRun(sdkManagerPath);
|
||||
return globals.processManager.canRun(sdkManagerPath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../flutter_manifest.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import 'android_sdk.dart';
|
||||
@@ -107,12 +107,12 @@ Iterable<String> _apkFilesFor(AndroidBuildInfo androidBuildInfo) {
|
||||
/// Returns true if the current version of the Gradle plugin is supported.
|
||||
bool _isSupportedVersion(AndroidProject project) {
|
||||
final File plugin = project.hostAppGradleRoot.childFile(
|
||||
fs.path.join('buildSrc', 'src', 'main', 'groovy', 'FlutterPlugin.groovy'));
|
||||
globals.fs.path.join('buildSrc', 'src', 'main', 'groovy', 'FlutterPlugin.groovy'));
|
||||
if (plugin.existsSync()) {
|
||||
return false;
|
||||
}
|
||||
final File appGradle = project.hostAppGradleRoot.childFile(
|
||||
fs.path.join('app', 'build.gradle'));
|
||||
globals.fs.path.join('app', 'build.gradle'));
|
||||
if (!appGradle.existsSync()) {
|
||||
return false;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ Future<File> getGradleAppOut(AndroidProject androidProject) async {
|
||||
/// Runs `gradlew dependencies`, ensuring that dependencies are resolved and
|
||||
/// potentially downloaded.
|
||||
Future<void> checkGradleDependencies() async {
|
||||
final Status progress = logger.startProgress(
|
||||
final Status progress = globals.logger.startProgress(
|
||||
'Ensuring gradle dependencies are up to date...',
|
||||
timeout: timeoutConfiguration.slowOperation,
|
||||
);
|
||||
@@ -168,15 +168,15 @@ void createSettingsAarGradle(Directory androidDirectory) {
|
||||
}
|
||||
final String currentFileContent = currentSettingsFile.readAsStringSync();
|
||||
|
||||
final String newSettingsRelativeFile = fs.path.relative(newSettingsFile.path);
|
||||
final Status status = logger.startProgress('✏️ Creating `$newSettingsRelativeFile`...',
|
||||
final String newSettingsRelativeFile = globals.fs.path.relative(newSettingsFile.path);
|
||||
final Status status = globals.logger.startProgress('✏️ Creating `$newSettingsRelativeFile`...',
|
||||
timeout: timeoutConfiguration.fastOperation);
|
||||
|
||||
final String flutterRoot = fs.path.absolute(Cache.flutterRoot);
|
||||
final File deprecatedFile = fs.file(fs.path.join(flutterRoot, 'packages','flutter_tools',
|
||||
final String flutterRoot = globals.fs.path.absolute(Cache.flutterRoot);
|
||||
final File deprecatedFile = globals.fs.file(globals.fs.path.join(flutterRoot, 'packages','flutter_tools',
|
||||
'gradle', 'deprecated_settings.gradle'));
|
||||
assert(deprecatedFile.existsSync());
|
||||
final String settingsAarContent = fs.file(fs.path.join(flutterRoot, 'packages','flutter_tools',
|
||||
final String settingsAarContent = globals.fs.file(globals.fs.path.join(flutterRoot, 'packages','flutter_tools',
|
||||
'gradle', 'settings_aar.gradle.tmpl')).readAsStringSync();
|
||||
|
||||
// Get the `settings.gradle` content variants that should be patched.
|
||||
@@ -192,16 +192,16 @@ void createSettingsAarGradle(Directory androidDirectory) {
|
||||
}
|
||||
if (!exactMatch) {
|
||||
status.cancel();
|
||||
printStatus('$warningMark Flutter tried to create the file `$newSettingsRelativeFile`, but failed.');
|
||||
globals.printStatus('$warningMark Flutter tried to create the file `$newSettingsRelativeFile`, but failed.');
|
||||
// Print how to manually update the file.
|
||||
printStatus(fs.file(fs.path.join(flutterRoot, 'packages','flutter_tools',
|
||||
globals.printStatus(globals.fs.file(globals.fs.path.join(flutterRoot, 'packages','flutter_tools',
|
||||
'gradle', 'manual_migration_settings.gradle.md')).readAsStringSync());
|
||||
throwToolExit('Please create the file and run this command again.');
|
||||
}
|
||||
// Copy the new file.
|
||||
newSettingsFile.writeAsStringSync(settingsAarContent);
|
||||
status.stop();
|
||||
printStatus('$successMark `$newSettingsRelativeFile` created successfully.');
|
||||
globals.printStatus('$successMark `$newSettingsRelativeFile` created successfully.');
|
||||
}
|
||||
|
||||
/// Builds an app.
|
||||
@@ -244,8 +244,8 @@ Future<void> buildGradleApp({
|
||||
BuildEvent('app-using-android-x').send();
|
||||
} else if (!usesAndroidX) {
|
||||
BuildEvent('app-not-using-android-x').send();
|
||||
printStatus('$warningMark Your app isn\'t using AndroidX.', emphasis: true);
|
||||
printStatus(
|
||||
globals.printStatus('$warningMark Your app isn\'t using AndroidX.', emphasis: true);
|
||||
globals.printStatus(
|
||||
'To avoid potential build failures, you can quickly migrate your app '
|
||||
'by following the steps on https://goo.gl/CP92wY.',
|
||||
indent: 4,
|
||||
@@ -270,7 +270,7 @@ Future<void> buildGradleApp({
|
||||
? getBundleTaskFor(buildInfo)
|
||||
: getAssembleTaskFor(buildInfo);
|
||||
|
||||
final Status status = logger.startProgress(
|
||||
final Status status = globals.logger.startProgress(
|
||||
'Running Gradle task \'$assembleTask\'...',
|
||||
timeout: timeoutConfiguration.slowOperation,
|
||||
multilineOutput: true,
|
||||
@@ -279,18 +279,18 @@ Future<void> buildGradleApp({
|
||||
final List<String> command = <String>[
|
||||
gradleUtils.getExecutable(project),
|
||||
];
|
||||
if (logger.isVerbose) {
|
||||
if (globals.logger.isVerbose) {
|
||||
command.add('-Pverbose=true');
|
||||
} else {
|
||||
command.add('-q');
|
||||
}
|
||||
if (artifacts is LocalEngineArtifacts) {
|
||||
final LocalEngineArtifacts localEngineArtifacts = artifacts as LocalEngineArtifacts;
|
||||
if (globals.artifacts is LocalEngineArtifacts) {
|
||||
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts;
|
||||
final Directory localEngineRepo = _getLocalEngineRepo(
|
||||
engineOutPath: localEngineArtifacts.engineOutPath,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
);
|
||||
printTrace(
|
||||
globals.printTrace(
|
||||
'Using local engine: ${localEngineArtifacts.engineOutPath}\n'
|
||||
'Local Maven repo: ${localEngineRepo.path}'
|
||||
);
|
||||
@@ -448,8 +448,8 @@ Future<void> buildGradleApp({
|
||||
? '' // Don't display the size when building a debug variant.
|
||||
: ' (${getSizeAsMB(bundleFile.lengthSync())})';
|
||||
|
||||
printStatus(
|
||||
'$successMark Built ${fs.path.relative(bundleFile.path)}$appSize.',
|
||||
globals.printStatus(
|
||||
'$successMark Built ${globals.fs.path.relative(bundleFile.path)}$appSize.',
|
||||
color: TerminalColor.green,
|
||||
);
|
||||
return;
|
||||
@@ -460,7 +460,7 @@ Future<void> buildGradleApp({
|
||||
// Copy the first APK to app.apk, so `flutter run` can find it.
|
||||
// TODO(egarciad): Handle multiple APKs.
|
||||
apkFiles.first.copySync(apkDirectory.childFile('app.apk').path);
|
||||
printTrace('calculateSha: $apkDirectory/app.apk');
|
||||
globals.printTrace('calculateSha: $apkDirectory/app.apk');
|
||||
|
||||
final File apkShaFile = apkDirectory.childFile('app.apk.sha1');
|
||||
apkShaFile.writeAsStringSync(_calculateSha(apkFiles.first));
|
||||
@@ -469,8 +469,8 @@ Future<void> buildGradleApp({
|
||||
final String appSize = (buildInfo.mode == BuildMode.debug)
|
||||
? '' // Don't display the size when building a debug variant.
|
||||
: ' (${getSizeAsMB(apkFile.lengthSync())})';
|
||||
printStatus(
|
||||
'$successMark Built ${fs.path.relative(apkFile.path)}$appSize.',
|
||||
globals.printStatus(
|
||||
'$successMark Built ${globals.fs.path.relative(apkFile.path)}$appSize.',
|
||||
color: TerminalColor.green,
|
||||
);
|
||||
}
|
||||
@@ -501,14 +501,14 @@ Future<void> buildGradleAar({
|
||||
}
|
||||
|
||||
final String aarTask = getAarTaskFor(androidBuildInfo.buildInfo);
|
||||
final Status status = logger.startProgress(
|
||||
final Status status = globals.logger.startProgress(
|
||||
'Running Gradle task \'$aarTask\'...',
|
||||
timeout: timeoutConfiguration.slowOperation,
|
||||
multilineOutput: true,
|
||||
);
|
||||
|
||||
final String flutterRoot = fs.path.absolute(Cache.flutterRoot);
|
||||
final String initScript = fs.path.join(
|
||||
final String flutterRoot = globals.fs.path.absolute(Cache.flutterRoot);
|
||||
final String initScript = globals.fs.path.join(
|
||||
flutterRoot,
|
||||
'packages',
|
||||
'flutter_tools',
|
||||
@@ -533,13 +533,13 @@ Future<void> buildGradleAar({
|
||||
.map(getPlatformNameForAndroidArch).join(',');
|
||||
command.add('-Ptarget-platform=$targetPlatforms');
|
||||
}
|
||||
if (artifacts is LocalEngineArtifacts) {
|
||||
final LocalEngineArtifacts localEngineArtifacts = artifacts as LocalEngineArtifacts;
|
||||
if (globals.artifacts is LocalEngineArtifacts) {
|
||||
final LocalEngineArtifacts localEngineArtifacts = globals.artifacts as LocalEngineArtifacts;
|
||||
final Directory localEngineRepo = _getLocalEngineRepo(
|
||||
engineOutPath: localEngineArtifacts.engineOutPath,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
);
|
||||
printTrace(
|
||||
globals.printTrace(
|
||||
'Using local engine: ${localEngineArtifacts.engineOutPath}\n'
|
||||
'Local Maven repo: ${localEngineRepo.path}'
|
||||
);
|
||||
@@ -565,8 +565,8 @@ Future<void> buildGradleAar({
|
||||
flutterUsage.sendTiming('build', 'gradle-aar', sw.elapsed);
|
||||
|
||||
if (result.exitCode != 0) {
|
||||
printStatus(result.stdout, wrap: false);
|
||||
printError(result.stderr, wrap: false);
|
||||
globals.printStatus(result.stdout, wrap: false);
|
||||
globals.printError(result.stderr, wrap: false);
|
||||
throwToolExit(
|
||||
'Gradle task $aarTask failed with exit code $exitCode.',
|
||||
exitCode: exitCode,
|
||||
@@ -574,15 +574,15 @@ Future<void> buildGradleAar({
|
||||
}
|
||||
final Directory repoDirectory = getRepoDirectory(outputDirectory);
|
||||
if (!repoDirectory.existsSync()) {
|
||||
printStatus(result.stdout, wrap: false);
|
||||
printError(result.stderr, wrap: false);
|
||||
globals.printStatus(result.stdout, wrap: false);
|
||||
globals.printError(result.stderr, wrap: false);
|
||||
throwToolExit(
|
||||
'Gradle task $aarTask failed to produce $repoDirectory.',
|
||||
exitCode: exitCode,
|
||||
);
|
||||
}
|
||||
printStatus(
|
||||
'$successMark Built ${fs.path.relative(repoDirectory.path)}.',
|
||||
globals.printStatus(
|
||||
'$successMark Built ${globals.fs.path.relative(repoDirectory.path)}.',
|
||||
color: TerminalColor.green,
|
||||
);
|
||||
}
|
||||
@@ -599,10 +599,10 @@ void printHowToConsumeAar({
|
||||
assert(repoDirectory != null);
|
||||
buildNumber ??= '1.0';
|
||||
|
||||
printStatus('''
|
||||
globals.printStatus('''
|
||||
|
||||
${terminal.bolden('Consuming the Module')}
|
||||
1. Open ${fs.path.join('<host>', 'app', 'build.gradle')}
|
||||
${globals.terminal.bolden('Consuming the Module')}
|
||||
1. Open ${globals.fs.path.join('<host>', 'app', 'build.gradle')}
|
||||
2. Ensure you have the repositories configured, otherwise add them:
|
||||
|
||||
repositories {
|
||||
@@ -619,16 +619,16 @@ ${terminal.bolden('Consuming the Module')}
|
||||
dependencies {''');
|
||||
|
||||
for (String buildMode in buildModes) {
|
||||
printStatus('''
|
||||
globals.printStatus('''
|
||||
${buildMode}Implementation '$androidPackage:flutter_$buildMode:$buildNumber''');
|
||||
}
|
||||
|
||||
printStatus('''
|
||||
globals.printStatus('''
|
||||
}
|
||||
''');
|
||||
|
||||
if (buildModes.contains('profile')) {
|
||||
printStatus('''
|
||||
globals.printStatus('''
|
||||
|
||||
4. Add the `profile` build type:
|
||||
|
||||
@@ -642,7 +642,7 @@ printStatus('''
|
||||
''');
|
||||
}
|
||||
|
||||
printStatus('To learn more, visit https://flutter.dev/go/build-aar''');
|
||||
globals.printStatus('To learn more, visit https://flutter.dev/go/build-aar''');
|
||||
}
|
||||
|
||||
String _hex(List<int> bytes) {
|
||||
@@ -656,11 +656,11 @@ String _hex(List<int> bytes) {
|
||||
String _calculateSha(File file) {
|
||||
final Stopwatch sw = Stopwatch()..start();
|
||||
final List<int> bytes = file.readAsBytesSync();
|
||||
printTrace('calculateSha: reading file took ${sw.elapsedMilliseconds}us');
|
||||
globals.printTrace('calculateSha: reading file took ${sw.elapsedMilliseconds}us');
|
||||
flutterUsage.sendTiming('build', 'apk-sha-read', sw.elapsed);
|
||||
sw.reset();
|
||||
final String sha = _hex(sha1.convert(bytes).bytes);
|
||||
printTrace('calculateSha: computing sha took ${sw.elapsedMilliseconds}us');
|
||||
globals.printTrace('calculateSha: computing sha took ${sw.elapsedMilliseconds}us');
|
||||
flutterUsage.sendTiming('build', 'apk-sha-calc', sw.elapsed);
|
||||
return sha;
|
||||
}
|
||||
@@ -712,16 +712,16 @@ Future<void> buildPluginsAsAar(
|
||||
if (pluginParts.length != 2) {
|
||||
continue;
|
||||
}
|
||||
final Directory pluginDirectory = fs.directory(pluginParts.last);
|
||||
final Directory pluginDirectory = globals.fs.directory(pluginParts.last);
|
||||
assert(pluginDirectory.existsSync());
|
||||
|
||||
final String pluginName = pluginParts.first;
|
||||
final File buildGradleFile = pluginDirectory.childDirectory('android').childFile('build.gradle');
|
||||
if (!buildGradleFile.existsSync()) {
|
||||
printTrace('Skipping plugin $pluginName since it doesn\'t have a android/build.gradle file');
|
||||
globals.printTrace('Skipping plugin $pluginName since it doesn\'t have a android/build.gradle file');
|
||||
continue;
|
||||
}
|
||||
logger.printStatus('Building plugin $pluginName...');
|
||||
globals.logger.printStatus('Building plugin $pluginName...');
|
||||
try {
|
||||
await buildGradleAar(
|
||||
project: FlutterProject.fromDirectory(pluginDirectory),
|
||||
@@ -848,11 +848,11 @@ void _exitWithExpectedFileNotFound({
|
||||
}
|
||||
|
||||
void _createSymlink(String targetPath, String linkPath) {
|
||||
final File targetFile = fs.file(targetPath);
|
||||
final File targetFile = globals.fs.file(targetPath);
|
||||
if (!targetFile.existsSync()) {
|
||||
throwToolExit('The file $targetPath wasn\'t found in the local engine out directory.');
|
||||
}
|
||||
final File linkFile = fs.file(linkPath);
|
||||
final File linkFile = globals.fs.file(linkPath);
|
||||
final Link symlink = linkFile.parent.childLink(linkFile.basename);
|
||||
try {
|
||||
symlink.createSync(targetPath, recursive: true);
|
||||
@@ -864,7 +864,7 @@ void _createSymlink(String targetPath, String linkPath) {
|
||||
}
|
||||
|
||||
String _getLocalArtifactVersion(String pomPath) {
|
||||
final File pomFile = fs.file(pomPath);
|
||||
final File pomFile = globals.fs.file(pomPath);
|
||||
if (!pomFile.existsSync()) {
|
||||
throwToolExit('The file $pomPath wasn\'t found in the local engine out directory.');
|
||||
}
|
||||
@@ -903,7 +903,7 @@ Directory _getLocalEngineRepo({
|
||||
assert(androidBuildInfo != null);
|
||||
|
||||
final String abi = getEnumName(androidBuildInfo.targetArchs.first);
|
||||
final Directory localEngineRepo = fs.systemTempDirectory
|
||||
final Directory localEngineRepo = globals.fs.systemTempDirectory
|
||||
.createTempSync('flutter_tool_local_engine_repo.');
|
||||
|
||||
// Remove the local engine repo before the tool exits.
|
||||
@@ -914,7 +914,7 @@ Directory _getLocalEngineRepo({
|
||||
|
||||
final String buildMode = androidBuildInfo.buildInfo.modeName;
|
||||
final String artifactVersion = _getLocalArtifactVersion(
|
||||
fs.path.join(
|
||||
globals.fs.path.join(
|
||||
engineOutPath,
|
||||
'flutter_embedding_$buildMode.pom',
|
||||
)
|
||||
@@ -922,11 +922,11 @@ Directory _getLocalEngineRepo({
|
||||
for (String artifact in const <String>['pom', 'jar']) {
|
||||
// The Android embedding artifacts.
|
||||
_createSymlink(
|
||||
fs.path.join(
|
||||
globals.fs.path.join(
|
||||
engineOutPath,
|
||||
'flutter_embedding_$buildMode.$artifact',
|
||||
),
|
||||
fs.path.join(
|
||||
globals.fs.path.join(
|
||||
localEngineRepo.path,
|
||||
'io',
|
||||
'flutter',
|
||||
@@ -937,11 +937,11 @@ Directory _getLocalEngineRepo({
|
||||
);
|
||||
// The engine artifacts (libflutter.so).
|
||||
_createSymlink(
|
||||
fs.path.join(
|
||||
globals.fs.path.join(
|
||||
engineOutPath,
|
||||
'${abi}_$buildMode.$artifact',
|
||||
),
|
||||
fs.path.join(
|
||||
globals.fs.path.join(
|
||||
localEngineRepo.path,
|
||||
'io',
|
||||
'flutter',
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/process.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import 'gradle_utils.dart';
|
||||
@@ -85,8 +85,8 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
|
||||
bool usesAndroidX,
|
||||
bool shouldBuildPluginAsAar,
|
||||
}) async {
|
||||
printStatus('$warningMark Gradle does not have execution permission.', emphasis: true);
|
||||
printStatus(
|
||||
globals.printStatus('$warningMark Gradle does not have execution permission.', emphasis: true);
|
||||
globals.printStatus(
|
||||
'You should change the ownership of the project directory to your user, '
|
||||
'or move the project to a directory with execute permissions.',
|
||||
indent: 4
|
||||
@@ -115,7 +115,7 @@ final GradleHandledError networkErrorHandler = GradleHandledError(
|
||||
bool usesAndroidX,
|
||||
bool shouldBuildPluginAsAar,
|
||||
}) async {
|
||||
printError(
|
||||
globals.printError(
|
||||
'$warningMark Gradle threw an error while trying to update itself. '
|
||||
'Retrying the update...'
|
||||
);
|
||||
@@ -136,9 +136,9 @@ final GradleHandledError r8FailureHandler = GradleHandledError(
|
||||
bool usesAndroidX,
|
||||
bool shouldBuildPluginAsAar,
|
||||
}) async {
|
||||
printStatus('$warningMark The shrinker may have failed to optimize the Java bytecode.', emphasis: true);
|
||||
printStatus('To disable the shrinker, pass the `--no-shrink` flag to this command.', indent: 4);
|
||||
printStatus('To learn more, see: https://developer.android.com/studio/build/shrink-code', indent: 4);
|
||||
globals.printStatus('$warningMark The shrinker may have failed to optimize the Java bytecode.', emphasis: true);
|
||||
globals.printStatus('To disable the shrinker, pass the `--no-shrink` flag to this command.', indent: 4);
|
||||
globals.printStatus('To learn more, see: https://developer.android.com/studio/build/shrink-code', indent: 4);
|
||||
return GradleBuildStatus.exit;
|
||||
},
|
||||
eventLabel: 'r8',
|
||||
@@ -187,7 +187,7 @@ final GradleHandledError androidXFailureHandler = GradleHandledError(
|
||||
if (hasPlugins && !usesAndroidX) {
|
||||
// If the app isn't using AndroidX, then the app is likely using
|
||||
// a plugin already migrated to AndroidX.
|
||||
printStatus(
|
||||
globals.printStatus(
|
||||
'AndroidX incompatibilities may have caused this build to fail. '
|
||||
'Please migrate your app to AndroidX. See https://goo.gl/CP92wY.'
|
||||
);
|
||||
@@ -206,7 +206,7 @@ final GradleHandledError androidXFailureHandler = GradleHandledError(
|
||||
).send();
|
||||
}
|
||||
if (hasPlugins && usesAndroidX && !shouldBuildPluginAsAar) {
|
||||
printStatus(
|
||||
globals.printStatus(
|
||||
'The built failed likely due to AndroidX incompatibilities in a plugin. '
|
||||
'The tool is about to try using Jetfier to solve the incompatibility.'
|
||||
);
|
||||
@@ -242,7 +242,7 @@ final GradleHandledError licenseNotAcceptedHandler = GradleHandledError(
|
||||
final RegExp licenseFailure = RegExp(licenseNotAcceptedMatcher, multiLine: true);
|
||||
assert(licenseFailure != null);
|
||||
final Match licenseMatch = licenseFailure.firstMatch(line);
|
||||
printStatus(
|
||||
globals.printStatus(
|
||||
'$warningMark Unable to download needed Android SDK components, as the '
|
||||
'following licenses have not been accepted:\n'
|
||||
'${licenseMatch.group(1)}\n\n'
|
||||
@@ -303,18 +303,18 @@ final GradleHandledError flavorUndefinedHandler = GradleHandledError(
|
||||
}
|
||||
}
|
||||
}
|
||||
printStatus(
|
||||
globals.printStatus(
|
||||
'\n$warningMark Gradle project does not define a task suitable '
|
||||
'for the requested build.'
|
||||
);
|
||||
if (productFlavors.isEmpty) {
|
||||
printStatus(
|
||||
globals.printStatus(
|
||||
'The android/app/build.gradle file does not define '
|
||||
'any custom product flavors. '
|
||||
'You cannot use the --flavor option.'
|
||||
);
|
||||
} else {
|
||||
printStatus(
|
||||
globals.printStatus(
|
||||
'The android/app/build.gradle file defines product '
|
||||
'flavors: ${productFlavors.join(', ')} '
|
||||
'You must specify a --flavor option to select one of them.'
|
||||
|
||||
@@ -9,13 +9,12 @@ import '../base/common.dart';
|
||||
import '../base/context.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/os.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../base/version.dart';
|
||||
import '../build_info.dart';
|
||||
import '../cache.dart';
|
||||
import '../globals.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import 'android_sdk.dart';
|
||||
@@ -23,7 +22,7 @@ import 'android_studio.dart';
|
||||
|
||||
/// The environment variables needed to run Gradle.
|
||||
Map<String, String> get gradleEnvironment {
|
||||
final Map<String, String> environment = Map<String, String>.from(platform.environment);
|
||||
final Map<String, String> environment = Map<String, String>.from(globals.platform.environment);
|
||||
if (javaPath != null) {
|
||||
// Use java bundled with Android Studio.
|
||||
environment['JAVA_HOME'] = javaPath;
|
||||
@@ -50,10 +49,10 @@ class GradleUtils {
|
||||
gradleUtils.injectGradleWrapperIfNeeded(androidDir);
|
||||
|
||||
final File gradle = androidDir.childFile(
|
||||
platform.isWindows ? 'gradlew.bat' : 'gradlew',
|
||||
globals.platform.isWindows ? 'gradlew.bat' : 'gradlew',
|
||||
);
|
||||
if (gradle.existsSync()) {
|
||||
printTrace('Using gradle from ${gradle.absolute.path}.');
|
||||
globals.printTrace('Using gradle from ${gradle.absolute.path}.');
|
||||
// If the Gradle executable doesn't have execute permission,
|
||||
// then attempt to set it.
|
||||
_giveExecutePermissionIfNeeded(gradle);
|
||||
@@ -79,10 +78,10 @@ class GradleUtils {
|
||||
}
|
||||
final String propertiesContent = gradleProperties.readAsStringSync();
|
||||
if (propertiesContent.contains('android.enableR8')) {
|
||||
printTrace('gradle.properties already sets `android.enableR8`');
|
||||
globals.printTrace('gradle.properties already sets `android.enableR8`');
|
||||
return;
|
||||
}
|
||||
printTrace('set `android.enableR8=true` in gradle.properties');
|
||||
globals.printTrace('set `android.enableR8=true` in gradle.properties');
|
||||
try {
|
||||
if (propertiesContent.isNotEmpty && !propertiesContent.endsWith('\n')) {
|
||||
// Add a new line if the file doesn't end with a new line.
|
||||
@@ -100,7 +99,7 @@ class GradleUtils {
|
||||
/// Injects the Gradle wrapper files if any of these files don't exist in [directory].
|
||||
void injectGradleWrapperIfNeeded(Directory directory) {
|
||||
copyDirectorySync(
|
||||
cache.getArtifactDirectory('gradle_wrapper'),
|
||||
globals.cache.getArtifactDirectory('gradle_wrapper'),
|
||||
directory,
|
||||
shouldCopyFile: (File sourceFile, File destinationFile) {
|
||||
// Don't override the existing files in the project.
|
||||
@@ -114,7 +113,7 @@ class GradleUtils {
|
||||
);
|
||||
// Add the `gradle-wrapper.properties` file if it doesn't exist.
|
||||
final File propertiesFile = directory.childFile(
|
||||
fs.path.join('gradle', 'wrapper', 'gradle-wrapper.properties'));
|
||||
globals.fs.path.join('gradle', 'wrapper', 'gradle-wrapper.properties'));
|
||||
if (!propertiesFile.existsSync()) {
|
||||
final String gradleVersion = getGradleVersionForAndroidPlugin(directory);
|
||||
propertiesFile.writeAsStringSync('''
|
||||
@@ -157,7 +156,7 @@ const int _kExecPermissionMask = 0x49; // a+x
|
||||
bool _hasAllExecutableFlagSet(File executable) {
|
||||
final FileStat stat = executable.statSync();
|
||||
assert(stat.type != FileSystemEntityType.notFound);
|
||||
printTrace('${executable.path} mode: ${stat.mode} ${stat.modeString()}.');
|
||||
globals.printTrace('${executable.path} mode: ${stat.mode} ${stat.modeString()}.');
|
||||
return stat.mode & _kExecPermissionMask == _kExecPermissionMask;
|
||||
}
|
||||
|
||||
@@ -165,14 +164,14 @@ bool _hasAllExecutableFlagSet(File executable) {
|
||||
bool _hasAnyExecutableFlagSet(File executable) {
|
||||
final FileStat stat = executable.statSync();
|
||||
assert(stat.type != FileSystemEntityType.notFound);
|
||||
printTrace('${executable.path} mode: ${stat.mode} ${stat.modeString()}.');
|
||||
globals.printTrace('${executable.path} mode: ${stat.mode} ${stat.modeString()}.');
|
||||
return stat.mode & _kExecPermissionMask != 0;
|
||||
}
|
||||
|
||||
/// Gives execute permission to [executable] if it doesn't have it already.
|
||||
void _giveExecutePermissionIfNeeded(File executable) {
|
||||
if (!_hasAllExecutableFlagSet(executable)) {
|
||||
printTrace('Trying to give execute permission to ${executable.path}.');
|
||||
globals.printTrace('Trying to give execute permission to ${executable.path}.');
|
||||
os.makeExecutable(executable);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user