Commit 6d66be17 authored by Jakob Andersen's avatar Jakob Andersen Committed by GitHub

Add support for target file in Gradle builds. (#8364)

If a target file is specified on the flutter tools command line, pass it
through to Gradle.

It is still possible to statically specify a target file in the flutter
section of build.gradle, but it is now possible to specify it on the
command line as well. The command line option takes precedence.

Fixes #8175.
parent 13d7770c
......@@ -141,6 +141,13 @@ class FlutterPlugin implements Plugin<Project> {
if (target == null) {
target = 'lib/main.dart'
}
if (project.hasProperty('target')) {
target = project.property('target')
}
File targetFile = project.file(Paths.get(project.flutter.source, target).toString())
if (!targetFile.exists()) {
throw new GradleException("Target file $targetFile not found")
}
if (project.tasks.findByName('flutterBuildX86Jar')) {
project.compileDebugJavaWithJavac.dependsOn project.flutterBuildX86Jar
......@@ -184,6 +191,7 @@ class FlutterTask extends DefaultTask {
String buildMode
String localEngine
String localEngineSrcPath
@Input
String targetPath
File sourceDir
......
......@@ -102,7 +102,7 @@ Future<String> ensureGradle() async {
return gradle;
}
Future<Null> buildGradleProject(BuildMode buildMode) async {
Future<Null> buildGradleProject(BuildMode buildMode, String target) async {
// Create android/local.properties.
File localProperties = fs.file('android/local.properties');
if (!localProperties.existsSync()) {
......@@ -130,7 +130,7 @@ Future<Null> buildGradleProject(BuildMode buildMode) async {
case FlutterPluginVersion.managed:
// Fall through. Managed plugin builds the same way as plugin v2.
case FlutterPluginVersion.v2:
return buildGradleProjectV2(gradle, buildModeName);
return buildGradleProjectV2(gradle, buildModeName, target);
}
}
......@@ -153,7 +153,7 @@ Future<Null> buildGradleProjectV1(String gradle) async {
printStatus('Built $gradleAppOutV1 (${getSizeAsMB(apkFile.lengthSync())}).');
}
Future<Null> buildGradleProjectV2(String gradle, String buildModeName) async {
Future<Null> buildGradleProjectV2(String gradle, String buildModeName, String target) async {
String assembleTask = "assemble${toTitleCase(buildModeName)}";
// Run 'gradle assemble<BuildMode>'.
......@@ -168,6 +168,9 @@ Future<Null> buildGradleProjectV2(String gradle, String buildModeName) async {
printTrace('Using local engine: ${localEngineArtifacts.engineOutPath}');
command.add('-PlocalEngineOut=${localEngineArtifacts.engineOutPath}');
}
if (target != null) {
command.add('-Ptarget=$target');
}
command.add(assembleTask);
int exitcode = await runCommandAndStreamOutput(
command,
......
......@@ -589,7 +589,7 @@ Future<Null> buildAndroidWithGradle(
throwToolExit('Try re-installing or updating your Android SDK.');
}
return buildGradleProject(buildMode);
return buildGradleProject(buildMode, target);
}
Future<Null> buildApk(
......
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