Commit 5af67e15 authored by Adam Barth's avatar Adam Barth

Add support for `target` to gradle build (#4420)

This lets you build something other than `lib/main.dart`.
parent 3ba17136
...@@ -15,8 +15,8 @@ Create an `ios/Flutter/Generated.xcconfig` file with this entry: ...@@ -15,8 +15,8 @@ Create an `ios/Flutter/Generated.xcconfig` file with this entry:
There are a number of other parameters you can control with this file: There are a number of other parameters you can control with this file:
* `FLUTTER_APPLICATION_PATH`: The path that contains your `pubspec.yaml` file * `FLUTTER_APPLICATION_PATH`: The path to the directory that contains your
relative to your `xcodeproj` file. `pubspec.yaml` file relative to your `xcodeproj` file.
* `FLUTTER_BUILD_MODE`: Whether to build for `debug`, `profile`, or `release`. * `FLUTTER_BUILD_MODE`: Whether to build for `debug`, `profile`, or `release`.
Defaults to `release`. Defaults to `release`.
* `FLUTTER_TARGET`: The path to your `main.dart` relative to your * `FLUTTER_TARGET`: The path to your `main.dart` relative to your
...@@ -47,10 +47,18 @@ There are a number of other parameters you can control with this file: ...@@ -47,10 +47,18 @@ There are a number of other parameters you can control with this file:
`android-arm-release` version of `flutter.jar` in the `bin/cache` directory `android-arm-release` version of `flutter.jar` in the `bin/cache` directory
of the Flutter SDK. of the Flutter SDK.
See `android/app/build.gradle` for project specific settings, including:
* `source`: The path to the directory that contains your `pubspec.yaml` file
relative to your `build.gradle` file.
* `target`: The path to your `main.dart` relative to your `pubspec.yaml`.
Defaults to `lib/main.dart`.
### Build ### Build
To build direction with gradle, use the following commands: To build directly with `gradle`, use the following commands:
* `cd android`
* `gradle wrapper` * `gradle wrapper`
* `./gradlew build` * `./gradlew build`
......
...@@ -87,10 +87,16 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -87,10 +87,16 @@ class FlutterPlugin implements Plugin<Project> {
throw new GradleException("Must provide Flutter source directory") throw new GradleException("Must provide Flutter source directory")
} }
String target = project.flutter.target;
if (target == null) {
target = 'lib/main.dart'
}
FlutterTask flutterTask = project.tasks.create("flutterBuild", FlutterTask) { FlutterTask flutterTask = project.tasks.create("flutterBuild", FlutterTask) {
flutterRoot this.flutterRoot flutterRoot this.flutterRoot
buildMode this.buildMode buildMode this.buildMode
localEngine this.localEngine localEngine this.localEngine
targetPath target
sourceDir project.file(project.flutter.source) sourceDir project.file(project.flutter.source)
intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter") intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter")
} }
...@@ -109,12 +115,14 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -109,12 +115,14 @@ class FlutterPlugin implements Plugin<Project> {
class FlutterExtension { class FlutterExtension {
String source String source
String target
} }
class FlutterTask extends DefaultTask { class FlutterTask extends DefaultTask {
File flutterRoot File flutterRoot
String buildMode String buildMode
String localEngine String localEngine
String targetPath
@InputDirectory @InputDirectory
File sourceDir File sourceDir
...@@ -150,6 +158,7 @@ class FlutterTask extends DefaultTask { ...@@ -150,6 +158,7 @@ class FlutterTask extends DefaultTask {
args "--local-engine", localEngine args "--local-engine", localEngine
} }
args "build", "aot" args "build", "aot"
args "--target", targetPath
args "--target-platform", "android-arm" args "--target-platform", "android-arm"
args "--output-dir", "${intermediateDir}" args "--output-dir", "${intermediateDir}"
args "--${buildMode}" args "--${buildMode}"
...@@ -163,6 +172,7 @@ class FlutterTask extends DefaultTask { ...@@ -163,6 +172,7 @@ class FlutterTask extends DefaultTask {
args "--local-engine", localEngine args "--local-engine", localEngine
} }
args "build", "flx" args "build", "flx"
args "--target", targetPath
args "--output-file", "${intermediateDir}/app.flx" args "--output-file", "${intermediateDir}/app.flx"
if (buildMode != "debug") { if (buildMode != "debug") {
args "--precompiled" args "--precompiled"
......
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