mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Create configOnly flag for android (#121904)
Create configOnly flag for android
This commit is contained in:
parent
a9700ffdd5
commit
fe9e819143
@ -27,6 +27,7 @@ abstract class AndroidBuilder {
|
||||
required FlutterProject project,
|
||||
required AndroidBuildInfo androidBuildInfo,
|
||||
required String target,
|
||||
bool configOnly = false,
|
||||
});
|
||||
|
||||
/// Builds an App Bundle artifact.
|
||||
@ -36,5 +37,6 @@ abstract class AndroidBuilder {
|
||||
required String target,
|
||||
bool validateDeferredComponents = true,
|
||||
bool deferredComponentsEnabled = false,
|
||||
bool configOnly = false,
|
||||
});
|
||||
}
|
||||
|
||||
@ -181,6 +181,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
required FlutterProject project,
|
||||
required AndroidBuildInfo androidBuildInfo,
|
||||
required String target,
|
||||
bool configOnly = false,
|
||||
}) async {
|
||||
await buildGradleApp(
|
||||
project: project,
|
||||
@ -188,6 +189,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
target: target,
|
||||
isBuildingBundle: false,
|
||||
localGradleErrors: gradleErrors,
|
||||
configOnly: configOnly,
|
||||
);
|
||||
}
|
||||
|
||||
@ -199,6 +201,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
required String target,
|
||||
bool validateDeferredComponents = true,
|
||||
bool deferredComponentsEnabled = false,
|
||||
bool configOnly = false,
|
||||
}) async {
|
||||
await buildGradleApp(
|
||||
project: project,
|
||||
@ -208,6 +211,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
localGradleErrors: gradleErrors,
|
||||
validateDeferredComponents: validateDeferredComponents,
|
||||
deferredComponentsEnabled: deferredComponentsEnabled,
|
||||
configOnly: configOnly,
|
||||
);
|
||||
}
|
||||
|
||||
@ -225,6 +229,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
required String target,
|
||||
required bool isBuildingBundle,
|
||||
required List<GradleHandledError> localGradleErrors,
|
||||
required bool configOnly,
|
||||
bool validateDeferredComponents = true,
|
||||
bool deferredComponentsEnabled = false,
|
||||
int retry = 0,
|
||||
@ -249,8 +254,22 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
}
|
||||
// The default Gradle script reads the version name and number
|
||||
// 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 String assembleTask = isBuildingBundle
|
||||
? getBundleTaskFor(buildInfo)
|
||||
@ -260,9 +279,6 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
"Running Gradle task '$assembleTask'...",
|
||||
);
|
||||
|
||||
final List<String> command = <String>[
|
||||
_gradleUtils.getExecutable(project),
|
||||
];
|
||||
if (_logger.isVerbose) {
|
||||
command.add('--full-stacktrace');
|
||||
command.add('--info');
|
||||
@ -428,6 +444,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
|
||||
localGradleErrors: localGradleErrors,
|
||||
retry: retry,
|
||||
maxRetries: maxRetries,
|
||||
configOnly: configOnly,
|
||||
);
|
||||
final String successEventLabel = 'gradle-${detectedGradleError!.eventLabel}-success';
|
||||
BuildEvent(successEventLabel, type: 'gradle', flutterUsage: _usage).send();
|
||||
|
||||
@ -43,6 +43,9 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
help: 'Whether to split the APKs per ABIs. '
|
||||
'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',
|
||||
defaultsTo: <String>['android-arm', 'android-arm64', 'android-x64'],
|
||||
allowed: <String>['android-arm', 'android-arm64', 'android-x86', 'android-x64'],
|
||||
@ -57,6 +60,8 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
@override
|
||||
DeprecationBehavior get deprecationBehavior => boolArgDeprecated('ignore-deprecation') ? DeprecationBehavior.ignore : DeprecationBehavior.exit;
|
||||
|
||||
bool get configOnly => boolArg('config-only') ?? false;
|
||||
|
||||
@override
|
||||
Future<Set<DevelopmentArtifact>> get requiredArtifacts async => <DevelopmentArtifact>{
|
||||
DevelopmentArtifact.androidGenSnapshot,
|
||||
@ -112,6 +117,7 @@ class BuildApkCommand extends BuildSubCommand {
|
||||
project: FlutterProject.current(),
|
||||
target: targetFile,
|
||||
androidBuildInfo: androidBuildInfo,
|
||||
configOnly: configOnly,
|
||||
);
|
||||
return FlutterCommandResult.success();
|
||||
}
|
||||
|
||||
@ -92,6 +92,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: <GradleHandledError>[
|
||||
GradleHandledError(
|
||||
test: (String line) {
|
||||
@ -187,6 +188,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: <GradleHandledError>[],
|
||||
);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
@ -256,6 +258,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: <GradleHandledError>[
|
||||
GradleHandledError(
|
||||
test: (String line) {
|
||||
@ -350,6 +353,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: <GradleHandledError>[
|
||||
GradleHandledError(
|
||||
test: (String line) {
|
||||
@ -441,6 +445,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: const <GradleHandledError>[],
|
||||
);
|
||||
}, throwsProcessException());
|
||||
@ -520,6 +525,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: <GradleHandledError>[
|
||||
GradleHandledError(
|
||||
test: (String line) {
|
||||
@ -636,6 +642,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: <GradleHandledError>[],
|
||||
);
|
||||
|
||||
@ -704,6 +711,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: const <GradleHandledError>[],
|
||||
);
|
||||
|
||||
@ -963,6 +971,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: const <GradleHandledError>[],
|
||||
);
|
||||
}, throwsToolExit());
|
||||
@ -1039,6 +1048,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: const <GradleHandledError>[],
|
||||
);
|
||||
}, throwsToolExit());
|
||||
@ -1115,6 +1125,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: const <GradleHandledError>[],
|
||||
);
|
||||
}, throwsToolExit());
|
||||
@ -1192,6 +1203,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: const <GradleHandledError>[],
|
||||
);
|
||||
}, throwsToolExit());
|
||||
@ -1250,6 +1262,7 @@ void main() {
|
||||
),
|
||||
target: 'lib/main.dart',
|
||||
isBuildingBundle: false,
|
||||
configOnly: false,
|
||||
localGradleErrors: const <GradleHandledError>[],
|
||||
);
|
||||
}, throwsToolExit());
|
||||
|
||||
@ -0,0 +1,65 @@
|
||||
// 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 {
|
||||
required FlutterProject project,
|
||||
required AndroidBuildInfo androidBuildInfo,
|
||||
required String target,
|
||||
bool configOnly = false,
|
||||
}) async {}
|
||||
|
||||
@override
|
||||
@ -33,6 +34,7 @@ class FakeAndroidBuilder implements AndroidBuilder {
|
||||
required String target,
|
||||
bool validateDeferredComponents = true,
|
||||
bool deferredComponentsEnabled = false,
|
||||
bool configOnly = false,
|
||||
}) async {}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user