本文介绍了Flutter Android SDK版本28错误,但我正在使用30的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我创建一个新的flutter应用程序时,它将启动android sdk版本28,但我使用的是android sdk 30.Flutter医生还展示了Android平台-30,构建工具30.0.2.当我尝试安装url_launcher或shared_preferences之类的软件包时,出现错误,它查找的是Android SDK 30.同样,每次我从build.gradle更改android sdk verison时.

When I create a new flutter app, It starts android sdk version 28 but I use android sdk 30.Flutter doctor also shows Platform android-30, build-tools 30.0.2. When I tried to install a package like url_launcher or shared_preferences I am getting error It looks for Android sdk 30.Also every time I am changing android sdk verison from build.gradle.

这是我扑扑的医生的输出:

Here is My flutter doctor output:

flutter doctor -v
[✓] Flutter (Channel stable, 1.22.0, on Linux, locale en_US.UTF-8)
    • Flutter version 1.22.0 at /home/felix/snap/flutter/common/flutter
    • Framework revision d408d302e2 (7 days ago), 2020-09-29 11:49:17 -0700
    • Engine revision 5babba6c4d
    • Dart version 2.10.0


[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at /home/felix/Android/Sdk
    • Platform android-30, build-tools 30.0.2
    • Java binary at: /home/felix/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6626763/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[!] Android Studio (version 4.0)
    • Android Studio at /home/felix/.local/share/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6626763
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593

)

网址启动器程序包错误:

Url launcher package error :

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':url_launcher:parseDebugLibraryResources'.
> Could not resolve all files for configuration ':url_launcher:androidApis'.
   > Failed to transform file 'android.jar' to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}
      > Execution failed for PlatformAttrTransform: /home/computer/Android/Sdk/platforms/android-28/android.jar.
         > /home/computer/Android/Sdk/platforms/android-28/android.jar (No such file or directory)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

异常:Gradle任务assembleDebug失败,退出代码为1

Exception: Gradle task assembleDebug failed with exit code 1

我的build.gradle文件

My build.gradle file

    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 30

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

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.appdeals"
        minSdkVersion 16
        targetSdkVersion 30
        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"
}

shared_preferences错误:

shared_preferences error :

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':shared_preferences:parseDebugLibraryResources'.
> Could not resolve all files for configuration ':shared_preferences:androidApis'.
   > Failed to transform file 'android.jar' to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}
      > Execution failed for PlatformAttrTransform: /home/computer/Android/Sdk/platforms/android-28/android.jar.
         > /home/computer/Android/Sdk/platforms/android-28/android.jar (No such file or directory)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org

BUILD FAILED in 8s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)

推荐答案

尝试一下,

minSdkVersion 16
compiledSdkVersion 28
targetSdkVersion 29

这篇关于Flutter Android SDK版本28错误,但我正在使用30的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 01:54