forked from firka/flutter
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
This commit is contained in:
committed by
GitHub
parent
83b9142468
commit
e9af570f1f
@@ -2,6 +2,7 @@ import java.nio.file.Path
|
||||
import java.nio.file.Paths
|
||||
|
||||
import com.android.builder.model.AndroidProject
|
||||
import org.apache.tools.ant.taskdefs.condition.Os
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.GradleException
|
||||
import org.gradle.api.Project
|
||||
@@ -28,6 +29,7 @@ apply plugin: FlutterPlugin
|
||||
|
||||
class FlutterPlugin implements Plugin<Project> {
|
||||
private File flutterRoot
|
||||
private File flutterExecutable
|
||||
private String localEngine
|
||||
private Properties localProperties
|
||||
|
||||
@@ -70,6 +72,9 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
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")
|
||||
if (flutterJarPath != null) {
|
||||
File flutterJar = project.file(flutterJarPath)
|
||||
@@ -86,7 +91,7 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
File releaseFlutterJar = baseEnginePath.resolve("android-arm-release").resolve("flutter.jar").toFile()
|
||||
if (!debugFlutterJar.isFile()) {
|
||||
project.exec {
|
||||
executable "${flutterRoot}/bin/flutter"
|
||||
executable flutterExecutable.absolutePath
|
||||
args "precache"
|
||||
}
|
||||
if (!debugFlutterJar.isFile()) {
|
||||
@@ -139,6 +144,7 @@ class FlutterPlugin implements Plugin<Project> {
|
||||
|
||||
FlutterTask flutterTask = project.tasks.create("flutterBuild${variant.name.capitalize()}", FlutterTask) {
|
||||
flutterRoot this.flutterRoot
|
||||
flutterExecutable this.flutterExecutable
|
||||
buildMode variant.name
|
||||
localEngine this.localEngine
|
||||
targetPath target
|
||||
@@ -164,6 +170,7 @@ class FlutterExtension {
|
||||
|
||||
class FlutterTask extends DefaultTask {
|
||||
File flutterRoot
|
||||
File flutterExecutable
|
||||
String buildMode
|
||||
String localEngine
|
||||
String targetPath
|
||||
@@ -200,7 +207,7 @@ class FlutterTask extends DefaultTask {
|
||||
|
||||
if (buildMode != "debug") {
|
||||
project.exec {
|
||||
executable "${flutterRoot}/bin/flutter"
|
||||
executable flutterExecutable.absolutePath
|
||||
workingDir sourceDir
|
||||
if (localEngine != null) {
|
||||
args "--local-engine", localEngine
|
||||
@@ -214,7 +221,7 @@ class FlutterTask extends DefaultTask {
|
||||
}
|
||||
|
||||
project.exec {
|
||||
executable "${flutterRoot}/bin/flutter"
|
||||
executable flutterExecutable.absolutePath
|
||||
workingDir sourceDir
|
||||
if (localEngine != null) {
|
||||
args "--local-engine", localEngine
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../base/common.dart';
|
||||
import '../base/file_system.dart';
|
||||
import '../base/logger.dart';
|
||||
import '../base/os.dart';
|
||||
import '../base/platform.dart';
|
||||
import '../base/process.dart';
|
||||
import '../base/utils.dart';
|
||||
import '../build_info.dart';
|
||||
@@ -176,8 +177,8 @@ Future<Null> buildGradleProject(BuildMode buildMode) async {
|
||||
File localProperties = fs.file('android/local.properties');
|
||||
if (!localProperties.existsSync()) {
|
||||
localProperties.writeAsStringSync(
|
||||
'sdk.dir=${androidSdk.directory}\n'
|
||||
'flutter.sdk=${Cache.flutterRoot}\n'
|
||||
'sdk.dir=${_escapePath(androidSdk.directory)}\n'
|
||||
'flutter.sdk=${_escapePath(Cache.flutterRoot)}\n'
|
||||
);
|
||||
}
|
||||
// Update the local.properties file with the build mode.
|
||||
@@ -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 {
|
||||
// Run 'gradlew build'.
|
||||
Status status = logger.startProgress('Running \'gradlew build\'...', expectSlowOperation: true);
|
||||
|
||||
Reference in New Issue
Block a user