【问题标题】:flutter . When I'm trying run this commend "flutter build appbundle" I get this error扑腾。当我尝试运行此推荐“flutter build appbundle”时,出现此错误
【发布时间】:2022-01-08 07:47:28
【问题描述】:

我正在尝试使用 flutter 构建应用程序。当我尝试运行此推荐“flutter build appbundle”时,出现此错误:

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

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

  • 出了什么问题:评估项目 ':app' 时出现问题。

无法为 FlutterExtension 类型的扩展“flutter”获取未知属性“compileSdkVersion”。

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

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

在 828 毫秒内构建失败运行 Gradle 任务“bundleRelease”...
1,536 毫秒 Gradle 任务 bundleRelease 失败,退出代码为 1

我的 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'
}

【问题讨论】:

  • 请显示 build.gradle 文件,该文件出现错误
  • @Shojaeddin 请检查
  • 你应该使用 sdk 的数量来编译
  • 在添加compiileSdkVersion 30 后我收到此错误* What went wrong: A problem occurred evaluating project ':app'. > Could not get unknown property 'minSdkVersion' for extension 'flutter' of type FlutterExtension. * 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.
  • 为 mimumsdk 、targetsdk 设置编号。请制作一个简单的 android 应用程序并在那里查看默认配置

标签: android flutter dart build.gradle android-app-bundle


【解决方案1】:

从您的 android/app/build.gradle 文件中,您需要将 build.gradle 文件中的 3 个变量更改为整数:compileSdkVersion 现在设置为 flutter.compileSdkVersionminSdkVersion 现在设置为 @987654324 @ 和 targetSdkVersion 现在设置为 flutter.targetSdkVersion。它们需要替换为最新的稳定版本。

android {

    compileSdkVersion 31

    compileOptions {
       ...
    }

   ... ...

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

compileSdkVersion 应该是最新的稳定版本。例如现在是 31。 targetSdkVersion 可以小于或等于 compileSdkVersion,因此 30 可以,31 更好。如果不设置 targetSdkVersion,它将使用 minSdkVersion。

进行更改后,运行 flutter clean 以删除您之前的最后一个构建。 然后再次重建 flutter build appbundle -vflutter build appbundle 以反映您的新更改。

【讨论】:

  • 它有效,谢谢
【解决方案2】:

您当前正在将 android 编译版本设置为不存在的变量 compileSdkVersion flutter.compileSdkVersion。编译版本通常是一个硬编码的数字例如:compileSdkVersion 30

【讨论】:

  • 在添加 compiileSdkVersion 30 后出现此错误 * What went wrong: A problem occurred evaluating project ':app'. > Could not get unknown property 'minSdkVersion' for extension 'flutter' of type FlutterExtension. * 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.
  • flutter 变量不存在。到处都是flutter.something,您必须将其替换为实际值或创建扩展颤振并在其中硬编码变量。
猜你喜欢
  • 2022-01-11
  • 1970-01-01
  • 2019-01-26
  • 2021-12-24
  • 1970-01-01
  • 2020-10-09
  • 2022-06-25
  • 2022-11-07
  • 1970-01-01
相关资源
最近更新 更多