flutter 构建错误 - 在虚拟移动设备上运行时出错

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

在移动环境中构建时,出现错误。 谷歌浏览器做得对。但是,在 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。

我已在新文件夹中创建了一个项目。

这个门我想了两天了,就是解决不了。

如果您对我的提问方法或代码有疑问,请随时告诉我。

flutter android-studio build
2个回答
2
投票

尝试这个解决方案

在 build.gradle (应用程序级别)

compileSdkVersion 31

   defaultConfig {
    minSdkVersion 16
    targetSdkVersion 31
           ...        
  }

在 build.gradle (项目级别):

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

0
投票

我也有同样的问题。固定了吗?你能帮我吗?

FAILURE:构建失败并出现异常。

  • 出了什么问题: 任务“:path_provider_android:parseDebugLocalResources”执行失败。

无法解析配置“:path_provider_android:androidApis”的所有文件。 无法转换 android.jar 以匹配属性 {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}。 > PlatformAttrTransform 执行失败:C:\Users\LENOVO\AppData\Local\Android\sdk\platforms ndroid-33 ndroid.jar。 > C:\Users\LENOVO\AppData\Local\Android\sdk\platforms ndroid-33 ndroid.jar

  • 尝试:

使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获得更多日志输出。 使用 --scan 运行以获得完整的见解。

5秒内构建失败 异常:Gradle 任务 assembleDebug 失败,退出代码为 1

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