From 5cb9097965824ccaeeb26e3464f87b3e0372efce Mon Sep 17 00:00:00 2001 From: Brian Slesinsky Date: Fri, 14 Apr 2017 10:12:48 -0700 Subject: [PATCH] flutter create: enable Java support in IDEA (#9335) Generates an android.iml file and a package-level library for flutter.jar. Does not set up an Android SDK in IDEA; this isn't possible with a template-based approach. But IDEA shows a clear warning, so the user can fix this by setting the SDK. (When creating a Flutter project from within IDEA, we can fix this up afterwards in the plugin.) --- .../lib/src/commands/create.dart | 14 +++++++---- .../create/.idea/libraries/Dart_SDK.xml.tmpl | 25 +++++++++++++++++++ .../libraries/flutter_for_android.xml.tmpl | 9 +++++++ .../templates/create/.idea/modules.xml.tmpl | 1 + .../templates/create/android.iml.tmpl | 12 +++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 packages/flutter_tools/templates/create/.idea/libraries/Dart_SDK.xml.tmpl create mode 100644 packages/flutter_tools/templates/create/.idea/libraries/flutter_for_android.xml.tmpl create mode 100644 packages/flutter_tools/templates/create/android.iml.tmpl diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index 1dedb53982..e102823a35 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -5,6 +5,7 @@ import 'dart:async'; import '../android/android.dart' as android; +import '../android/android_sdk.dart' as android_sdk; import '../base/common.dart'; import '../base/file_system.dart'; import '../base/utils.dart'; @@ -103,7 +104,7 @@ class CreateCommand extends FlutterCommand { final Map templateContext = _templateContext( projectName, argResults['description'], dirPath, - flutterPackagesDirectory, renderDriverTest: argResults['with-driver-test'], + flutterRoot, renderDriverTest: argResults['with-driver-test'], withPluginHook: generatePlugin, ); @@ -188,10 +189,10 @@ Host platform code is in the android/ and ios/ directories under $relativePlugin } Map _templateContext(String projectName, - String projectDescription, String dirPath, String flutterPackagesDirectory, + String projectDescription, String dirPath, String flutterRoot, { bool renderDriverTest: false, bool withPluginHook: false }) { - flutterPackagesDirectory = fs.path.normalize(flutterPackagesDirectory); - flutterPackagesDirectory = _relativePath(from: dirPath, to: flutterPackagesDirectory); + flutterRoot = fs.path.normalize(flutterRoot); + flutterRoot = _relativePath(from: dirPath, to: flutterRoot); final String pluginDartClass = _createPluginClassName(projectName); final String pluginClass = pluginDartClass.endsWith('Plugin') @@ -203,8 +204,11 @@ Host platform code is in the android/ and ios/ directories under $relativePlugin 'androidIdentifier': _createAndroidIdentifier(projectName), 'iosIdentifier': _createUTIIdentifier(projectName), 'description': projectDescription, - 'flutterPackagesDirectory': flutterPackagesDirectory, + 'dartSdk': '$flutterRoot/bin/cache/dart-sdk', + 'flutterPackagesDirectory': fs.path.join(flutterRoot, 'packages'), 'androidMinApiLevel': android.minApiLevel, + 'androidSdkVersion': android_sdk.minimumAndroidSdkVersion, + 'androidFlutterJar': "$flutterRoot/bin/cache/artifacts/engine/android-arm/flutter.jar", 'withDriverTest': renderDriverTest, 'pluginClass': pluginClass, 'pluginDartClass': pluginDartClass, diff --git a/packages/flutter_tools/templates/create/.idea/libraries/Dart_SDK.xml.tmpl b/packages/flutter_tools/templates/create/.idea/libraries/Dart_SDK.xml.tmpl new file mode 100644 index 0000000000..4c3c50cc99 --- /dev/null +++ b/packages/flutter_tools/templates/create/.idea/libraries/Dart_SDK.xml.tmpl @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/flutter_tools/templates/create/.idea/libraries/flutter_for_android.xml.tmpl b/packages/flutter_tools/templates/create/.idea/libraries/flutter_for_android.xml.tmpl new file mode 100644 index 0000000000..2fac6b7982 --- /dev/null +++ b/packages/flutter_tools/templates/create/.idea/libraries/flutter_for_android.xml.tmpl @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/packages/flutter_tools/templates/create/.idea/modules.xml.tmpl b/packages/flutter_tools/templates/create/.idea/modules.xml.tmpl index 7488ebe80d..3a1214ba94 100644 --- a/packages/flutter_tools/templates/create/.idea/modules.xml.tmpl +++ b/packages/flutter_tools/templates/create/.idea/modules.xml.tmpl @@ -3,6 +3,7 @@ + diff --git a/packages/flutter_tools/templates/create/android.iml.tmpl b/packages/flutter_tools/templates/create/android.iml.tmpl new file mode 100644 index 0000000000..8e9d155a82 --- /dev/null +++ b/packages/flutter_tools/templates/create/android.iml.tmpl @@ -0,0 +1,12 @@ + + + + + + + + + + + +