Android Studio 无法正确构建 flutter 应用程序

2024-05-03

我正在开发一个应用程序,当我打开它时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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.shopapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

控制台输出:

在调试模式下在 IA 模拟器上的 AOSP 上启动 lib\main.dart... 运行 Gradle 任务“assembleDebug”...

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

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

    没有 NDK 版本与请求的版本 20.0.5594570 匹配。本地可用版本:21.0.6113669

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

  • 获得更多帮助https://help.gradle.org https://help.gradle.org

1 秒内构建失败完成并出现错误:Gradle 任务 assembleDebug 失败,退出代码为 1

Also there is a message in logcat Please configure Android SDK enter image description here I looked for a solution and did not find a solution for it

我只是需要帮助,但不知道我是否违反了该网站的法律,因为我英语说得不流利


解决方案之一是这样的,

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

lintOptions {
    disable 'InvalidPackage'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.shopapp"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode flutterVersionCode.toInteger()
    versionName flutterVersionName
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        signingConfig signingConfigs.debug
    }
}

ndkVersion "21.0.6113669" ///  <<---Add this, 



}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}

原因是因为你安装了其他NDK,并且android studio有其他版本,其他解决方案是,->转到sdk工具,然后卸载NDK和Cmake。

抱歉我的英语,我不是母语人士。祝你好运!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android Studio 无法正确构建 flutter 应用程序 的相关文章

随机推荐

  • 使用异步时 SqlConnection 未被释放

    我有一个项目 有一个 Sql Server 数据库后端和 Dapper 作为 ORM 我正在尝试使用 Dapper 的QueryAsync 方法来获取一些数据 不仅如此 对我的存储库的调用来自几个使用 a 调用的任务内部Task WhenA
  • PHP exec - 检查是否启用或禁用

    有没有办法检查 php 脚本是否exec 在服务器上启用还是禁用 这将检查该功能是否确实有效 权限 权利等 if exec echo EXEC EXEC echo exec works
  • 以最小的努力在多台计算机之间同步代码

    我希望能够跨多台计算机 准确地说是 3 台 同步源代码和整个项目 我尝试过使用 git 但从来没有获得过无忧无虑的体验 也许是因为我从来没有投入很多精力 所以 我理想中想要的是 能够将文件夹及其所有子文件夹添加到 同步 列表 基本上 一旦我
  • Visual Studio Publish 的动态文件夹名称

    是否可以在 VS 2017 中配置文件系统发布选项 以根据日期或增量构建版本部署到新文件夹 即 当我单击发布时 我希望它转到 MyApp v1 然后下次单击 MyApp V2 您可以使用一些宏 要执行日期 请使用此宏 System Date
  • Phonegap从Java代码获取本地存储值?

    我已经使用phonegap在客户端保存了数据本地存储 http docs phonegap com en 1 2 0 phonegap storage storage md html现在我想用java代码访问保存的数据 这可能吗 我怎样才能
  • jQuery UI MultiSelect Widget 选择保留在 IE 中,但不保留在 Chrome 中

    我正在使用jQuery 多选小部件 http www erichynds com examples jquery ui multiselect widget demos basic 使用 IE 时 如果我从基本下拉列表中选择 3 个选项 浏
  • Gradle println 在未调用时打印

    我的目标是每当idea任务已运行 但不幸的是 每当运行任何内容时都会打印该消息 为什么打印行在执行时执行idea任务没有运行 如何仅在以下情况下显示消息idea任务执行了 构建 gradle apply plugin idea task h
  • 更改 ant junit 任务中的工作目录

    我有一个运行 JUnits 测试的 ant 文件 这些测试依赖于某些配置文件的相对路径 我尝试设置批量测试的工作目录 但失败 我希望工作目录是 plugins dir name ant 脚本的 JUnit 部分
  • 如何合法使用网络字体? [关闭]

    Closed 这个问题是无关 help closed questions 目前不接受答案 我对适用于网络字体的法律有点困惑 我知道使用 Arial Times Romans Georgia 等字体是可以的 我认为使用其他商业字体是违法的 有
  • ng2-charts:如何设置 y 轴的固定范围

    我有一个使用 ng2 charts 模块的 Chart js 图表 该图表在 y 轴上显示百分比 在 x 轴上显示时间 是否可以将 y 轴设置为显示 0 到 100 而不是基于数据的动态范围 尝试将以下内容添加到图表选项中 scales y
  • 如何在java中执行定时器任务

    我只想用 Java 实现以下内容 有人有什么想法吗 public String method1 statement1 statement 5 我想为statemen1 涉及一些网络通信 设置一个计时器 如果语句 1 在 25 秒后仍未完成
  • 使用 PowerShell 对 zip 文件中的文件和文件夹进行计数

    如何计算 zip 文件中的文件和文件夹数量 我正在运行备份验证 需要将 zip 文件的文件夹结构与 Windows 文件夹的文件夹结构进行比较 最终目标是获得一个布尔值 源计数是否等于 zip 内容计数 到目前为止 这是我所掌握的 Refl
  • 如何使用 MigraDoc 让表情符号出现在生成的 PDF 中

    我正在尝试生成包含一些表情符号的 PDF 但没有成功 为了使其简单且可重现 这里是代码 Document document new Document Section section document AddSection Paragraph
  • Cocos2D 2.1:iOS 6 中已弃用“Delegate”。如何设置此 AVAudioSession 的委托?

    在 Xcode 4 5 中启动了 Cocos2D 2 1 模板 没有物理引擎 针对 iOS 6 和 iPad 在 CDAudioManager m 文件中 以下代码 AVAudioSession session AVAudioSession
  • Ninject 2.2 多重绑定

    我最近将 ASP NET MVC 3 应用程序更新为 Ninject 2 2 以前 我的主应用程序中有以下接口来实现绑定 Bind typeof IMyInterface lt gt To typeof MyImplementation l
  • prometheus 节点实例列表

    是否可以使用 prometheus 获取节点实例列表 我有一个节点导出器 但我没有看到这样的指标 我们应该添加一个新的运算符吗 您可以使用kube 状态指标 https github com kubernetes kube state me
  • c# - 系统的是/否值

    有没有办法获得 Net 框架中系统语言的 是 否 值 当我只需要 是 和 否 时 我不想为每种语言制作语言文件 你确实可以使用windows资源 我曾经做过一个例子 不幸的是在Delphi中 但你当然也可以在Dotnet中做到这一点 它真的
  • 如何在WinForms中将字典绑定到ListBox

    是否可以将字典绑定到列表框 保持列表框和成员属性之间的同步 var choices new Dictionary
  • gcloud 部署应用程序找不到导入包 - golang

    我已经将应用程序的一个版本部署到 GAE 但现在部署新版本时遇到问题 当我尝试时gcloud app deploy version VERSION 我收到一堆错误 显示远程构建找不到我的导入包 Beginning deployment of
  • Android Studio 无法正确构建 flutter 应用程序

    我正在开发一个应用程序 当我打开它时build gradle文件 出现了几个错误 def localProperties new Properties def localPropertiesFile rootProject file loc