Make sure the project uses or supports androidX before integration. ——Suggestions from those who have experienced it! ! !
If you haven't migrated to androidX yet, someone who has been here will also share some experience of migrating androidX with you, hoping to help you
Start integrating flutter_boost
1. Introduce module, create manually, step by step, write by yourself
a. Enter the command line in Terminal
flutter create -t module flutter_module
Pay attention to the location you need to store, you can cd to the upper level directory and create it again, the operation is similar to switching the drive letter
b. Then open the flutter module you created, first find pubspec.yaml and then get the packages, you can run the flutter module you created first
c. Find these four files in the native android project
aa, first add in gradle.properties
android.useAndroidX=true
android.enableJetifier=true
Of course, if you already support the two lines of androidx, there must be
bb, add in settings.gradle
setBinding(new Binding([gradle: this]))
evaluate(new File(
settingsDir,
'../你的module/.android/include_flutter.groovy'
))
include ':你的module名'
project(':你的module名').projectDir = new File('../你的module名')
cc, add in the app's build.gradle
implementation project(path: ':flutter')
implementation project(path: ':flutter_boost')
dd. Initialize flutter_boost in the application. For details, please refer to the official flutter_boost
INativeRouter router = new INativeRouter() {
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
String assembleUrl = Utils.assembleUrl(url, urlParams);
PageRouter.openPageByUrl(context, assembleUrl, urlParams);
}
};
FlutterBoost.BoostLifecycleListener boostLifecycleListener = new FlutterBoost.BoostLifecycleListener() {
@Override
public void beforeCreateEngine() {
}
@Override
public void onEngineCreated() {
// 注册MethodChannel,监听flutter侧的getPlatformVersion调用
methodChannel = new MethodChannel(FlutterBoost.instance().engineProvider().getDartExecutor(), PageRouter.METHOD_CHANNEL);
FlutterUtils.setMethodCallHandler(mInstance, methodChannel);
// 注册PlatformView viewTypeId要和flutter中的viewType对应
FlutterBoost
.instance()
.engineProvider()
.getPlatformViewsController()
.getRegistry()
.registerViewFactory("plugins.test/view", new TextPlatformViewFactory(StandardMessageCodec.INSTANCE));
}
@Override
public void onPluginsRegistered() {
}
@Override
public void onEngineDestroy() {
}
};
Platform platform = new FlutterBoost
.ConfigBuilder(this, router)
.isDebug(true)
.whenEngineStart(FlutterBoost.ConfigBuilder.ANY_ACTIVITY_CREATED)
.renderMode(FlutterView.RenderMode.texture)
.lifecycleListener(boostLifecycleListener)
.build();
FlutterBoost.instance().init(platform);
ee, register in AndroidManifest.xml
<activity
android:name="com.idlefish.flutterboost.containers.BoostFlutterActivity"
android:theme="@style/Theme.AppCompat"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize" >
<!--页面加载loading图-->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@mipmap/你想要的过渡图片"/>
</activity>
<meta-data android:name="flutterEmbedding"
android:value="2"/>
2. If you have reached the sky in one step, and someone else has written something about flutter and you need to import it directly, then you can import it as a module, and the four files need to be matched correctly ! ! !
3. If you are co-developing and others have put the flutter module project in git or svn, then you first create the module manually, then paste the .git or .svn file into the manually created module, open the project, and pull Check the file, get it again, and you’re basically done. If it doesn’t work, just paste lib, .yaml and assets in, but the four files need to be matched correctly! ! ! ! ! !