Unverified Commit e0ec9a06 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] Make ApplicationPackageFactory inject dependencies for Android Builds (#67827)

* [flutter_tools] simplication of application store logic

* maybe return null

* fix install tests

* Clean up imports

* revert windows test

* remove unused import
parent 6cfb86fb
...@@ -575,7 +575,8 @@ class AndroidDevice extends Device { ...@@ -575,7 +575,8 @@ class AndroidDevice extends Device {
); );
// Package has been built, so we can get the updated application ID and // Package has been built, so we can get the updated application ID and
// activity name from the .apk. // activity name from the .apk.
package = await AndroidApk.fromAndroidProject(project.android); package = await ApplicationPackageFactory.instance
.getPackageForPlatform(devicePlatform, buildInfo: debuggingOptions.buildInfo) as AndroidApk;
} }
// There was a failure parsing the android project information. // There was a failure parsing the android project information.
if (package == null) { if (package == null) {
......
...@@ -323,6 +323,7 @@ class AndroidSdk { ...@@ -323,6 +323,7 @@ class AndroidSdk {
sdkLevel: platformVersion, sdkLevel: platformVersion,
platformName: platformName, platformName: platformName,
buildToolsVersion: buildToolsVersion, buildToolsVersion: buildToolsVersion,
fileSystem: globals.fs,
); );
}).where((AndroidSdkVersion version) => version != null).toList(); }).where((AndroidSdkVersion version) => version != null).toList();
...@@ -436,19 +437,29 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> { ...@@ -436,19 +437,29 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
@required this.sdkLevel, @required this.sdkLevel,
@required this.platformName, @required this.platformName,
@required this.buildToolsVersion, @required this.buildToolsVersion,
@required FileSystem fileSystem,
}) : assert(sdkLevel != null), }) : assert(sdkLevel != null),
assert(platformName != null), assert(platformName != null),
assert(buildToolsVersion != null); assert(buildToolsVersion != null),
_fileSystem = fileSystem;
final AndroidSdk sdk; final AndroidSdk sdk;
final int sdkLevel; final int sdkLevel;
final String platformName; final String platformName;
final Version buildToolsVersion; final Version buildToolsVersion;
final FileSystem _fileSystem;
String get buildToolsVersionName => buildToolsVersion.toString(); String get buildToolsVersionName => buildToolsVersion.toString();
String get androidJarPath => getPlatformsPath('android.jar'); String get androidJarPath => getPlatformsPath('android.jar');
/// Return the path to the android application package tool.
///
/// This is used to dump the xml in order to launch built android applications.
///
/// See also:
/// * [AndroidApk.fromApk], which depends on this to determine application identifiers.
String get aaptPath => getBuildToolsPath('aapt'); String get aaptPath => getBuildToolsPath('aapt');
List<String> validateSdkWellFormed() { List<String> validateSdkWellFormed() {
...@@ -464,11 +475,11 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> { ...@@ -464,11 +475,11 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
} }
String getPlatformsPath(String itemName) { String getPlatformsPath(String itemName) {
return globals.fs.path.join(sdk.directory, 'platforms', platformName, itemName); return _fileSystem.path.join(sdk.directory, 'platforms', platformName, itemName);
} }
String getBuildToolsPath(String binaryName) { String getBuildToolsPath(String binaryName) {
return globals.fs.path.join(sdk.directory, 'build-tools', buildToolsVersionName, binaryName); return _fileSystem.path.join(sdk.directory, 'build-tools', buildToolsVersionName, binaryName);
} }
@override @override
...@@ -478,7 +489,7 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> { ...@@ -478,7 +489,7 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
String toString() => '[${sdk.directory}, SDK version $sdkLevel, build-tools $buildToolsVersionName]'; String toString() => '[${sdk.directory}, SDK version $sdkLevel, build-tools $buildToolsVersionName]';
String _exists(String path) { String _exists(String path) {
if (!globals.fs.isFileSync(path)) { if (!_fileSystem.isFileSync(path)) {
return 'Android SDK file not found: $path.'; return 'Android SDK file not found: $path.';
} }
return null; return null;
......
...@@ -88,7 +88,13 @@ Future<T> runInContext<T>( ...@@ -88,7 +88,13 @@ Future<T> runInContext<T>(
androidSdk: globals.androidSdk, androidSdk: globals.androidSdk,
featureFlags: featureFlags, featureFlags: featureFlags,
), ),
ApplicationPackageFactory: () => ApplicationPackageFactory(), ApplicationPackageFactory: () => ApplicationPackageFactory(
userMessages: globals.userMessages,
processManager: globals.processManager,
logger: globals.logger,
fileSystem: globals.fs,
androidSdk: globals.androidSdk,
),
Artifacts: () => CachedArtifacts( Artifacts: () => CachedArtifacts(
fileSystem: globals.fs, fileSystem: globals.fs,
cache: globals.cache, cache: globals.cache,
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:flutter_tools/src/application_package.dart'; import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/install.dart'; import 'package:flutter_tools/src/commands/install.dart';
......
...@@ -10,8 +10,10 @@ import 'package:flutter_tools/src/android/android_sdk.dart'; ...@@ -10,8 +10,10 @@ import 'package:flutter_tools/src/android/android_sdk.dart';
import 'package:flutter_tools/src/application_package.dart'; import 'package:flutter_tools/src/application_package.dart';
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/fuchsia/application_package.dart'; import 'package:flutter_tools/src/fuchsia/application_package.dart';
...@@ -130,67 +132,114 @@ void main() { ...@@ -130,67 +132,114 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse); expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: overrides); }, overrides: overrides);
testUsingContext('returns null when failed to extract manifest', () async { testWithoutContext('returns null when failed to extract manifest', () async {
final AndroidSdkVersion sdkVersion = MockitoAndroidSdkVersion(); final AndroidSdkVersion sdkVersion = MockitoAndroidSdkVersion();
when(sdk.latestVersion).thenReturn(sdkVersion); when(sdk.latestVersion).thenReturn(sdkVersion);
final AndroidApk androidApk = AndroidApk.fromApk(
null,
processManager: fakeProcessManager,
logger: BufferLogger.test(),
userMessages: UserMessages(),
androidSdk: sdk,
);
expect(AndroidApk.fromApk(null), isNull); expect(androidApk, isNull);
expect(fakeProcessManager.hasRemainingExpectations, isFalse); expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: overrides); });
}); });
group('ApkManifestData', () { group('ApkManifestData', () {
testUsingContext('Parses manifest with an Activity that has enabled set to true, action set to android.intent.action.MAIN and category set to android.intent.category.LAUNCHER', () { testWithoutContext('Parses manifest with an Activity that has enabled set to true, action set to android.intent.action.MAIN and category set to android.intent.category.LAUNCHER', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithExplicitEnabledAndMainLauncherActivity); final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithExplicitEnabledAndMainLauncherActivity,
BufferLogger.test(),
);
expect(data, isNotNull); expect(data, isNotNull);
expect(data.packageName, 'io.flutter.examples.hello_world'); expect(data.packageName, 'io.flutter.examples.hello_world');
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity2'); expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity2');
}, overrides: noColorTerminalOverride); });
testWithoutContext('Parses manifest with an Activity that has no value for its enabled field, action set to android.intent.action.MAIN and category set to android.intent.category.LAUNCHER', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithDefaultEnabledAndMainLauncherActivity,
BufferLogger.test(),
);
testUsingContext('Parses manifest with an Activity that has no value for its enabled field, action set to android.intent.action.MAIN and category set to android.intent.category.LAUNCHER', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithDefaultEnabledAndMainLauncherActivity);
expect(data, isNotNull); expect(data, isNotNull);
expect(data.packageName, 'io.flutter.examples.hello_world'); expect(data.packageName, 'io.flutter.examples.hello_world');
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity2'); expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity2');
}, overrides: noColorTerminalOverride); });
testWithoutContext('Parses manifest with a dist namespace', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithDistNamespace,
BufferLogger.test(),
);
testUsingContext('Parses manifest with a dist namespace', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithDistNamespace);
expect(data, isNotNull); expect(data, isNotNull);
expect(data.packageName, 'io.flutter.examples.hello_world'); expect(data.packageName, 'io.flutter.examples.hello_world');
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity'); expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity');
}, overrides: noColorTerminalOverride); });
testWithoutContext('Error when parsing manifest with no Activity that has enabled set to true nor has no value for its enabled field', () {
final BufferLogger logger = BufferLogger.test();
final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithNoEnabledActivity,
logger,
);
testUsingContext('Error when parsing manifest with no Activity that has enabled set to true nor has no value for its enabled field', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithNoEnabledActivity);
expect(data, isNull); expect(data, isNull);
expect( expect(
testLogger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n'); logger.errorText,
}, overrides: noColorTerminalOverride); 'Error running io.flutter.examples.hello_world. Default activity not found\n',
);
});
testWithoutContext('Error when parsing manifest with no Activity that has action set to android.intent.action.MAIN', () {
final BufferLogger logger = BufferLogger.test();
final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithNoMainActivity,
logger,
);
testUsingContext('Error when parsing manifest with no Activity that has action set to android.intent.action.MAIN', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithNoMainActivity);
expect(data, isNull); expect(data, isNull);
expect( expect(
testLogger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n'); logger.errorText,
}, overrides: noColorTerminalOverride); 'Error running io.flutter.examples.hello_world. Default activity not found\n',
);
});
testWithoutContext('Error when parsing manifest with no Activity that has category set to android.intent.category.LAUNCHER', () {
final BufferLogger logger = BufferLogger.test();
final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithNoLauncherActivity,
logger,
);
testUsingContext('Error when parsing manifest with no Activity that has category set to android.intent.category.LAUNCHER', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithNoLauncherActivity);
expect(data, isNull); expect(data, isNull);
expect( expect(
testLogger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n'); logger.errorText,
}, overrides: noColorTerminalOverride); 'Error running io.flutter.examples.hello_world. Default activity not found\n',
);
});
testWithoutContext('Parsing manifest with Activity that has multiple category, android.intent.category.LAUNCHER and android.intent.category.DEFAULT', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithLauncherAndDefaultActivity,
BufferLogger.test(),
);
testUsingContext('Parsing manifest with Activity that has multiple category, android.intent.category.LAUNCHER and android.intent.category.DEFAULT', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithLauncherAndDefaultActivity);
expect(data, isNotNull); expect(data, isNotNull);
expect(data.packageName, 'io.flutter.examples.hello_world'); expect(data.packageName, 'io.flutter.examples.hello_world');
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity'); expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity');
}, overrides: noColorTerminalOverride); });
testUsingContext('Parses manifest with missing application tag', () async { testWithoutContext('Parses manifest with missing application tag', () async {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithoutApplication); final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithoutApplication,
BufferLogger.test(),
);
expect(data, isNull); expect(data, isNull);
}); });
......
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