Including a Flutter module in a native Android app is a powerful way to integrate Flutter's UI capabilities into an existing Android project. However, correctly handling ABI (Application Binary Interface) filters is important to ensure your native app is only built for the architectures that Flutter supports. Let’s go through the key concepts and practical steps involved.
🔍 What are ABI Filters?
ABI filters in Android tell Gradle to build only for specific processor architectures. Common architectures:
- armeabi-v7a (32-bit ARM)
- arm64-v8a (64-bit ARM)
- x86 (32-bit Intel)
- x86_64 (64-bit Intel)
⚠️ x86 and x86_64 are only supported in the emulator. Flutter does not support mips or mips64. If you build your Android app for unsupported ABIs, your app might crash or the Flutter module might fail to load. e.g. https://github.com/flutter/flutter/issues/169192
🛠️ How to Define ABI Filters in Android
In your native Android app, open build.gradle (usually app/build.gradle), and add the following under the android block:
android {
...
defaultConfig {
...
ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
// Optional: for productFlavors
// productFlavors {
// demo {
// ndk {
// abiFilters 'armeabi-v7a', 'arm64-v8a'
// }
// }
// }
// Optional: For packaging multiple APKs manually
// splits {
// abi {
// enable true
// reset()
// include 'armeabi-v7a', 'arm64-v8a'
// universalApk false
// }
// }
}
📦 Flutter Module ABI Considerations
When you integrate a Flutter module (added via flutter create -t module flutter_module and linked via settings.gradle), Flutter precompiles native libraries for supported ABIs. You must match those in your native build config. You can check what ABIs are built by Flutter:
flutter build aar
This generates AARs under build/host/outputs/repo containing native .so files for each supported ABI.
📘 Resources for Deeper Learning
No comments:
Post a Comment