diff --git a/examples/hello_android/README.md b/examples/hello_android/README.md deleted file mode 100644 index 3d7cc1bddc..0000000000 --- a/examples/hello_android/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# Example of building a Flutter app for Android using Gradle - -This project demonstrates how to embed Flutter within an Android application -and build the Android and Flutter components with Gradle. - -To build this project: - -* Create a `local.properties` file with these entries: - * `sdk.dir=[path to the Android SDK]` - * `flutter.sdk=[path to the Flutter SDK]` - -Then run: - -* `gradle wrapper` -* `./gradlew build` - -## Updating the Dart code - -You can push new Dart code to a Flutter app during development without performing -a full rebuild of the Android app package. - -The `flutter refresh` tool manages this process. `flutter refresh` will build -a snapshot of an app's Dart code, copy it to an Android device, and send an -intent instructing the Android app to load the snapshot. - -To try this out: - -* Install and run this app on your device -* Edit the Dart code in `app/src/flutter/lib` -* cd `app/src/flutter` -* `flutter refresh --activity com.example.flutter/.ExampleActivity` - -`flutter refresh` sends an `ACTION_RUN` intent with an extra containing the -device filesystem path where the snapshot was copied. `ExampleActivity.java` -shows how an activity can handle this intent and load the new snapshot into -a Flutter view. diff --git a/examples/hello_android/app/src/flutter/lib/main.dart b/examples/hello_android/app/src/flutter/lib/main.dart deleted file mode 100644 index ef2fa82ec4..0000000000 --- a/examples/hello_android/app/src/flutter/lib/main.dart +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; -import 'dart:convert'; -import 'dart:math'; - -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter/widgets.dart'; - -final Random random = new Random(); - -Future handleGetRandom(String json) async { - Map message = JSON.decode(json); - double min = message['min'].toDouble(); - double max = message['max'].toDouble(); - - double value = (random.nextDouble() * (max - min)) + min; - - Map reply = {'value': value}; - return JSON.encode(reply); -} - -class HelloAndroid extends StatefulWidget { - @override - _HelloAndroidState createState() => new _HelloAndroidState(); -} - -class _HelloAndroidState extends State { - double _latitude; - double _longitude; - - @override - Widget build(BuildContext context) { - return new Material( - child: new Center( - child: new Column( - children: [ - new Text('Hello from Flutter!'), - new RaisedButton( - child: new Text('Get Location'), - onPressed: _getLocation - ), - new Text('Latitude: $_latitude, Longitude: $_longitude'), - ] - ) - ) - ); - } - - void _getLocation() { - Map message = {'provider': 'network'}; - HostMessages.sendToHost('getLocation', JSON.encode(message)) - .then(_onReceivedLocation); - } - - void _onReceivedLocation(String json) { - Map reply = JSON.decode(json); - setState(() { - _latitude = reply['latitude']; - _longitude = reply['longitude']; - }); - } -} - -void main() { - runApp(new HelloAndroid()); - - HostMessages.addMessageHandler('getRandom', handleGetRandom); -} diff --git a/examples/hello_android/app/src/flutter/pubspec.yaml b/examples/hello_android/app/src/flutter/pubspec.yaml deleted file mode 100644 index 22acfdaf05..0000000000 --- a/examples/hello_android/app/src/flutter/pubspec.yaml +++ /dev/null @@ -1,9 +0,0 @@ -name: gradle - -dependencies: - flutter: - path: ../../../../../packages/flutter - -dev_dependencies: - flutter_test: - path: ../../../../../packages/flutter_test diff --git a/examples/hello_services/.gitignore b/examples/hello_services/.gitignore index 2c17f4a14d..9b3426eff3 100644 --- a/examples/hello_services/.gitignore +++ b/examples/hello_services/.gitignore @@ -1,45 +1,8 @@ -.idea/ -.vagrant/ -.sconsign.dblite -.svn/ - .DS_Store -*.swp -*.lock -profile - -DerivedData/ -build/ - -*.pbxuser -*.mode1v3 -*.mode2v3 -*.perspectivev3 - -!default.pbxuser -!default.mode1v3 -!default.mode2v3 -!default.perspectivev3 - -xcuserdata - -*.moved-aside - -*.pyc -*sync/ -Icon? -.tags* - .atom/ -.buildlog +.idea .packages .pub/ build/ packages/ pubspec.lock - -ios/Flutter/app.flx -ios/Flutter/app.so -ios/Flutter/app.zip -ios/Flutter/Flutter.framework -ios/Flutter/Generated.xcconfig diff --git a/examples/hello_services/README.md b/examples/hello_services/README.md index 38e2a7ba7e..83d173b56a 100644 --- a/examples/hello_services/README.md +++ b/examples/hello_services/README.md @@ -1,25 +1,68 @@ -# Example of using FlutterView in an iOS app. +# Example of embedding Flutter using FlutterView -This project demonstrates how to embed Flutter within an iOS application -and build the iOS and Flutter components with Xcode. +This project demonstrates how to embed Flutter within an iOS or Android +application. On iOS, the iOS and Flutter components are built with Xcode. On +Android, the Android and Flutter components are built with Android Studio or +gradle. -## Configure +## iOS + +### Configure Create an `ios/Flutter/Generated.xcconfig` file with this entry: - * `FLUTTER_ROOT=[absolute path to the Flutter SDK]` + * `FLUTTER_ROOT=[absolute path to the Flutter SDK]` There are a number of other parameters you can control with this file: - * `FLUTTER_APPLICATION_PATH`: The path that contains your `pubspec.yaml` file - relative to your `xcodeproj` file. - * `FLUTTER_TARGET`: The path to your `main.dart` relative to your - `pubspec.yaml`. Defaults to `lib/main.dart`. - * `FLUTTER_FRAMEWORK_DIR`: The absolute path to the directory that contains - `Flutter.framework`. Defaults to the `ios-release` version of - `Flutter.framework` in the `bin/cache` directory of the Flutter SDK. + * `FLUTTER_APPLICATION_PATH`: The path that contains your `pubspec.yaml` file + relative to your `xcodeproj` file. + * `FLUTTER_TARGET`: The path to your `main.dart` relative to your + `pubspec.yaml`. Defaults to `lib/main.dart`. + * `FLUTTER_FRAMEWORK_DIR`: The absolute path to the directory that contains + `Flutter.framework`. Defaults to the `ios-release` version of + `Flutter.framework` in the `bin/cache` directory of the Flutter SDK. -## Build +### Build Once you've configured your project, you can open `ios/HelloServices.xcodeproj` in Xcode and build the project as usual. + +## Android + +### Configure + +Create an `android/local.properties` file with these entries: + + * `sdk.dir=[path to the Android SDK]` + * `flutter.sdk=[path to the Flutter SDK]` + +### Build + +To build direction with gradle, use the following commands: + + * `gradle wrapper` + * `./gradlew build` + +To build with Android Studio, open the `android` folder in Android Studio and +build the project as usual. + +### Updating the Dart code + +You can push new Dart code to a Flutter app during development without performing +a full rebuild of the Android app package. + +The `flutter refresh` tool manages this process. `flutter refresh` will build +a snapshot of an app's Dart code, copy it to an Android device, and send an +intent instructing the Android app to load the snapshot. + +To try this out: + + * Install and run the app on your device + * Edit the Dart code + * `flutter refresh --activity com.example.flutter/.ExampleActivity` + +`flutter refresh` sends an `ACTION_RUN` intent with an extra containing the +device filesystem path where the snapshot was copied. `ExampleActivity.java` +shows how an activity can handle this intent and load the new snapshot into +a FlutterView. diff --git a/examples/hello_services/android/.gitignore b/examples/hello_services/android/.gitignore new file mode 100644 index 0000000000..5c4ef82869 --- /dev/null +++ b/examples/hello_services/android/.gitignore @@ -0,0 +1,12 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures + +/gradle +/gradlew +/gradlew.bat diff --git a/examples/hello_services/android/app/.gitignore b/examples/hello_services/android/app/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/examples/hello_services/android/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/examples/hello_android/app/build.gradle b/examples/hello_services/android/app/build.gradle similarity index 89% rename from examples/hello_android/app/build.gradle rename to examples/hello_services/android/app/build.gradle index 8ece56f40b..79afa384c1 100644 --- a/examples/hello_android/app/build.gradle +++ b/examples/hello_services/android/app/build.gradle @@ -11,5 +11,5 @@ android { } flutter { - source 'src/flutter' + source '../..' } diff --git a/examples/hello_android/app/src/main/AndroidManifest.xml b/examples/hello_services/android/app/src/main/AndroidManifest.xml similarity index 100% rename from examples/hello_android/app/src/main/AndroidManifest.xml rename to examples/hello_services/android/app/src/main/AndroidManifest.xml diff --git a/examples/hello_android/app/src/main/java/com/example/flutter/ExampleActivity.java b/examples/hello_services/android/app/src/main/java/com/example/flutter/ExampleActivity.java similarity index 93% rename from examples/hello_android/app/src/main/java/com/example/flutter/ExampleActivity.java rename to examples/hello_services/android/app/src/main/java/com/example/flutter/ExampleActivity.java index 99fe701fe3..5ff4f4bee7 100644 --- a/examples/hello_android/app/src/main/java/com/example/flutter/ExampleActivity.java +++ b/examples/hello_services/android/app/src/main/java/com/example/flutter/ExampleActivity.java @@ -35,7 +35,7 @@ public class ExampleActivity extends Activity { super.onCreate(savedInstanceState); FlutterMain.ensureInitializationComplete(getApplicationContext(), null); - setContentView(R.layout.flutter_layout); + setContentView(R.layout.hello_services_layout); flutterView = (FlutterView) findViewById(R.id.flutter_view); File appBundle = new File(PathUtils.getDataDirectory(this), FlutterMain.APP_BUNDLE); @@ -150,8 +150,13 @@ public class ExampleActivity extends Activity { JSONObject reply = new JSONObject(); try { - reply.put("latitude", location.getLatitude()); - reply.put("longitude", location.getLongitude()); + if (location != null) { + reply.put("latitude", location.getLatitude()); + reply.put("longitude", location.getLongitude()); + } else { + reply.put("latitude", 0); + reply.put("longitude", 0); + } } catch (JSONException e) { Log.e(TAG, "JSON exception", e); return null; diff --git a/examples/hello_android/app/src/main/res/layout/flutter_layout.xml b/examples/hello_services/android/app/src/main/res/layout/hello_services_layout.xml similarity index 100% rename from examples/hello_android/app/src/main/res/layout/flutter_layout.xml rename to examples/hello_services/android/app/src/main/res/layout/hello_services_layout.xml diff --git a/examples/hello_android/app/src/main/res/values/strings.xml b/examples/hello_services/android/app/src/main/res/values/strings.xml similarity index 77% rename from examples/hello_android/app/src/main/res/values/strings.xml rename to examples/hello_services/android/app/src/main/res/values/strings.xml index 28a74f501e..010ee34453 100644 --- a/examples/hello_android/app/src/main/res/values/strings.xml +++ b/examples/hello_services/android/app/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - Flutter App + Hello Services Flutter Application Get Random Number diff --git a/examples/hello_android/build.gradle b/examples/hello_services/android/build.gradle similarity index 100% rename from examples/hello_android/build.gradle rename to examples/hello_services/android/build.gradle diff --git a/examples/hello_android/buildSrc/build.gradle b/examples/hello_services/android/buildSrc/build.gradle similarity index 100% rename from examples/hello_android/buildSrc/build.gradle rename to examples/hello_services/android/buildSrc/build.gradle diff --git a/examples/hello_android/buildSrc/src/main/groovy/FlutterPlugin.groovy b/examples/hello_services/android/buildSrc/src/main/groovy/FlutterPlugin.groovy similarity index 100% rename from examples/hello_android/buildSrc/src/main/groovy/FlutterPlugin.groovy rename to examples/hello_services/android/buildSrc/src/main/groovy/FlutterPlugin.groovy diff --git a/examples/hello_android/buildSrc/src/main/resources/META-INF/gradle-plugins/flutter.properties b/examples/hello_services/android/buildSrc/src/main/resources/META-INF/gradle-plugins/flutter.properties similarity index 100% rename from examples/hello_android/buildSrc/src/main/resources/META-INF/gradle-plugins/flutter.properties rename to examples/hello_services/android/buildSrc/src/main/resources/META-INF/gradle-plugins/flutter.properties diff --git a/examples/hello_android/settings.gradle b/examples/hello_services/android/settings.gradle similarity index 100% rename from examples/hello_android/settings.gradle rename to examples/hello_services/android/settings.gradle diff --git a/examples/hello_services/ios/.gitignore b/examples/hello_services/ios/.gitignore new file mode 100644 index 0000000000..fdc9f59762 --- /dev/null +++ b/examples/hello_services/ios/.gitignore @@ -0,0 +1,37 @@ +.idea/ +.vagrant/ +.sconsign.dblite +.svn/ + +.DS_Store +*.swp +*.lock +profile + +DerivedData/ +build/ + +*.pbxuser +*.mode1v3 +*.mode2v3 +*.perspectivev3 + +!default.pbxuser +!default.mode1v3 +!default.mode2v3 +!default.perspectivev3 + +xcuserdata + +*.moved-aside + +*.pyc +*sync/ +Icon? +.tags* + +/Flutter/app.flx +/Flutter/app.so +/Flutter/app.zip +/Flutter/Flutter.framework +/Flutter/Generated.xcconfig