Commit e9af570f authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Enable Gradle Workflow on Windows (#8201)

* Enable Gradle Workflow on Windows

With this the app created by `flutter create` now compiles on Windows.

* Move OS check to gradle file
parent 83b91424
...@@ -2,6 +2,7 @@ import java.nio.file.Path ...@@ -2,6 +2,7 @@ import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import com.android.builder.model.AndroidProject import com.android.builder.model.AndroidProject
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.DefaultTask import org.gradle.api.DefaultTask
import org.gradle.api.GradleException import org.gradle.api.GradleException
import org.gradle.api.Project import org.gradle.api.Project
...@@ -28,6 +29,7 @@ apply plugin: FlutterPlugin ...@@ -28,6 +29,7 @@ apply plugin: FlutterPlugin
class FlutterPlugin implements Plugin<Project> { class FlutterPlugin implements Plugin<Project> {
private File flutterRoot private File flutterRoot
private File flutterExecutable
private String localEngine private String localEngine
private Properties localProperties private Properties localProperties
...@@ -70,6 +72,9 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -70,6 +72,9 @@ class FlutterPlugin implements Plugin<Project> {
throw new GradleException("flutter.sdk must point to the Flutter SDK directory") throw new GradleException("flutter.sdk must point to the Flutter SDK directory")
} }
String flutterExecutableName = Os.isFamily(Os.FAMILY_WINDOWS) ? "flutter.bat" : "flutter"
flutterExecutable = Paths.get(flutterRoot.absolutePath, "bin", flutterExecutableName).toFile();
String flutterJarPath = localProperties.getProperty("flutter.jar") String flutterJarPath = localProperties.getProperty("flutter.jar")
if (flutterJarPath != null) { if (flutterJarPath != null) {
File flutterJar = project.file(flutterJarPath) File flutterJar = project.file(flutterJarPath)
...@@ -86,7 +91,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -86,7 +91,7 @@ class FlutterPlugin implements Plugin<Project> {
File releaseFlutterJar = baseEnginePath.resolve("android-arm-release").resolve("flutter.jar").toFile() File releaseFlutterJar = baseEnginePath.resolve("android-arm-release").resolve("flutter.jar").toFile()
if (!debugFlutterJar.isFile()) { if (!debugFlutterJar.isFile()) {
project.exec { project.exec {
executable "${flutterRoot}/bin/flutter" executable flutterExecutable.absolutePath
args "precache" args "precache"
} }
if (!debugFlutterJar.isFile()) { if (!debugFlutterJar.isFile()) {
...@@ -139,6 +144,7 @@ class FlutterPlugin implements Plugin<Project> { ...@@ -139,6 +144,7 @@ class FlutterPlugin implements Plugin<Project> {
FlutterTask flutterTask = project.tasks.create("flutterBuild${variant.name.capitalize()}", FlutterTask) { FlutterTask flutterTask = project.tasks.create("flutterBuild${variant.name.capitalize()}", FlutterTask) {
flutterRoot this.flutterRoot flutterRoot this.flutterRoot
flutterExecutable this.flutterExecutable
buildMode variant.name buildMode variant.name
localEngine this.localEngine localEngine this.localEngine
targetPath target targetPath target
...@@ -164,6 +170,7 @@ class FlutterExtension { ...@@ -164,6 +170,7 @@ class FlutterExtension {
class FlutterTask extends DefaultTask { class FlutterTask extends DefaultTask {
File flutterRoot File flutterRoot
File flutterExecutable
String buildMode String buildMode
String localEngine String localEngine
String targetPath String targetPath
...@@ -200,7 +207,7 @@ class FlutterTask extends DefaultTask { ...@@ -200,7 +207,7 @@ class FlutterTask extends DefaultTask {
if (buildMode != "debug") { if (buildMode != "debug") {
project.exec { project.exec {
executable "${flutterRoot}/bin/flutter" executable flutterExecutable.absolutePath
workingDir sourceDir workingDir sourceDir
if (localEngine != null) { if (localEngine != null) {
args "--local-engine", localEngine args "--local-engine", localEngine
...@@ -214,7 +221,7 @@ class FlutterTask extends DefaultTask { ...@@ -214,7 +221,7 @@ class FlutterTask extends DefaultTask {
} }
project.exec { project.exec {
executable "${flutterRoot}/bin/flutter" executable flutterExecutable.absolutePath
workingDir sourceDir workingDir sourceDir
if (localEngine != null) { if (localEngine != null) {
args "--local-engine", localEngine args "--local-engine", localEngine
......
...@@ -8,6 +8,7 @@ import '../base/common.dart'; ...@@ -8,6 +8,7 @@ import '../base/common.dart';
import '../base/file_system.dart'; import '../base/file_system.dart';
import '../base/logger.dart'; import '../base/logger.dart';
import '../base/os.dart'; import '../base/os.dart';
import '../base/platform.dart';
import '../base/process.dart'; import '../base/process.dart';
import '../base/utils.dart'; import '../base/utils.dart';
import '../build_info.dart'; import '../build_info.dart';
...@@ -176,8 +177,8 @@ Future<Null> buildGradleProject(BuildMode buildMode) async { ...@@ -176,8 +177,8 @@ Future<Null> buildGradleProject(BuildMode buildMode) async {
File localProperties = fs.file('android/local.properties'); File localProperties = fs.file('android/local.properties');
if (!localProperties.existsSync()) { if (!localProperties.existsSync()) {
localProperties.writeAsStringSync( localProperties.writeAsStringSync(
'sdk.dir=${androidSdk.directory}\n' 'sdk.dir=${_escapePath(androidSdk.directory)}\n'
'flutter.sdk=${Cache.flutterRoot}\n' 'flutter.sdk=${_escapePath(Cache.flutterRoot)}\n'
); );
} }
// Update the local.properties file with the build mode. // Update the local.properties file with the build mode.
...@@ -203,6 +204,8 @@ Future<Null> buildGradleProject(BuildMode buildMode) async { ...@@ -203,6 +204,8 @@ Future<Null> buildGradleProject(BuildMode buildMode) async {
} }
} }
String _escapePath(String path) => platform.isWindows ? path.replaceAll('\\', '\\\\') : path;
Future<Null> buildGradleProjectV1(String gradlew) async { Future<Null> buildGradleProjectV1(String gradlew) async {
// Run 'gradlew build'. // Run 'gradlew build'.
Status status = logger.startProgress('Running \'gradlew build\'...', expectSlowOperation: true); Status status = logger.startProgress('Running \'gradlew build\'...', expectSlowOperation: true);
......
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