android {
//...
defaultConfig {
ndk {
// Filter for architectures supported by Flutter.
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64'
}
}
}
android {
//...
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
1. Open <host>/app/build.gradle
2. Ensure you have the repositories configured, otherwise add them:
repositories {
maven {
url '/Users/huangyuanhao/StudioProjects/flutter_module/build/host/outputs/repo'
}
maven {
url 'http://download.flutter.io'
}
}
3. Make the host app depend on the Flutter module:
dependencies {
debugImplementation 'com.superpentagon.fluttermodule:flutter_debug:1.0
profileImplementation 'com.superpentagon.fluttermodule:flutter_profile:1.0
releaseImplementation 'com.superpentagon.fluttermodule:flutter_release:1.0
}
4. Add the `profile` build type:
android {
buildTypes {
profile {
initWith debug
}
}
}
maven {
url 'https://mirrors.tuna.tsinghua.edu.cn/flutter/download.flutter.io'
}
// 初始化 Flutter
FlutterMain.Settings settings=new FlutterMain.Settings();
settings.setLogTag("MyFlutter");
FlutterMain.startInitialization(this,settings);
String[] args = {"info", "data"};
FlutterMain.ensureInitializationComplete(this,args);
// 初始化 FlutterEngine.
FlutterEngine flutterEngine = new FlutterEngine(this);
// Configure an initial route.
flutterEngine.getNavigationChannel().setInitialRoute(FlutterEngineUtils.Home.HOME_PAGE_ROUTE + "?{\"message\":\"StephenCurry\"}");
// Start executing Dart code to pre-warm the FlutterEngine.
flutterEngine.getDartExecutor().executeDartEntrypoint(
DartExecutor.DartEntrypoint.createDefault()
);
// Cache the FlutterEngine to be used by FlutterActivity or FlutterFragment.
FlutterEngineCache
.getInstance()
.put(FlutterEngineUtils.Home.HOME_PAGE_ROUTE, flutterEngine);
FlutterOperationUtil.init().initFragmentById(FlutterEngineUtils.Home.HOME_PAGE_ROUTE).initLayoutId(R.id.main_container).startFlutterTransation(getSupportFragmentManager());
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<FrameLayout
android:id="@+id/main_container"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</LinearLayout>