Flutter“任务'执行失败:shared_preferences_android:parseDebugLocalResources'”调试失败

问题描述 投票:0回答:1

我正在开发一个Android应用程序,当我安装SharedPreferences包(甚至没有使用)并尝试在chrome上调试该应用程序时,它运行正常,但是当我在我的设备(三星Galaxy S10)或在android studio 模拟器抛出以下错误:

* What went wrong:
Execution failed for task ':shared_preferences_android:parseDebugLocalResources'.
> Could not resolve all files for configuration ':shared_preferences_android:androidApis'.
   > Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
      > Execution failed for PlatformAttrTransform: C:\Users\User\AppData\Local\Android\sdk\platforms\android-33\android.jar.
         > C:\Users\User\AppData\Local\Android\sdk\platforms\android-33\android.jar

这是我的build.gradle(我将SdkVersion固定为34,否则它根本无法运行)


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 {
    namespace "com.example.movie_night"
    compileSdkVersion 34
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    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.movie_night"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion 34
        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"
}

这是我的 pubsec.yaml 依赖项:

environment:
  sdk: '>=3.0.5 <4.0.0'

dependencies:
  flutter:
    sdk: flutter

  uuid: ^3.0.6
  provider: ^6.0.0
  dio: ^5.3.1
  flutter_launcher_icons: ^0.13.1
  shared_preferences: ^2.2.0

我已经尝试运行

flutter clean && flutter pub get && flutter run
,但也不起作用。

P.S.:我使用Windows作为SO(不知道它是否会影响某些东西)

flutter dart gradle package sharedpreferences
1个回答
0
投票

我找到解决方法了!

虽然将SDK版本设置为34,但它正在搜索SDK版本33的文件,所以我去

C:\Users\User\AppData\Local\Android\Sdk\platforms\android-34
复制了
android.jar
并将其粘贴到
C:\Users\User\AppData\Local\Android\Sdk\platforms\android-33
中。

再次调试时,一切正常

© www.soinside.com 2019 - 2024. All rights reserved.