text
stringlengths
1
474
You can also build an AAR for your Flutter module in Android Studio using
the Build > Flutter > Build AAR menu.<topic_end>
<topic_start>Depend on the module’s source code
This option enables a one-step build for both your
Android project and Flutter project. This option is
convenient when you work on both parts simultaneously
and rapidly iterate, but your team must install the
Flutter SDK to build the host app.lightbulb Tip
By default, the host app provides the :app Gradle project.
To change the name of this project, set
flutter.hostAppProjectName in the Flutter module’s
gradle.properties file.
Include this project in the host app’s settings.gradle file.Include the Flutter module as a subproject in the host app’s
settings.gradle. This example assumes flutter_module and MyApp
exist in the same directory
<code_start>// Include the host app project.
include ':app' // assumed existing content
setBinding(new Binding([gradle: this])) // new
evaluate(new File( // new
settingsDir.parentFile, // new
'flutter_module/.android/include_flutter.groovy' // new
)) // new<code_end>
The binding and script evaluation allows the Flutter
module to include itself (as :flutter) and any
Flutter plugins used by the module (such as :package_info and :video_player)
in the evaluation context of your settings.gradle.Introduce an implementation dependency on the Flutter
module from your app:
<code_start>dependencies {
implementation project(':flutter')
}<code_end>
Your app now includes the Flutter module as a dependency.Continue to the Adding a Flutter screen to an Android app guide.
<topic_end>
<topic_start>Add a Flutter screen to an Android app
This guide describes how to add a single Flutter screen to an
existing Android app. A Flutter screen can be added as a normal,
opaque screen, or as a see-through, translucent screen.
Both options are described in this guide.<topic_end>
<topic_start>
Add a normal Flutter screen
<topic_end>
<topic_start>
Step 1: Add FlutterActivity to AndroidManifest.xml
Flutter provides FlutterActivity to display a Flutter
experience within an Android app. Like any other Activity,
FlutterActivity must be registered in your
AndroidManifest.xml. Add the following XML to your
AndroidManifest.xml file under your application tag:The reference to @style/LaunchTheme can be replaced
by any Android theme that want to apply to your FlutterActivity.
The choice of theme dictates the colors applied to
Android’s system chrome, like Android’s navigation bar, and to
the background color of the FlutterActivity just before
the Flutter UI renders itself for the first time.<topic_end>
<topic_start>
Step 2: Launch FlutterActivity
With FlutterActivity registered in your manifest file,
add code to launch FlutterActivity from whatever point
in your app that you’d like. The following example shows
FlutterActivity being launched from an OnClickListener.info Note
Make sure to use the following import:
<code_start>myButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(
FlutterActivity.createDefaultIntent(currentActivity)
);
}
});<code_end>
<code_start>myButton.setOnClickListener {
startActivity(
FlutterActivity.createDefaultIntent(this)
)
}<code_end>
The previous example assumes that your Dart entrypoint
is called main(), and your initial Flutter route is ‘/’.
The Dart entrypoint can’t be changed using Intent,
but the initial route can be changed using Intent.
The following example demonstrates how to launch a
FlutterActivity that initially renders a custom
route in Flutter.
<code_start>myButton.addOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivity(
FlutterActivity
.withNewEngine()
.initialRoute("/my_route")
.build(currentActivity)
);
}
});<code_end>
<code_start>myButton.setOnClickListener {
startActivity(
FlutterActivity
.withNewEngine()
.initialRoute("/my_route")
.build(this)
)
}<code_end>
Replace "/my_route" with your desired initial route.The use of the withNewEngine() factory method
configures a FlutterActivity that internally create