Unverified Commit c05c3d39 authored by Donghyun Kim's avatar Donghyun Kim Committed by GitHub

Use Flutter app project's NDK version from FFI plugin (#131141)

<img width="1119" alt="image" src="https://github.com/flutter/flutter/assets/66480156/e2e8eed1-3bef-436c-b21f-3891bdbe05bb">

In most cases, a FFI plugin doesn't need its own specific Android NDK version. Just following the Flutter app project's NDK version is enough.

If a Flutter app project depends on multiple FFI plugins that use different Android NDK versions, it can be quite wasteful and use excessive disk space due to multiple NDK installations.

Using Flutter app project's NDK version is also less error-prone because upgrading the Flutter SDK would be enough when upgrading FFI plugins(If project's `ndkVersion` is `flutter.ndkVersion`), without messing with Android NDK installations.

This problem was discussed in some actual FFI plugin repositories, and they are striving to find their own solutions:
- https://github.com/superlistapp/super_native_extensions/issues/143#issuecomment-1646207706
- https://github.com/cunarist/rust-in-flutter/discussions/60#discussioncomment-6484218
- https://github.com/rive-app/rive-flutter/issues/320
- https://github.com/juicycleff/flutter-unity-view-widget/issues/832
parent f43755d3
...@@ -33,9 +33,11 @@ android { ...@@ -33,9 +33,11 @@ android {
// to bump the version in their app. // to bump the version in their app.
compileSdkVersion {{compileSdkVersion}} compileSdkVersion {{compileSdkVersion}}
// Bumping the plugin ndkVersion requires all clients of this plugin to bump // Use the NDK version
// the version in their app and to download a newer version of the NDK. // declared in /android/app/build.gradle file of the Flutter project.
ndkVersion "{{ndkVersion}}" // Replace it with a version number if this plugin requires a specfic NDK version.
// (e.g. ndkVersion "23.1.7779620")
ndkVersion android.ndkVersion
// Invoke the shared CMake build with the Android Gradle Plugin. // Invoke the shared CMake build with the Android Gradle Plugin.
externalNativeBuild { externalNativeBuild {
......
...@@ -46,7 +46,7 @@ void main() { ...@@ -46,7 +46,7 @@ void main() {
final String pluginBuildGradle = pluginGradleFile.readAsStringSync(); final String pluginBuildGradle = pluginGradleFile.readAsStringSync();
// Bump up plugin ndkVersion to 21.4.7075529. // Bump up plugin ndkVersion to 21.4.7075529.
final RegExp androidNdkVersionRegExp = RegExp(r'ndkVersion (\"[0-9\.]+\"|flutter.ndkVersion)'); final RegExp androidNdkVersionRegExp = RegExp(r'ndkVersion (\"[0-9\.]+\"|flutter.ndkVersion|android.ndkVersion)');
final String newPluginGradleFile = pluginBuildGradle.replaceAll(androidNdkVersionRegExp, 'ndkVersion "21.4.7075529"'); final String newPluginGradleFile = pluginBuildGradle.replaceAll(androidNdkVersionRegExp, 'ndkVersion "21.4.7075529"');
expect(newPluginGradleFile, contains('21.4.7075529')); expect(newPluginGradleFile, contains('21.4.7075529'));
pluginGradleFile.writeAsStringSync(newPluginGradleFile); pluginGradleFile.writeAsStringSync(newPluginGradleFile);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment