Flutter“添加 2 个应用程序”Android 集成,并调整生成的 .android

Sve*_*obs 7 android flutter

我正在开发具有 3 年以上 Kotlin 开发经验的 Android 应用程序,并希望逐步将其迁移到 Flutter 功能。我使用“添加 2 个应用程序”集成的选项 B,其中我依赖于模块的源代码。Flutter 编写的功能通过FlutterActivity或集成到原生 Android 应用程序中FlutterFragment。这对第一个功能很有用,但是现在我在迁移第二个功能时遇到了问题。第二个功能需要包camerafirebase_ml_vision. 现在的问题是camera需要最小 SDK 为 21,但生成的 Android 代码.android将最小 SDK 设置为 16。另外firebase_ml_vision需要初始化 Firebase,这也需要添加到.android. 我正在考虑添加.android到 VCS 并添加所需的更改,但这是生成的代码。它在flutter clean被调用和生成时被删除flutter pub get。当 Flutter 更改/删除它时,我将不得不不断调整生成的代码:(.android仅托管在 Flutter 项目从 IDE(或命令行)运行时启动的“骨架”Android 应用程序。它不是主机应用程序(旧的原生应用程序),其中已经配置了 Firebase。但是,该.android应用程序用于快速开发周期。如果由于上述限制我无法再使用它,我将始终必须启动原生 Android 应用程序(主机)并失去许多好处Flutter 像热重载 :( 有没有人遇到过同样的问题?

更新:

本文中,他们明确指出.android不应修改或添加到 VCS。他们甚至以该camera模块为例。但是,这不起作用,可以通过几个简单的步骤重现:

  1. 创建一个新模块: flutter create --template=module --project-name example
  2. cd example
  3. 添加camera插件到pubspec.yaml
  4. flutter pub get
  5. 现在运行flutter build apk导致以下错误:
/Users/sven/Development/example/.android/app/src/main/AndroidManifest.xml Error:
        uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] /Users/sven/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/build/intermediates/library_manifest/release/AndroidManifest.xml as the library might be using APIs not available in 16
        Suggestion: use a compatible library with a minSdk of at most 16,
                or increase this project's minSdk version to at least 21,
                or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processReleaseManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] /Users/sven/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/build/intermediates/library_manifest/release/AndroidManifest.xml as the library might be using APIs not available in 16
        Suggestion: use a compatible library with a minSdk of at most 16,
                or increase this project's minSdk version to at least 21,
                or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)
Run Code Online (Sandbox Code Playgroud)

Mr *_*dom -3

android/app/build.gradleminSdkVersion 更改为 21