Commit 13d7770c authored by Jakob Andersen's avatar Jakob Andersen Committed by GitHub

Fix local engine support for Gradle builds. (#8362)

Fixes #6761.
parent fa043216
...@@ -31,6 +31,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -31,6 +31,7 @@ class FlutterPlugin implements Plugin<Project> {
private File flutterRoot private File flutterRoot
private File flutterExecutable private File flutterExecutable
private String localEngine private String localEngine
private String localEngineSrcPath
private Properties localProperties private Properties localProperties
private String resolveProperty(Project project, String name, String defaultValue) { private String resolveProperty(Project project, String name, String defaultValue) {
...@@ -41,7 +42,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -41,7 +42,7 @@ class FlutterPlugin implements Plugin<Project> {
localProperties.load(localPropertiesFile.newDataInputStream()) localProperties.load(localPropertiesFile.newDataInputStream())
} }
} }
String result; String result
if (project.hasProperty(name)) { if (project.hasProperty(name)) {
result = project.property(name) result = project.property(name)
} }
...@@ -75,12 +76,20 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -75,12 +76,20 @@ class FlutterPlugin implements Plugin<Project> {
String flutterExecutableName = Os.isFamily(Os.FAMILY_WINDOWS) ? "flutter.bat" : "flutter" String flutterExecutableName = Os.isFamily(Os.FAMILY_WINDOWS) ? "flutter.bat" : "flutter"
flutterExecutable = Paths.get(flutterRoot.absolutePath, "bin", flutterExecutableName).toFile(); flutterExecutable = Paths.get(flutterRoot.absolutePath, "bin", flutterExecutableName).toFile();
String flutterJarPath = localProperties.getProperty("flutter.jar") if (project.hasProperty('localEngineOut')) {
if (flutterJarPath != null) { String engineOutPath = project.property('localEngineOut')
File flutterJar = project.file(flutterJarPath) File engineOut = project.file(engineOutPath)
if (!engineOut.isDirectory()) {
throw new GradleException('localEngineOut must point to a local engine build')
}
File flutterJar = Paths.get(engineOut.absolutePath, "flutter.jar").toFile()
if (!flutterJar.isFile()) { if (!flutterJar.isFile()) {
throw new GradleException("flutter.jar must point to a Flutter engine JAR") throw new GradleException('Local engine build does not contain flutter.jar')
} }
localEngine = engineOut.name
localEngineSrcPath = engineOut.parentFile.parent
project.dependencies { project.dependencies {
compile project.files(flutterJar) compile project.files(flutterJar)
} }
...@@ -119,8 +128,6 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -119,8 +128,6 @@ class FlutterPlugin implements Plugin<Project> {
} }
} }
localEngine = localProperties.getProperty("flutter.localEngine")
project.extensions.create("flutter", FlutterExtension) project.extensions.create("flutter", FlutterExtension)
project.afterEvaluate this.&addFlutterTask project.afterEvaluate this.&addFlutterTask
} }
...@@ -135,7 +142,9 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -135,7 +142,9 @@ class FlutterPlugin implements Plugin<Project> {
target = 'lib/main.dart' target = 'lib/main.dart'
} }
project.compileDebugJavaWithJavac.dependsOn project.flutterBuildX86Jar if (project.tasks.findByName('flutterBuildX86Jar')) {
project.compileDebugJavaWithJavac.dependsOn project.flutterBuildX86Jar
}
project.android.applicationVariants.all { variant -> project.android.applicationVariants.all { variant ->
if (!["debug", "profile", "release"].contains(variant.name)) { if (!["debug", "profile", "release"].contains(variant.name)) {
...@@ -147,6 +156,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -147,6 +156,7 @@ class FlutterPlugin implements Plugin<Project> {
flutterExecutable this.flutterExecutable flutterExecutable this.flutterExecutable
buildMode variant.name buildMode variant.name
localEngine this.localEngine localEngine this.localEngine
localEngineSrcPath this.localEngineSrcPath
targetPath target targetPath target
sourceDir project.file(project.flutter.source) sourceDir project.file(project.flutter.source)
intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}") intermediateDir project.file("${project.buildDir}/${AndroidProject.FD_INTERMEDIATES}/flutter/${variant.name}")
...@@ -173,6 +183,7 @@ class FlutterTask extends DefaultTask { ...@@ -173,6 +183,7 @@ class FlutterTask extends DefaultTask {
File flutterExecutable File flutterExecutable
String buildMode String buildMode
String localEngine String localEngine
String localEngineSrcPath
String targetPath String targetPath
File sourceDir File sourceDir
...@@ -211,6 +222,7 @@ class FlutterTask extends DefaultTask { ...@@ -211,6 +222,7 @@ class FlutterTask extends DefaultTask {
workingDir sourceDir workingDir sourceDir
if (localEngine != null) { if (localEngine != null) {
args "--local-engine", localEngine args "--local-engine", localEngine
args "--local-engine-src-path", localEngineSrcPath
} }
args "build", "aot" args "build", "aot"
args "--target", targetPath args "--target", targetPath
...@@ -225,6 +237,7 @@ class FlutterTask extends DefaultTask { ...@@ -225,6 +237,7 @@ class FlutterTask extends DefaultTask {
workingDir sourceDir workingDir sourceDir
if (localEngine != null) { if (localEngine != null) {
args "--local-engine", localEngine args "--local-engine", localEngine
args "--local-engine-src-path", localEngineSrcPath
} }
args "build", "flx" args "build", "flx"
args "--target", targetPath args "--target", targetPath
......
...@@ -11,6 +11,7 @@ import '../base/os.dart'; ...@@ -11,6 +11,7 @@ import '../base/os.dart';
import '../base/platform.dart'; import '../base/platform.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/utils.dart'; import '../base/utils.dart';
import '../artifacts.dart';
import '../build_info.dart'; import '../build_info.dart';
import '../cache.dart'; import '../cache.dart';
import '../globals.dart'; import '../globals.dart';
...@@ -158,9 +159,16 @@ Future<Null> buildGradleProjectV2(String gradle, String buildModeName) async { ...@@ -158,9 +159,16 @@ Future<Null> buildGradleProjectV2(String gradle, String buildModeName) async {
// Run 'gradle assemble<BuildMode>'. // Run 'gradle assemble<BuildMode>'.
Status status = logger.startProgress('Running \'gradle $assembleTask\'...', expectSlowOperation: true); Status status = logger.startProgress('Running \'gradle $assembleTask\'...', expectSlowOperation: true);
String gradlePath = fs.file(gradle).absolute.path; String gradlePath = fs.file(gradle).absolute.path;
List<String> command = logger.isVerbose List<String> command = <String>[gradlePath];
? <String>[gradlePath, assembleTask] if (!logger.isVerbose) {
: <String>[gradlePath, '-q', assembleTask]; command.add('-q');
}
if (artifacts is LocalEngineArtifacts) {
LocalEngineArtifacts localEngineArtifacts = artifacts;
printTrace('Using local engine: ${localEngineArtifacts.engineOutPath}');
command.add('-PlocalEngineOut=${localEngineArtifacts.engineOutPath}');
}
command.add(assembleTask);
int exitcode = await runCommandAndStreamOutput( int exitcode = await runCommandAndStreamOutput(
command, command,
workingDirectory: 'android', workingDirectory: 'android',
......
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