【问题标题】:Flutter Android SDK version 28 Error but I am using 30Flutter Android SDK 版本 28 错误,但我使用的是 30
【发布时间】:2021-01-21 04:52:22
【问题描述】:

当我创建一个新的颤振应用程序时,它启动了 android sdk 版本 28,但我使用的是 android sdk 30。 Flutter Doctor 还展示了 Platform android-30, build-tools 30.0.2。当我尝试安装 url_launcher 或 shared_preferences 之类的软件包时,出现错误它正在寻找 Android sdk 30。 此外,每次我从 build.gradle 更改 android sdk 版本时。

这是我的颤振医生输出:

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

)

网址启动程序包错误:

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

我的 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 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 错误:

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)

【问题讨论】:

    标签: android flutter visual-studio-code android-sdk-2.3


    【解决方案1】:

    试试这个,

    minSdkVersion 16
    compileSdkVersion 28
    targetSdkVersion 29
    

    【讨论】:

    • 应该是 compileSdkVersion 而不是“compiledSdkVersion”,但对我有用
    【解决方案2】:

    在你的根项目的终端试试这个:

    flutter pub upgrade
    

    然后

    flutter clean
    

    然后再次运行您的项目。

    【讨论】:

      猜你喜欢
      • 2021-10-21
      • 1970-01-01
      • 2019-08-08
      • 1970-01-01
      • 2021-05-11
      • 1970-01-01
      • 2018-04-10
      • 2021-11-29
      • 1970-01-01
      相关资源
      最近更新 更多