我试图为一个使用蓝牙进行通信的应用程序启动一个flutter项目。为此,我使用了flutter blue。
不幸的是,当尝试(在Android设备上)运行我创建的第一个示例时,遇到了以下错误:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:flutter_blue] /home/maldus/Projects/flutter/polmac/build/flutter_blue/intermediates/manifests/full/debug/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 19,
or use tools:overrideLibrary="com.pauldemarco.flutterblue" to force usage (may lead to runtime failures)
如果我在Android Studio上,我会知道如何升级Android minSdkVersion,但在一个扑朔迷离的项目(使用VSCode)上,我有点迷失了。
是否有可能用颤振来增加最小Sdk版本,以及如何增加?
确实可以增加minSdkVersion,但我花了太多时间才找到它,因为谷歌搜索的结果大多是关于Sdk版本颤振绝对最小值的讨论,而不是如何在您自己的项目中增加它。
就像在Android Studio项目中一样,您必须编辑< code>build.gradle文件。在flutter项目中,它位于路径< code >。/Android/app/build . gradle 。
当然,需要更改的参数是minSdkVersion16
,使其达到您需要的程度(在本例中为19)。
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.projectname"
minSdkVersion 19 //*** This is the part that needs to be changed, previously was 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
现在看起来很明显,但我花了足够长的时间自己弄清楚。
颤振2.8或更高版本
构建。渐变
更新
更新到飘飘 2.8 之前
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
更新到Flutter 2.8后:
android {
compileSdkVersion flutter.compileSdkVersion
defaultConfig {
applicationId "com.example.app"
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
应按照说明从本地属性
进行更改:
android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()
defaultConfig {
minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
如果你不知道,谷歌Play商店只允许minSdk版本是20或更高。但颤抖仍然将默认的 minSdk 版本设置为 16。你能看到你总是有义务为每个新项目手动更改吗?
你上面所有的建议都是好的,但不是最好的,因为你创建的每个新项目都会被迫build.gradle。
最好的方法是从源代码修改全局minSdkVersion变量的值,以便所有项目,无论是新项目还是旧项目,都将采用它。记住颤动。minSdkVersion意味着变量位于flutter目录中(带有sdk)。
有问题的文件是flatter.gradle。
地址是flutter-directory/packages/flutter _ tools/gradle/flutter . gradle
class FlutterExtension {
/** Sets the compileSdkVersion used by default in Flutter app projects. */
static int compileSdkVersion = 31
/** Sets the minSdkVersion used by default in Flutter app projects. */
static int minSdkVersion = 16
/** Sets the targetSdkVersion used by default in Flutter app projects. */
static int targetSdkVersion = 31
将minSdkVersion的值从16更改为20或更高,不要干扰build.gradle中的代码。
如果你愿意,你可以观看我在Youtube上制作的视频,并在以下位置进行解释:颤动配置minSdkVersion从16到20或更高版本