【发布时间】:2021-03-02 18:50:59
【问题描述】:
我正在开发一个具有 3 年以上 Kotlin 开发经验的 Android 应用,并希望逐步将其逐个功能迁移到 Flutter。我使用“add 2 app”集成的option B,我依赖于模块的源代码。 Flutter 编写的功能通过FlutterActivity 或FlutterFragment 集成到原生Android 应用程序中。这对第一个功能非常有用,但是现在我在迁移第二个功能时遇到了问题。第二个功能需要包camera 和firebase_ml_vision。现在的问题是camera 要求最小 SDK 为 21,但在.android 中生成的 Android 代码将最小 SDK 设置为 16。此外,firebase_ml_vision 需要初始化 Firebase,这也需要添加到 .android。我正在考虑将.android 添加到VCS 并添加所需的更改,但是这是生成的代码。当flutter clean 被调用并在flutter pub get 上生成时,它会被删除。当 Flutter 更改/删除它时,我必须不断调整生成的代码:(.android 仅托管从 IDE(或命令行)运行 Flutter 项目时启动的“骨架”Android 应用程序。它不是主机已配置 Firebase 的应用程序(旧的本机应用程序)。但是,.android 应用程序用于快速开发周期。如果由于上述限制我不能再使用它,我总是必须启动本机 Android 应用程序(主机) 并失去了 Flutter 的许多好处,例如热重载 :( 有没有人遇到过同样的问题?
更新:
在this article 中,他们明确指出不应修改.android 或将其添加到VCS。他们甚至以camera 模块为例。但是,这不起作用,只需几个简单的步骤即可重现:
- 创建一个新模块:
flutter create --template=module --project-name example cd example- 将
camera插件添加到pubspec.yaml flutter pub get- 现在运行
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)
【问题讨论】:
-
你有没有试过把安卓应用的
build.gradle(Module: app)上的minSdk改成21然后重新生成? -
@Ferdinand 你能解释一下“android 应用的 build.gradle”是什么意思吗?只有一个
.android文件夹被删除并在flutter clean && flutter pub get上生成。 -
你说你有2个应用,第一个是用kotlin写的,第二个是用flutter写的,我的意思是你在kotlin上改一下,然后重新生成文件。
-
@Ferdinand Android 应用程序已经在 minSDK 21 上,甚至在我添加 Flutter 模块之前。该值对生成的
.android文件夹没有影响,因为 Flutter 模块不知道 Android 应用程序。 Android 应用包含该模块,而不是相反。 -
@SvenJacobs 根据您的屏幕截图,您可以使用 tools:overrideLibrary="io.flutter.plugins.camera" 强制使用(可能导致运行时失败)否则尝试在 Kotllin 中移动所有 camara 类型代码