我正在尝试为一个使用蓝牙通信的应用程序启动一个颤振项目。我用的是颤振蓝。
不幸的是,当试图运行(在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,但在一个flutter项目(使用VSCode),我有点迷失。
是否有可能增加minSdkVersion与颤振,以及如何?
如果你不知道,谷歌Playstore只允许minSdkVersion为20或以上。但是flutter仍然将默认minSdkVersion设置为16。您是否看到您将总是被迫为每个新项目手动更改?
以上所有建议都很好,但不是最好的,因为您将被迫调整构建。为你创建的每个新项目Gradle。
最好的方法是从全局minSdkVersion变量的源修改它的值,这样所有的项目,无论是新项目还是旧项目,都将采用它。记得颤振。minSdkVersion表示变量在flutter目录下(包含sdk)。
问题文件是flutter.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或以上
2.8或以上
构建。gradle更新
在更新到Flutter 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->local.properties
从这里开始变化
像这样改变build.gradle
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
}
添加以下行到android/local。属性文件:
flutter.versionCode=1
flutter.versionName=0.0.1
flutter.flutterMinSdkVersion=24
flutter.flutterTargetSdkVersion=31
在android/app/build.gradle文件的"def versionName ="后面添加以下代码行:
def flutterMinSdkVersion = localProperties.getProperty('flutter.flutterMinSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '16'
}
def flutterTargetSdkVersion = localProperties.getProperty('flutter.flutterTargetSdkVersion')
if (flutterMinSdkVersion == null) {
flutterMinSdkVersion = '31'
}
最后编辑构建的部分。Gradle匹配如下:
defaultConfig {
applicationId "do.main.subdomain" // Use your App ID
minSdkVersion flutterMinSdkVersion.toInteger()
targetSdkVersion flutterTargetSdkVersion.toInteger()
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
一旦所有这些都完成了,你就可以开始了。下次你想要更新一些东西时,你只需要更改一个文件。