我正在尝试为一个使用蓝牙通信的应用程序启动一个颤振项目。我用的是颤振蓝。

不幸的是,当试图运行(在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与颤振,以及如何?


当前回答

改变的地方。下面提到的属性文件..因为目前游戏商店更新最低目标API版本至少30

sdk.dir=/Users/sweetnandha/Library/Android/sdk
flutter.sdk=/Users/sweetnandha/FlutterDev/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.compileSdkVersion=32
flutter.minSdkVersion=21
flutter.targetSdkVersion=32

or

其他回答

我在我的flutter应用程序中设置Auth0、flutter_appauth和flutter_secure_storage时遇到了这个问题。在更改minSdkVersion版本后,我得到了这个错误

C:\Users\myusername\AndroidStudioProjects\wole\android\app\src\debug\AndroidManifest.xml Error:
    Attribute data@scheme at AndroidManifest.xml requires a placeholder substitution but no value for <appAuthRedirectScheme> is provided.
FAILURE: Build failed with an exception.

问题出在哪里: 任务“:app:processDebugManifest”执行失败。

清单合并失败:AndroidManifest.xml中的属性data@scheme需要占位符替换,但没有提供for的值。

解决方案就是这样添加manifest占位符

从Flutter 2.8开始,设置minSdkVersion, targetSdkVersion和compileSdkVersion略有不同。现在gradle文件在your_flutter_app/android/app/build。Gradle路径是这样的:

只需将当前值替换为您想要的版本号,如下所示:

现在运行你的颤振项目,就这样。

这里详细的解决MinSdk / MinSdk版本错误的方法,按照下面的步骤进行。

在android\local.properties中添加以下行

sdk.dir=
flutter.sdk=C:\\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1

flutter.minSdkVersion=21
flutter.targetSdkVersion=31
flutter.compileSdkVersion=31

删除现有的行,并将其粘贴到应用程序级别构建。gradle: android \ app \ build.gradle

       defaultConfig {
        applicationId "app-id"

        minSdkVersion localProperties.getProperty('flutter.minSdkVersion').toInteger()
        targetSdkVersion localProperties.getProperty('flutter.targetSdkVersion').toInteger()
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
}

改变的地方。下面提到的属性文件..因为目前游戏商店更新最低目标API版本至少30

sdk.dir=/Users/sweetnandha/Library/Android/sdk
flutter.sdk=/Users/sweetnandha/FlutterDev/flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.compileSdkVersion=32
flutter.minSdkVersion=21
flutter.targetSdkVersion=32

or

如果你不知道,谷歌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或以上