Android Studio flutter构建错误-在虚拟移动终端上运行时出错

huwehgph  于 2023-02-16  发布在  Android
关注(0)|答案(1)|浏览(105)

当在移动的环境中构建时,会出现错误。Google Chrome做得很好。然而,当在Pixel 4 API 30(移动)上运行时,会出现错误。

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':path_provider_android:parseDebugLocalResources'.
> Could not resolve all files for configuration ':path_provider_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-31\android.jar.
         > C:\Users\user\AppData\Local\Android\Sdk\platforms\android-31\android.jar

* 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 6s
Exception: Gradle task assembleDebug failed with exit code 1

jdk版本

应用程序构建.gralde

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 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

build.gralde

buildscript {
    ext.kotlin_version = '1.6.10'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.2'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我已将Android Studio更新至最新版本
我安装了jdk并添加了sdk 11。
我已在新文件夹中创建了一个项目。

我已经想了两天这扇门,但我没有解决它。
如果你对我的提问方法或代码有问题,请随时告诉我。

ssgvzors

ssgvzors1#

尝试此解决方案
〈项目文件/android/应用程序/build.gradle〉(应用程序级别)

compileSdkVersion 31

以及

defaultConfig {
    minSdkVersion 16
    targetSdkVersion 31
           ...        
  }

在build.gradle中〈项目文件/android/build.gradle〉(项目级别):

dependencies {
        classpath 'com.android.tools.build:gradle:7.0.1'
    }

相关问题