Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_tools] cache adb path #76650

Merged
merged 1 commit into from Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/flutter_tools/lib/src/android/android_sdk.dart
Expand Up @@ -167,7 +167,8 @@ class AndroidSdk {

AndroidSdkVersion get latestVersion => _latestVersion;

String get adbPath => getPlatformToolsPath(globals.platform.isWindows ? 'adb.exe' : 'adb');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nice thing about this approach is technically the user could still install it after the daemon starts up too.

String get adbPath => _adbPath ??= getPlatformToolsPath(globals.platform.isWindows ? 'adb.exe' : 'adb');
String _adbPath;

String get emulatorPath => getEmulatorPath();

Expand Down
Expand Up @@ -83,6 +83,27 @@ void main() {
Config: () => config,
});

testUsingContext('Caches adb location after first access', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);

final AndroidSdk sdk = AndroidSdk.locateAndroidSdk();
final File adbFile = fileSystem.file(
fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'adb.exe')
)..createSync(recursive: true);

expect(sdk.adbPath, fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'adb.exe'));

adbFile.deleteSync(recursive: true);

expect(sdk.adbPath, fileSystem.path.join(sdk.directory.path, 'cmdline-tools', 'adb.exe'));
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'windows'),
Config: () => config,
});

testUsingContext('returns sdkmanager.bat path under cmdline tools for windows', () {
sdkDir = MockAndroidSdk.createSdkDirectory();
config.setValue('android-sdk', sdkDir.path);
Expand Down