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 {
);
// Package has been built, so we can get the updated application ID and
// 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.
if (package == null) {
......
......@@ -323,6 +323,7 @@ class AndroidSdk {
sdkLevel: platformVersion,
platformName: platformName,
buildToolsVersion: buildToolsVersion,
fileSystem: globals.fs,
);
}).where((AndroidSdkVersion version) => version != null).toList();
......@@ -436,19 +437,29 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
@required this.sdkLevel,
@required this.platformName,
@required this.buildToolsVersion,
@required FileSystem fileSystem,
}) : assert(sdkLevel != null),
assert(platformName != null),
assert(buildToolsVersion != null);
assert(buildToolsVersion != null),
_fileSystem = fileSystem;
final AndroidSdk sdk;
final int sdkLevel;
final String platformName;
final Version buildToolsVersion;
final FileSystem _fileSystem;
String get buildToolsVersionName => buildToolsVersion.toString();
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');
List<String> validateSdkWellFormed() {
......@@ -464,11 +475,11 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
}
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) {
return globals.fs.path.join(sdk.directory, 'build-tools', buildToolsVersionName, binaryName);
return _fileSystem.path.join(sdk.directory, 'build-tools', buildToolsVersionName, binaryName);
}
@override
......@@ -478,7 +489,7 @@ class AndroidSdkVersion implements Comparable<AndroidSdkVersion> {
String toString() => '[${sdk.directory}, SDK version $sdkLevel, build-tools $buildToolsVersionName]';
String _exists(String path) {
if (!globals.fs.isFileSync(path)) {
if (!_fileSystem.isFileSync(path)) {
return 'Android SDK file not found: $path.';
}
return null;
......
......@@ -88,7 +88,13 @@ Future<T> runInContext<T>(
androidSdk: globals.androidSdk,
featureFlags: featureFlags,
),
ApplicationPackageFactory: () => ApplicationPackageFactory(),
ApplicationPackageFactory: () => ApplicationPackageFactory(
userMessages: globals.userMessages,
processManager: globals.processManager,
logger: globals.logger,
fileSystem: globals.fs,
androidSdk: globals.androidSdk,
),
Artifacts: () => CachedArtifacts(
fileSystem: globals.fs,
cache: globals.cache,
......
......@@ -4,6 +4,7 @@
import 'package:file/file.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/cache.dart';
import 'package:flutter_tools/src/commands/install.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/base/context.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/platform.dart';
import 'package:flutter_tools/src/base/user_messages.dart';
import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/fuchsia/application_package.dart';
......@@ -130,67 +132,114 @@ void main() {
expect(fakeProcessManager.hasRemainingExpectations, isFalse);
}, overrides: overrides);
testUsingContext('returns null when failed to extract manifest', () async {
testWithoutContext('returns null when failed to extract manifest', () async {
final AndroidSdkVersion sdkVersion = MockitoAndroidSdkVersion();
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);
}, overrides: overrides);
});
});
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', () {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithExplicitEnabledAndMainLauncherActivity);
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,
BufferLogger.test(),
);
expect(data, isNotNull);
expect(data.packageName, 'io.flutter.examples.hello_world');
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.packageName, 'io.flutter.examples.hello_world');
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.packageName, 'io.flutter.examples.hello_world');
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(
testLogger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n');
}, overrides: noColorTerminalOverride);
logger.errorText,
'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(
testLogger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n');
}, overrides: noColorTerminalOverride);
logger.errorText,
'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(
testLogger.errorText, 'Error running io.flutter.examples.hello_world. Default activity not found\n');
}, overrides: noColorTerminalOverride);
logger.errorText,
'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.packageName, 'io.flutter.examples.hello_world');
expect(data.launchableActivityName, 'io.flutter.examples.hello_world.MainActivity');
}, overrides: noColorTerminalOverride);
});
testUsingContext('Parses manifest with missing application tag', () async {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(_aaptDataWithoutApplication);
testWithoutContext('Parses manifest with missing application tag', () async {
final ApkManifestData data = ApkManifestData.parseFromXmlDump(
_aaptDataWithoutApplication,
BufferLogger.test(),
);
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