Unverified Commit fe9e8191 authored by Reid Baker's avatar Reid Baker Committed by GitHub

Create configOnly flag for android (#121904)

Create configOnly flag for android
parent a9700ffd
...@@ -27,6 +27,7 @@ abstract class AndroidBuilder { ...@@ -27,6 +27,7 @@ abstract class AndroidBuilder {
required FlutterProject project, required FlutterProject project,
required AndroidBuildInfo androidBuildInfo, required AndroidBuildInfo androidBuildInfo,
required String target, required String target,
bool configOnly = false,
}); });
/// Builds an App Bundle artifact. /// Builds an App Bundle artifact.
...@@ -36,5 +37,6 @@ abstract class AndroidBuilder { ...@@ -36,5 +37,6 @@ abstract class AndroidBuilder {
required String target, required String target,
bool validateDeferredComponents = true, bool validateDeferredComponents = true,
bool deferredComponentsEnabled = false, bool deferredComponentsEnabled = false,
bool configOnly = false,
}); });
} }
...@@ -181,6 +181,7 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -181,6 +181,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
required FlutterProject project, required FlutterProject project,
required AndroidBuildInfo androidBuildInfo, required AndroidBuildInfo androidBuildInfo,
required String target, required String target,
bool configOnly = false,
}) async { }) async {
await buildGradleApp( await buildGradleApp(
project: project, project: project,
...@@ -188,6 +189,7 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -188,6 +189,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
target: target, target: target,
isBuildingBundle: false, isBuildingBundle: false,
localGradleErrors: gradleErrors, localGradleErrors: gradleErrors,
configOnly: configOnly,
); );
} }
...@@ -199,6 +201,7 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -199,6 +201,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
required String target, required String target,
bool validateDeferredComponents = true, bool validateDeferredComponents = true,
bool deferredComponentsEnabled = false, bool deferredComponentsEnabled = false,
bool configOnly = false,
}) async { }) async {
await buildGradleApp( await buildGradleApp(
project: project, project: project,
...@@ -208,6 +211,7 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -208,6 +211,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
localGradleErrors: gradleErrors, localGradleErrors: gradleErrors,
validateDeferredComponents: validateDeferredComponents, validateDeferredComponents: validateDeferredComponents,
deferredComponentsEnabled: deferredComponentsEnabled, deferredComponentsEnabled: deferredComponentsEnabled,
configOnly: configOnly,
); );
} }
...@@ -225,6 +229,7 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -225,6 +229,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
required String target, required String target,
required bool isBuildingBundle, required bool isBuildingBundle,
required List<GradleHandledError> localGradleErrors, required List<GradleHandledError> localGradleErrors,
required bool configOnly,
bool validateDeferredComponents = true, bool validateDeferredComponents = true,
bool deferredComponentsEnabled = false, bool deferredComponentsEnabled = false,
int retry = 0, int retry = 0,
...@@ -249,8 +254,22 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -249,8 +254,22 @@ class AndroidGradleBuilder implements AndroidBuilder {
} }
// The default Gradle script reads the version name and number // The default Gradle script reads the version name and number
// from the local.properties file. // from the local.properties file.
updateLocalProperties(project: project, buildInfo: androidBuildInfo.buildInfo); updateLocalProperties(
project: project, buildInfo: androidBuildInfo.buildInfo);
final List<String> command = <String>[
// This does more than get gradlewrapper. It creates the file, ensures it
// exists and verifies the file is executable.
_gradleUtils.getExecutable(project),
];
// All automatically created files should exist.
if (configOnly) {
_logger.printStatus('Config complete.');
return;
}
// Assembly work starts here.
final BuildInfo buildInfo = androidBuildInfo.buildInfo; final BuildInfo buildInfo = androidBuildInfo.buildInfo;
final String assembleTask = isBuildingBundle final String assembleTask = isBuildingBundle
? getBundleTaskFor(buildInfo) ? getBundleTaskFor(buildInfo)
...@@ -260,9 +279,6 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -260,9 +279,6 @@ class AndroidGradleBuilder implements AndroidBuilder {
"Running Gradle task '$assembleTask'...", "Running Gradle task '$assembleTask'...",
); );
final List<String> command = <String>[
_gradleUtils.getExecutable(project),
];
if (_logger.isVerbose) { if (_logger.isVerbose) {
command.add('--full-stacktrace'); command.add('--full-stacktrace');
command.add('--info'); command.add('--info');
...@@ -428,6 +444,7 @@ class AndroidGradleBuilder implements AndroidBuilder { ...@@ -428,6 +444,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
localGradleErrors: localGradleErrors, localGradleErrors: localGradleErrors,
retry: retry, retry: retry,
maxRetries: maxRetries, maxRetries: maxRetries,
configOnly: configOnly,
); );
final String successEventLabel = 'gradle-${detectedGradleError!.eventLabel}-success'; final String successEventLabel = 'gradle-${detectedGradleError!.eventLabel}-success';
BuildEvent(successEventLabel, type: 'gradle', flutterUsage: _usage).send(); BuildEvent(successEventLabel, type: 'gradle', flutterUsage: _usage).send();
......
...@@ -43,6 +43,9 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -43,6 +43,9 @@ class BuildApkCommand extends BuildSubCommand {
help: 'Whether to split the APKs per ABIs. ' help: 'Whether to split the APKs per ABIs. '
'To learn more, see: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split', 'To learn more, see: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split',
) )
..addFlag('config-only',
help: 'Generate build files used by flutter but '
'do not build any artifacts.')
..addMultiOption('target-platform', ..addMultiOption('target-platform',
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'], defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'], allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'],
...@@ -57,6 +60,8 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -57,6 +60,8 @@ class BuildApkCommand extends BuildSubCommand {
@override @override
DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit; DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
bool get configOnly => boolArg('config-only') ?? false;
@override @override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{ Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
DevelopmentArtifact.androidGenSnapshot, DevelopmentArtifact.androidGenSnapshot,
...@@ -112,6 +117,7 @@ class BuildApkCommand extends BuildSubCommand { ...@@ -112,6 +117,7 @@ class BuildApkCommand extends BuildSubCommand {
project: FlutterProject.current(), project: FlutterProject.current(),
target: targetFile, target: targetFile,
androidBuildInfo: androidBuildInfo, androidBuildInfo: androidBuildInfo,
configOnly: configOnly,
); );
return FlutterCommandResult.success(); return FlutterCommandResult.success();
} }
......
...@@ -92,6 +92,7 @@ void main() { ...@@ -92,6 +92,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: <GradleHandledError>[ localGradleErrors: <GradleHandledError>[
GradleHandledError( GradleHandledError(
test: (String line) { test: (String line) {
...@@ -187,6 +188,7 @@ void main() { ...@@ -187,6 +188,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: <GradleHandledError>[], localGradleErrors: <GradleHandledError>[],
); );
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
...@@ -256,6 +258,7 @@ void main() { ...@@ -256,6 +258,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: <GradleHandledError>[ localGradleErrors: <GradleHandledError>[
GradleHandledError( GradleHandledError(
test: (String line) { test: (String line) {
...@@ -350,6 +353,7 @@ void main() { ...@@ -350,6 +353,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: <GradleHandledError>[ localGradleErrors: <GradleHandledError>[
GradleHandledError( GradleHandledError(
test: (String line) { test: (String line) {
...@@ -441,6 +445,7 @@ void main() { ...@@ -441,6 +445,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
}, throwsProcessException()); }, throwsProcessException());
...@@ -520,6 +525,7 @@ void main() { ...@@ -520,6 +525,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: <GradleHandledError>[ localGradleErrors: <GradleHandledError>[
GradleHandledError( GradleHandledError(
test: (String line) { test: (String line) {
...@@ -636,6 +642,7 @@ void main() { ...@@ -636,6 +642,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: <GradleHandledError>[], localGradleErrors: <GradleHandledError>[],
); );
...@@ -704,6 +711,7 @@ void main() { ...@@ -704,6 +711,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
...@@ -963,6 +971,7 @@ void main() { ...@@ -963,6 +971,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
}, throwsToolExit()); }, throwsToolExit());
...@@ -1039,6 +1048,7 @@ void main() { ...@@ -1039,6 +1048,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
}, throwsToolExit()); }, throwsToolExit());
...@@ -1115,6 +1125,7 @@ void main() { ...@@ -1115,6 +1125,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
}, throwsToolExit()); }, throwsToolExit());
...@@ -1192,6 +1203,7 @@ void main() { ...@@ -1192,6 +1203,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
}, throwsToolExit()); }, throwsToolExit());
...@@ -1250,6 +1262,7 @@ void main() { ...@@ -1250,6 +1262,7 @@ void main() {
), ),
target: 'lib/main.dart', target: 'lib/main.dart',
isBuildingBundle: false, isBuildingBundle: false,
configOnly: false,
localGradleErrors: const <GradleHandledError>[], localGradleErrors: const <GradleHandledError>[],
); );
}, throwsToolExit()); }, throwsToolExit());
......
// Copyright 2014 The Flutter 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:file_testing/file_testing.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import '../src/common.dart';
import 'test_utils.dart';
// Test that configOnly creates the gradlew file and does not assemble and app.
void main() {
late Directory tempDir;
late String flutterBin;
late Directory exampleAppDir;
setUp(() async {
tempDir = createResolvedTempDirectorySync('flutter_build_test.');
flutterBin = fileSystem.path.join(
getFlutterRoot(),
'bin',
'flutter',
);
exampleAppDir = tempDir.childDirectory('bbb').childDirectory('example');
processManager.runSync(<String>[
flutterBin,
...getLocalEngineArguments(),
'create',
'--template=plugin',
'--platforms=android',
'bbb',
], workingDirectory: tempDir.path);
});
tearDown(() async {
tryToDelete(tempDir);
});
test(
'flutter build apk --config-only should create gradlew and not assemble',
() async {
final File gradleFile = fileSystem
.directory(exampleAppDir)
.childDirectory('android')
.childFile(platform.isWindows ? 'gradlew.bat' : 'gradlew');
// Ensure file is gone prior to configOnly running.
await gradleFile.delete();
final ProcessResult result = processManager.runSync(<String>[
flutterBin,
...getLocalEngineArguments(),
'build',
'apk',
'--target-platform=android-arm',
'--config-only',
], workingDirectory: exampleAppDir.path);
expect(gradleFile, exists);
expect(result.stdout, contains(RegExp(r'Config complete')));
expect(result.stdout, isNot(contains(RegExp(r'Running Gradle task'))));
},
);
}
...@@ -24,6 +24,7 @@ class FakeAndroidBuilder implements AndroidBuilder { ...@@ -24,6 +24,7 @@ class FakeAndroidBuilder implements AndroidBuilder {
required FlutterProject project, required FlutterProject project,
required AndroidBuildInfo androidBuildInfo, required AndroidBuildInfo androidBuildInfo,
required String target, required String target,
bool configOnly = false,
}) async {} }) async {}
@override @override
...@@ -33,6 +34,7 @@ class FakeAndroidBuilder implements AndroidBuilder { ...@@ -33,6 +34,7 @@ class FakeAndroidBuilder implements AndroidBuilder {
required String target, required String target,
bool validateDeferredComponents = true, bool validateDeferredComponents = true,
bool deferredComponentsEnabled = false, bool deferredComponentsEnabled = false,
bool configOnly = false,
}) async {} }) async {}
} }
......
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