[英]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.org
在https://help.gradle.org获得更多帮助
BUILD FAILED in 828ms Running Gradle task 'bundleRelease'...
运行 Gradle 任务 'bundleRelease' 的 828 毫秒内构建失败...
1,536ms Gradle task bundleRelease failed with exit code 11,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 -v
或flutter 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.