简体   繁体   English

flutter。 当我尝试运行此推荐“flutter build appbundle”时,出现此错误

[英]flutter . When I'm trying run this commend "flutter build appbundle" I get this error

I am trying to build a app with flutter.我正在尝试使用 flutter 构建一个应用程序。 When I'm trying run this commend "flutter build appbundle" I get this error:当我尝试运行此推荐“flutter build appbundle”时,我收到此错误:

FAILURE: Build failed with an exception. FAILURE:构建失败并出现异常。

  • Where: Build file 'F:\azabaza_app\myapp\android\app\build.gradle' line: 28其中:构建文件 'F:\azabaza_app\myapp\android\app\build.gradle' 行:28

  • What went wrong: A problem occurred evaluating project ':app'.出了什么问题:评估项目“:app”时出现问题。

Could not get unknown property 'compileSdkVersion' for extension 'flutter' of type FlutterExtension.无法为 FlutterExtension 类型的扩展“flutter”获取未知属性“compileSdkVersion”。

  • Try: Run with --stacktrace option to get the stack trace.尝试:使用 --stacktrace 选项运行以获取堆栈跟踪。 Run with --info or --debug option to get more log output.使用 --info 或 --debug 选项运行以获得更多日志 output。 Run with --scan to get full insights.运行 --scan 以获得完整的见解。

  • Get more help at https://help.gradle.orghttps://help.gradle.org获得更多帮助

BUILD FAILED in 828ms Running Gradle task 'bundleRelease'...运行 Gradle 任务 'bundleRelease' 的 828 毫秒内构建失败...
1,536ms Gradle task bundleRelease failed with exit code 1 1,536 毫秒 Gradle 任务捆绑发布失败,退出代码为 1

My android/app/build.gradle file:我的 android/app/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"
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
    compileSdkVersion flutter.compileSdkVersion
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    defaultConfig {
        applicationId "io.flutter.examples.flutter_view"
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
   signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }

}
flutter {
    source '../..'
}
dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.0.0'
}

From your android/app/build.gradle file, you need to change 3 variables from your build.gradle file into to integers: compileSdkVersion which is now set to flutter.compileSdkVersion , minSdkVersion now set to flutter.minSdkVersion , and targetSdkVersion now set to flutter.targetSdkVersion . From your android/app/build.gradle file, you need to change 3 variables from your build.gradle file into to integers: compileSdkVersion which is now set to flutter.compileSdkVersion , minSdkVersion now set to flutter.minSdkVersion , and targetSdkVersion now set to flutter.targetSdkVersion They need to be replaced with latest stable versions.它们需要替换为最新的稳定版本。

android {

    compileSdkVersion 31

    compileOptions {
       ...
    }

   ... ...

    defaultConfig {
        ...
        minSdkVersion 28
        targetSdkVersion 30
       ...
    }
}

The compileSdkVersion should be newest stable version. compileSdkVersion 应该是最新的稳定版本。 eg now is 31. The targetSdkVersion can be less or equal to compileSdkVersion, thus 30 is OK, and 31 is even better.例如,现在是 31。targetSdkVersion 可以小于或等于 compileSdkVersion,因此 30 可以,31 更好。 If you don't set the targetSdkVersion, it will use the minSdkVersion.如果不设置 targetSdkVersion,它将使用 minSdkVersion。

After you make your changes, run flutter clean to remove your last previous build.进行更改后,运行flutter clean以删除上一个先前的构建。 Then rebuild again flutter build appbundle -v or flutter build appbundle to reflect your new changes.然后再次重建flutter build appbundle -vflutter build appbundle以反映您的新更改。

You are currently setting android the compile version to a variable that doesn't exist compileSdkVersion flutter.compileSdkVersion .您当前正在将 android 编译版本设置为不存在的变量compileSdkVersion flutter.compileSdkVersion The compile version is usually a hard coded number ex: compileSdkVersion 30编译版本通常是一个硬编码的数字,例如: compileSdkVersion 30

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:我正在使用 flutter 应用程序,我从 git 集线器克隆它,当我尝试运行它时构建失败 - Flutter: I'm working in a flutter application which i clone it from git hub, the build is failed when i trying to run it “flutter build appbundle”命令中的 Flutter 构建错误 - Flutter build error in "flutter build appbundle" command 尝试在 vscode 上通过 flutter 运行应用程序时出现此错误 - I get this error when trying to run an app via flutter on vscode 当我运行“ flutter build aot --debug ”错误时? - when I run " flutter build aot --debug " error? 当我使用 Flutter 运行此应用程序时,我收到此错误 - When I run this app with Flutter, I get this error 我在使用 flutter 构建 appbundle 时遇到问题 - i have an issue with building appbundle with flutter 如何修复“错误:Flutter 目录不是 GitHub 项目的克隆。” 尝试安装 flutter 时出错? - How do I fix the "Error: The Flutter directory is not a clone of the GitHub project." error when I'm trying to install flutter? Flutter 当我运行“flutter run”时出现条带错误 - Flutter Stripe Error When I run “flutter run” 尝试运行 flutter 应用程序时,build.gradle 文件中出现错误 - When trying to run flutter application there is a Error in build.gradle file 当我尝试从 url 获取数据后尝试运行我的 flutter 应用程序时,出现 null 错误 - I get a null error when I try to run my flutter app after trying to fetch data from a url
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM