* Make new project template gradle-based for Android. With this change, the 'new project' template uses the same gradle-based build for Android as the hello_services example. This has some implications on build performance, since we're now building a complete Android app instead of just combining a pre-compiled .dex with the Flutter assets. The very first build is a little over 2x slower, since it needs to download gradle and build the build scripts before getting to the actual code. Subsequent builds with changes to the code are comparable to the old builds. Null builds are faster. Enabling the gradle daemon speeds up subsequent builds by around 5s. * Move Flutter Gradle plugin to Flutter root.
Example of embedding Flutter using FlutterView
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.
You can read more about accessing platform and third-party services in Flutter.
iOS
Configure
Create an ios/Flutter/Generated.xcconfig file with this entry:
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 to the directory that contains yourpubspec.yamlfile relative to yourxcodeprojfile.FLUTTER_BUILD_MODE: Whether to build fordebug,profile, orrelease. Defaults torelease.FLUTTER_TARGET: The path to yourmain.dartrelative to yourpubspec.yaml. Defaults tolib/main.dart.FLUTTER_FRAMEWORK_DIR: The absolute path to the directory that containsFlutter.framework. Defaults to theios-releaseversion ofFlutter.frameworkin thebin/cachedirectory of the Flutter SDK.
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]
There are a number of other parameters you can control with this file:
flutter.buildMode: Whether to build fordebug,profile, orrelease. Defaults torelease.flutter.jar: The path toflutter.jar. Defaults to theandroid-arm-releaseversion offlutter.jarin thebin/cachedirectory of the Flutter SDK.
See android/app/build.gradle for project specific settings, including:
source: The path to the directory that contains yourpubspec.yamlfile relative to yourbuild.gradlefile.target: The path to yourmain.dartrelative to yourpubspec.yaml. Defaults tolib/main.dart.
Build
To build directly with gradle, use the following commands:
cd androidgradle wrapper./gradlew build
To build with Android Studio, open the android folder in Android Studio and
build the project as usual.