mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Log flags in build apk and appbundle (#39457)
This commit is contained in:
parent
2dbf0106d8
commit
6266d5f35d
@ -1,62 +0,0 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../build_info.dart';
|
||||
import '../project.dart';
|
||||
|
||||
import 'android_sdk.dart';
|
||||
import 'gradle.dart';
|
||||
|
||||
/// Provides a method to build a module or plugin as AAR.
|
||||
abstract class AarBuilder {
|
||||
/// Builds the AAR artifacts.
|
||||
Future<void> build({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
@required String outputDir,
|
||||
});
|
||||
}
|
||||
|
||||
/// Default implementation of [AarBuilder].
|
||||
class AarBuilderImpl extends AarBuilder {
|
||||
AarBuilderImpl();
|
||||
|
||||
/// Builds the AAR and POM files for the current Flutter module or plugin.
|
||||
@override
|
||||
Future<void> build({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
@required String outputDir,
|
||||
}) async {
|
||||
if (!project.android.isUsingGradle) {
|
||||
throwToolExit(
|
||||
'The build process for Android has changed, and the current project configuration\n'
|
||||
'is no longer valid. Please consult\n\n'
|
||||
' https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle\n\n'
|
||||
'for details on how to upgrade the project.'
|
||||
);
|
||||
}
|
||||
if (!project.manifest.isModule && !project.manifest.isPlugin) {
|
||||
throwToolExit('AARs can only be built for plugin or module projects.');
|
||||
}
|
||||
// Validate that we can find an Android SDK.
|
||||
if (androidSdk == null) {
|
||||
throwToolExit('No Android SDK found. Try setting the `ANDROID_SDK_ROOT` environment variable.');
|
||||
}
|
||||
await buildGradleAar(
|
||||
project: project,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
target: target,
|
||||
outputDir: outputDir,
|
||||
);
|
||||
androidSdk.reinitialize();
|
||||
}
|
||||
}
|
||||
169
packages/flutter_tools/lib/src/android/android_builder.dart
Normal file
169
packages/flutter_tools/lib/src/android/android_builder.dart
Normal file
@ -0,0 +1,169 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../base/context.dart';
|
||||
import '../build_info.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
|
||||
import 'android_sdk.dart';
|
||||
import 'gradle.dart';
|
||||
|
||||
/// The builder in the current context.
|
||||
AndroidBuilder get androidBuilder => context.get<AndroidBuilder>() ?? _AndroidBuilderImpl();
|
||||
|
||||
/// Provides the methods to build Android artifacts.
|
||||
abstract class AndroidBuilder {
|
||||
/// Builds an AAR artifact.
|
||||
Future<void> buildAar({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
@required String outputDir,
|
||||
});
|
||||
|
||||
/// Builds an APK artifact.
|
||||
Future<void> buildApk({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
});
|
||||
|
||||
/// Builds an App Bundle artifact.
|
||||
Future<void> buildAab({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
});
|
||||
}
|
||||
|
||||
/// Default implementation of [AarBuilder].
|
||||
class _AndroidBuilderImpl extends AndroidBuilder {
|
||||
_AndroidBuilderImpl();
|
||||
|
||||
/// Builds the AAR and POM files for the current Flutter module or plugin.
|
||||
@override
|
||||
Future<void> buildAar({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
@required String outputDir,
|
||||
}) async {
|
||||
if (!project.android.isUsingGradle) {
|
||||
throwToolExit(
|
||||
'The build process for Android has changed, and the current project configuration '
|
||||
'is no longer valid. Please consult\n\n'
|
||||
' https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle\n\n'
|
||||
'for details on how to upgrade the project.'
|
||||
);
|
||||
}
|
||||
if (!project.manifest.isModule && !project.manifest.isPlugin) {
|
||||
throwToolExit('AARs can only be built for plugin or module projects.');
|
||||
}
|
||||
// Validate that we can find an Android SDK.
|
||||
if (androidSdk == null) {
|
||||
throwToolExit('No Android SDK found. Try setting the `ANDROID_SDK_ROOT` environment variable.');
|
||||
}
|
||||
await buildGradleAar(
|
||||
project: project,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
target: target,
|
||||
outputDir: outputDir,
|
||||
);
|
||||
androidSdk.reinitialize();
|
||||
}
|
||||
|
||||
/// Builds the APK.
|
||||
@override
|
||||
Future<void> buildApk({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
}) async {
|
||||
if (!project.android.isUsingGradle) {
|
||||
throwToolExit(
|
||||
'The build process for Android has changed, and the current project configuration '
|
||||
'is no longer valid. Please consult\n\n'
|
||||
' https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle\n\n'
|
||||
'for details on how to upgrade the project.'
|
||||
);
|
||||
}
|
||||
// Validate that we can find an android sdk.
|
||||
if (androidSdk == null) {
|
||||
throwToolExit('No Android SDK found. Try setting the ANDROID_SDK_ROOT environment variable.');
|
||||
}
|
||||
await buildGradleProject(
|
||||
project: project,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
target: target,
|
||||
isBuildingBundle: false,
|
||||
);
|
||||
androidSdk.reinitialize();
|
||||
}
|
||||
|
||||
/// Builds the App Bundle.
|
||||
@override
|
||||
Future<void> buildAab({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
}) async {
|
||||
if (!project.android.isUsingGradle) {
|
||||
throwToolExit(
|
||||
'The build process for Android has changed, and the current project configuration '
|
||||
'is no longer valid. Please consult\n\n'
|
||||
'https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle\n\n'
|
||||
'for details on how to upgrade the project.'
|
||||
);
|
||||
}
|
||||
// Validate that we can find an android sdk.
|
||||
if (androidSdk == null) {
|
||||
throwToolExit('No Android SDK found. Try setting the ANDROID_HOME environment variable.');
|
||||
}
|
||||
final List<String> validationResult = androidSdk.validateSdkWellFormed();
|
||||
if (validationResult.isNotEmpty) {
|
||||
for (String message in validationResult) {
|
||||
printError(message, wrap: false);
|
||||
}
|
||||
throwToolExit('Try re-installing or updating your Android SDK.');
|
||||
}
|
||||
return buildGradleProject(
|
||||
project: project,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
target: target,
|
||||
isBuildingBundle: true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A fake implementation of [AndroidBuilder].
|
||||
@visibleForTesting
|
||||
class FakeAndroidBuilder implements AndroidBuilder {
|
||||
@override
|
||||
Future<void> buildAar({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
@required String outputDir,
|
||||
}) async {}
|
||||
|
||||
@override
|
||||
Future<void> buildApk({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
}) async {}
|
||||
|
||||
@override
|
||||
Future<void> buildAab({
|
||||
@required FlutterProject project,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
@required String target,
|
||||
}) async {}
|
||||
}
|
||||
@ -6,9 +6,9 @@ import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../android/android_builder.dart';
|
||||
import '../android/android_sdk.dart';
|
||||
import '../android/android_workflow.dart';
|
||||
import '../android/apk.dart';
|
||||
import '../application_package.dart';
|
||||
import '../base/common.dart' show throwToolExit;
|
||||
import '../base/file_system.dart';
|
||||
@ -482,7 +482,7 @@ class AndroidDevice extends Device {
|
||||
if (!prebuiltApplication || androidSdk.licensesAvailable && androidSdk.latestVersion == null) {
|
||||
printTrace('Building APK');
|
||||
final FlutterProject project = FlutterProject.current();
|
||||
await buildApk(
|
||||
await androidBuilder.buildApk(
|
||||
project: project,
|
||||
target: mainPath,
|
||||
androidBuildInfo: AndroidBuildInfo(debuggingOptions.buildInfo,
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../build_info.dart';
|
||||
import '../project.dart';
|
||||
|
||||
import 'android_sdk.dart';
|
||||
import 'gradle.dart';
|
||||
|
||||
Future<void> buildApk({
|
||||
@required FlutterProject project,
|
||||
@required String target,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
}) async {
|
||||
if (!project.android.isUsingGradle) {
|
||||
throwToolExit(
|
||||
'The build process for Android has changed, and the current project configuration\n'
|
||||
'is no longer valid. Please consult\n\n'
|
||||
' https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle\n\n'
|
||||
'for details on how to upgrade the project.'
|
||||
);
|
||||
}
|
||||
|
||||
// Validate that we can find an android sdk.
|
||||
if (androidSdk == null)
|
||||
throwToolExit('No Android SDK found. Try setting the ANDROID_SDK_ROOT environment variable.');
|
||||
|
||||
await buildGradleProject(
|
||||
project: project,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
target: target,
|
||||
isBuildingBundle: false,
|
||||
);
|
||||
androidSdk.reinitialize();
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../base/common.dart';
|
||||
import '../build_info.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
|
||||
import 'android_sdk.dart';
|
||||
import 'gradle.dart';
|
||||
|
||||
Future<void> buildAppBundle({
|
||||
@required FlutterProject project,
|
||||
@required String target,
|
||||
@required AndroidBuildInfo androidBuildInfo,
|
||||
}) async {
|
||||
if (!project.android.isUsingGradle) {
|
||||
throwToolExit(
|
||||
'The build process for Android has changed, and the current project configuration\n'
|
||||
'is no longer valid. Please consult\n\n'
|
||||
'https://github.com/flutter/flutter/wiki/Upgrading-Flutter-projects-to-build-with-gradle\n\n'
|
||||
'for details on how to upgrade the project.'
|
||||
);
|
||||
}
|
||||
|
||||
// Validate that we can find an android sdk.
|
||||
if (androidSdk == null)
|
||||
throwToolExit('No Android SDK found. Try setting the ANDROID_HOME environment variable.');
|
||||
|
||||
final List<String> validationResult = androidSdk.validateSdkWellFormed();
|
||||
if (validationResult.isNotEmpty) {
|
||||
for (String message in validationResult) {
|
||||
printError(message, wrap: false);
|
||||
}
|
||||
throwToolExit('Try re-installing or updating your Android SDK.');
|
||||
}
|
||||
|
||||
return buildGradleProject(
|
||||
project: project,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
target: target,
|
||||
isBuildingBundle: true,
|
||||
);
|
||||
}
|
||||
@ -4,8 +4,7 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../android/aar.dart';
|
||||
import '../base/context.dart';
|
||||
import '../android/android_builder.dart';
|
||||
import '../base/os.dart';
|
||||
import '../build_info.dart';
|
||||
import '../project.dart';
|
||||
@ -13,9 +12,6 @@ import '../reporting/reporting.dart';
|
||||
import '../runner/flutter_command.dart' show DevelopmentArtifact, FlutterCommandResult;
|
||||
import 'build.dart';
|
||||
|
||||
/// The AAR builder in the current context.
|
||||
AarBuilder get aarBuilder => context.get<AarBuilder>() ?? AarBuilderImpl();
|
||||
|
||||
class BuildAarCommand extends BuildSubCommand {
|
||||
BuildAarCommand({bool verboseHelp = false}) {
|
||||
addBuildModeFlags(verboseHelp: verboseHelp);
|
||||
@ -74,7 +70,7 @@ class BuildAarCommand extends BuildSubCommand {
|
||||
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(buildInfo,
|
||||
targetArchs: argResults['target-platform'].map<AndroidArch>(getAndroidArchForName));
|
||||
|
||||
await aarBuilder.build(
|
||||
await androidBuilder.buildAar(
|
||||
project: _getProject(),
|
||||
target: '', // Not needed because this command only builds Android's code.
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
|
||||
@ -4,11 +4,12 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../android/apk.dart';
|
||||
import '../android/android_builder.dart';
|
||||
import '../base/terminal.dart';
|
||||
import '../build_info.dart';
|
||||
import '../globals.dart';
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import '../runner/flutter_command.dart' show DevelopmentArtifact, FlutterCommandResult;
|
||||
import 'build.dart';
|
||||
|
||||
@ -39,18 +40,40 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
@override
|
||||
final String name = 'apk';
|
||||
|
||||
@override
|
||||
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{
|
||||
DevelopmentArtifact.universal,
|
||||
DevelopmentArtifact.android,
|
||||
};
|
||||
|
||||
@override
|
||||
final String description = 'Build an Android APK file from your app.\n\n'
|
||||
'This command can build debug and release versions of your application. \'debug\' builds support '
|
||||
'debugging and a quick development cycle. \'release\' builds don\'t support debugging and are '
|
||||
'suitable for deploying to app stores.';
|
||||
|
||||
@override
|
||||
Future<Map<CustomDimensions, String>> get usageValues async {
|
||||
final Map<CustomDimensions, String> usage = <CustomDimensions, String>{};
|
||||
|
||||
usage[CustomDimensions.commandBuildApkTargetPlatform] =
|
||||
(argResults['target-platform'] as List<String>).join(',');
|
||||
usage[CustomDimensions.commandBuildApkSplitPerAbi] =
|
||||
argResults['split-per-abi'].toString();
|
||||
|
||||
if (argResults['release']) {
|
||||
usage[CustomDimensions.commandBuildApkBuildMode] = 'release';
|
||||
} else if (argResults['debug']) {
|
||||
usage[CustomDimensions.commandBuildApkBuildMode] = 'debug';
|
||||
} else if (argResults['profile']) {
|
||||
usage[CustomDimensions.commandBuildApkBuildMode] = 'profile';
|
||||
} else {
|
||||
// The build defaults to release.
|
||||
usage[CustomDimensions.commandBuildApkBuildMode] = 'release';
|
||||
}
|
||||
return usage;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => const <DevelopmentArtifact>{
|
||||
DevelopmentArtifact.universal,
|
||||
DevelopmentArtifact.android,
|
||||
};
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
final BuildInfo buildInfo = getBuildInfo();
|
||||
@ -76,7 +99,7 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
'--split-per-abi', indent: 8);
|
||||
printStatus('Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split',indent: 8);
|
||||
}
|
||||
await buildApk(
|
||||
await androidBuilder.buildApk(
|
||||
project: FlutterProject.current(),
|
||||
target: targetFile,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
|
||||
@ -4,9 +4,10 @@
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import '../android/app_bundle.dart';
|
||||
import '../android/android_builder.dart';
|
||||
import '../build_info.dart';
|
||||
import '../project.dart';
|
||||
import '../reporting/reporting.dart';
|
||||
import '../runner/flutter_command.dart' show FlutterCommandResult;
|
||||
import 'build.dart';
|
||||
|
||||
@ -39,12 +40,32 @@ class BuildAppBundleCommand extends BuildSubCommand {
|
||||
'debugging and a quick development cycle. \'release\' builds don\'t support debugging and are '
|
||||
'suitable for deploying to app stores. \n app bundle improves your app size';
|
||||
|
||||
@override
|
||||
Future<Map<CustomDimensions, String>> get usageValues async {
|
||||
final Map<CustomDimensions, String> usage = <CustomDimensions, String>{};
|
||||
|
||||
usage[CustomDimensions.commandBuildAppBundleTargetPlatform] =
|
||||
(argResults['target-platform'] as List<String>).join(',');
|
||||
|
||||
if (argResults['release']) {
|
||||
usage[CustomDimensions.commandBuildAppBundleBuildMode] = 'release';
|
||||
} else if (argResults['debug']) {
|
||||
usage[CustomDimensions.commandBuildAppBundleBuildMode] = 'debug';
|
||||
} else if (argResults['profile']) {
|
||||
usage[CustomDimensions.commandBuildAppBundleBuildMode] = 'profile';
|
||||
} else {
|
||||
// The build defaults to release.
|
||||
usage[CustomDimensions.commandBuildAppBundleBuildMode] = 'release';
|
||||
}
|
||||
return usage;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
final AndroidBuildInfo androidBuildInfo = AndroidBuildInfo(getBuildInfo(),
|
||||
targetArchs: argResults['target-platform'].map<AndroidArch>(getAndroidArchForName)
|
||||
);
|
||||
await buildAppBundle(
|
||||
await androidBuilder.buildAab(
|
||||
project: FlutterProject.current(),
|
||||
target: targetFile,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
|
||||
@ -48,6 +48,11 @@ enum CustomDimensions {
|
||||
commandBuildAarProjectType, // cd35
|
||||
buildEventCommand, // cd36
|
||||
buildEventSettings, // cd37
|
||||
commandBuildApkTargetPlatform, // cd38
|
||||
commandBuildApkBuildMode, // cd39
|
||||
commandBuildApkSplitPerAbi, // cd40
|
||||
commandBuildAppBundleTargetPlatform, // cd41
|
||||
commandBuildAppBundleBuildMode, // cd42
|
||||
}
|
||||
|
||||
String cdKey(CustomDimensions cd) => 'cd${cd.index + 1}';
|
||||
|
||||
@ -3,12 +3,11 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/android/aar.dart';
|
||||
import 'package:flutter_tools/src/android/android_builder.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build_aar.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
@ -18,16 +17,9 @@ void main() {
|
||||
|
||||
group('getUsage', () {
|
||||
Directory tempDir;
|
||||
AarBuilder mockAarBuilder;
|
||||
|
||||
setUp(() {
|
||||
tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
|
||||
mockAarBuilder = MockAarBuilder();
|
||||
when(mockAarBuilder.build(
|
||||
project: anyNamed('project'),
|
||||
androidBuildInfo: anyNamed('androidBuildInfo'),
|
||||
target: anyNamed('target'),
|
||||
outputDir: anyNamed('outputDir'))).thenAnswer((_) => Future<void>.value());
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
@ -54,7 +46,7 @@ void main() {
|
||||
containsPair(CustomDimensions.commandBuildAarProjectType, 'module'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AarBuilder: () => mockAarBuilder,
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
|
||||
testUsingContext('indicate that project is a plugin', () async {
|
||||
@ -66,7 +58,7 @@ void main() {
|
||||
containsPair(CustomDimensions.commandBuildAarProjectType, 'plugin'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AarBuilder: () => mockAarBuilder,
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
|
||||
testUsingContext('indicate the target platform', () async {
|
||||
@ -79,9 +71,7 @@ void main() {
|
||||
containsPair(CustomDimensions.commandBuildAarTargetPlatform, 'android-arm'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AarBuilder: () => mockAarBuilder,
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
});
|
||||
}
|
||||
|
||||
class MockAarBuilder extends Mock implements AarBuilder {}
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/android/android_builder.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build_apk.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
void main() {
|
||||
Cache.disableLocking();
|
||||
|
||||
group('getUsage', () {
|
||||
Directory tempDir;
|
||||
|
||||
setUp(() {
|
||||
tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
Future<BuildApkCommand> runCommandIn(String target, { List<String> arguments }) async {
|
||||
final BuildApkCommand command = BuildApkCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
await runner.run(<String>[
|
||||
'apk',
|
||||
...?arguments,
|
||||
fs.path.join(target, 'lib', 'main.dart'),
|
||||
]);
|
||||
return command;
|
||||
}
|
||||
|
||||
testUsingContext('indicate the default target platforms', () async {
|
||||
final String projectPath = await createProject(tempDir,
|
||||
arguments: <String>['--no-pub', '--template=app']);
|
||||
final BuildApkCommand command = await runCommandIn(projectPath);
|
||||
|
||||
expect(await command.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildApkTargetPlatform, 'android-arm,android-arm64'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
|
||||
testUsingContext('split per abi', () async {
|
||||
final String projectPath = await createProject(tempDir,
|
||||
arguments: <String>['--no-pub', '--template=app']);
|
||||
|
||||
final BuildApkCommand commandWithFlag = await runCommandIn(projectPath,
|
||||
arguments: <String>['--split-per-abi']);
|
||||
expect(await commandWithFlag.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildApkSplitPerAbi, 'true'));
|
||||
|
||||
final BuildApkCommand commandWithoutFlag = await runCommandIn(projectPath);
|
||||
expect(await commandWithoutFlag.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildApkSplitPerAbi, 'false'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
|
||||
testUsingContext('build type', () async {
|
||||
final String projectPath = await createProject(tempDir,
|
||||
arguments: <String>['--no-pub', '--template=app']);
|
||||
|
||||
final BuildApkCommand commandDefault = await runCommandIn(projectPath);
|
||||
expect(await commandDefault.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildApkBuildMode, 'release'));
|
||||
|
||||
final BuildApkCommand commandInRelease = await runCommandIn(projectPath,
|
||||
arguments: <String>['--release']);
|
||||
expect(await commandInRelease.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildApkBuildMode, 'release'));
|
||||
|
||||
final BuildApkCommand commandInDebug = await runCommandIn(projectPath,
|
||||
arguments: <String>['--debug']);
|
||||
expect(await commandInDebug.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildApkBuildMode, 'debug'));
|
||||
|
||||
final BuildApkCommand commandInProfile = await runCommandIn(projectPath,
|
||||
arguments: <String>['--profile']);
|
||||
expect(await commandInProfile.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildApkBuildMode, 'profile'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/android/android_builder.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/build_appbundle.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
|
||||
void main() {
|
||||
Cache.disableLocking();
|
||||
|
||||
group('getUsage', () {
|
||||
Directory tempDir;
|
||||
|
||||
setUp(() {
|
||||
tempDir = fs.systemTempDirectory.createTempSync('flutter_tools_packages_test.');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
tryToDelete(tempDir);
|
||||
});
|
||||
|
||||
Future<BuildAppBundleCommand> runCommandIn(String target, { List<String> arguments }) async {
|
||||
final BuildAppBundleCommand command = BuildAppBundleCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
await runner.run(<String>[
|
||||
'appbundle',
|
||||
...?arguments,
|
||||
fs.path.join(target, 'lib', 'main.dart'),
|
||||
]);
|
||||
return command;
|
||||
}
|
||||
|
||||
testUsingContext('indicate the default target platforms', () async {
|
||||
final String projectPath = await createProject(tempDir,
|
||||
arguments: <String>['--no-pub', '--template=app']);
|
||||
final BuildAppBundleCommand command = await runCommandIn(projectPath);
|
||||
|
||||
expect(await command.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildAppBundleTargetPlatform, 'android-arm,android-arm64'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
|
||||
testUsingContext('build type', () async {
|
||||
final String projectPath = await createProject(tempDir,
|
||||
arguments: <String>['--no-pub', '--template=app']);
|
||||
|
||||
final BuildAppBundleCommand commandDefault = await runCommandIn(projectPath);
|
||||
expect(await commandDefault.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildAppBundleBuildMode, 'release'));
|
||||
|
||||
final BuildAppBundleCommand commandInRelease = await runCommandIn(projectPath,
|
||||
arguments: <String>['--release']);
|
||||
expect(await commandInRelease.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildAppBundleBuildMode, 'release'));
|
||||
|
||||
final BuildAppBundleCommand commandInDebug = await runCommandIn(projectPath,
|
||||
arguments: <String>['--debug']);
|
||||
expect(await commandInDebug.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildAppBundleBuildMode, 'debug'));
|
||||
|
||||
final BuildAppBundleCommand commandInProfile = await runCommandIn(projectPath,
|
||||
arguments: <String>['--profile']);
|
||||
expect(await commandInProfile.usageValues,
|
||||
containsPair(CustomDimensions.commandBuildAppBundleBuildMode, 'profile'));
|
||||
|
||||
}, overrides: <Type, Generator>{
|
||||
AndroidBuilder: () => FakeAndroidBuilder(),
|
||||
}, timeout: allowForCreateFlutterProject);
|
||||
});
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user