简体   繁体   中英

Add Flutter module to native Android app via standalone .aar file

I am trying to add a Flutter Module to a native Android app via an .aar file.

I followed the steps here: https://flutter.dev/docs/development/add-to-app/android/project-setup

I create a new Android project. I also created a new Flutter Module independently (different location and IDE project outside of the Android project). Then I built an .aar via flutter build aar of the module. Then I created a module from that .aar file in the Android project.

Unfortunately, I can not get it to work. After adding the aar module, I can not access FlutterActivity , FlutterEngine etc. Only FlutterFragment and Flutter under io.flutter.facade are available. I can not see the io.flutter.embedding package.

IDE 截图

Apparently, the Flutter dependencies are not included in the .aar archive. I tried various "fat aar" build scripts. No success. Also, as I understand, the described approach with the flutter build aar should contain all necessary Flutter dependencies, right?

Some people seem to got it to work. Unfortunately, there is no example project or specific help about the .aar approach anywhere.

Can someone help?

Add this in your AndroidManifest.xml

<activity
android:name="io.flutter.embedding.android.FlutterActivity"
android:theme="@style/LaunchTheme"  android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize"/>

Refer this below link

https://flutter.dev/docs/development/add-to-app/android/add-flutter-screen?tab=custom-activity-launch-kotlin-tab

This might help you.

You're right, AAR should contain all dependencies so from the native side, you don't need to do any extra steps, maybe you missing include one of them

maven {
    url "$project.rootDir/../duy_flutter_module/build/host/outputs/repo"
}
maven {
    url 'http://download.flutter.io'
}

remember that if your android native project has 2 modules, app and second module (contain an activity host your Flutter), your need to add AAR to both modules or add to build.gradle root inside allprojects block. You can refer to here https://github.com/duytq94/demo-integrate-flutter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM