google_maps_flutter Flutter 版本 2.10.2 损坏

google_maps_flutter broken with Flutter version 2.10.2

我在我的 flutter 应用程序中使用了 google_maps_flutter,但是当我将 flutter 更新到版本 2.10.2 时,这已经破坏了版本。

The plugin google_maps_flutter requires a higher Android SDK version.                         │
│ Fix this issue by adding the following to the file                                            │
│ C:\Users\howle\Documents\GitHub\TicketDistribution\android\app\build.gradle:                  │
│ android {                                                                                     │
│   defaultConfig {                                                                             │
│     minSdkVersion 20                                                                          │
│   }                                                                                           │
│ }                                                                                             │
│                                                                                               │
│ Note that your app won't be available to users running Android SDKs below 20.                 │
│ Alternatively, try to find a version of this plugin that supports these lower versions of the │
│ Android SDK.  

我按照更改版本的步骤进行操作,但似乎没有用,所以我想知道是否有其他开发人员面临此问题或有解决方案?

我会把我的 build.gradle 和 localproperties 文件放在下面。 app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion flutter.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 20
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.ticket_distribution_app"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

local.properties

sdk.dir=C:\Users\howle\AppData\Local\Android\sdk
flutter.sdk=C:\flutter
flutter.buildMode=debug
flutter.versionName=1.0.0
flutter.versionCode=1
flutter.minSdkVersion=20
flutter.targetSdkVersion=20

开发者提前干杯

使用此代码更新您的 android -> 应用 -> build.gradle 文件,从 androidbuildTypes 以上。 compileSdkVersion 将是正在编译应用程序的 android 版本。 minSdkVersion 适用于您的应用可以兼容的最低 android 版本。大多数情况下,现在包需要 21 作为 minSdk,所以将它设置为 21,但是 20 它现在应该也可以工作,因为你也缺少 multidex 并且包含一些用于 运行 应用程序的代码。

android {
          
compileSdkVersion 30

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    jvmTarget = '1.8'
}

sourceSets {
    main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
    applicationId "com.example.ticket_distribution_app"
    minSdkVersion 21
    multiDexEnabled true
    targetSdkVersion 30
    versionCode 1
    versionName "1.0.0"
}

注意:确保您使用的是 flutter 2.10.0-2.10.2 然后将 compileSdkVersion 更改为 31