为什么我得到这些错误我试图释放apk
我运行“flutter build apk--release”
未找到SDK位置。使用local.properties文件中的sdk. dir或ANDROID_HOME环境变量定义位置。
android/app/build. g radle
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 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.deleviry"
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
multiDexEnabled true
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
} }
flutter {
source '../..' }
dependencies {
implementation 'com.google.firebase:firebase-core:17.2.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" }
apply plugin: 'com.google.gms.google-services'
android/build. gradle
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.google.gms:google-services:4.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
allprojects {
repositories {
google()
jcenter()
} }
rootProject.buildDir = '../build' subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects {
project.evaluationDependsOn(':app') }
task clean(type: Delete) {
delete rootProject.buildDir }
升级gradle构建工具似乎破坏了一些线条。
要解决此问题,您可以:
如果您的错误显示debug/libs. jar,则构建--debug然后--release。
如果您的错误显示profile/libs.jar,则构建--profile然后--release。
从https://github.com/flutter/flutter/issues/58247#issuecomment-636500680
如果以上不起作用,您可以禁用检查。
在android/app/build. gradle文件的lintOptions
中添加checkReleaseBuilds false
。
android {
...
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false //<- add this line
}
}
如果您的错误显示debug/libs. jar
,请构建--debug
然后--release
:
flutter build apk --debug
flutter build apk --release
如果您的错误显示profile/libs. jar
,请构建--profile
然后--release
:
flutter build apk --profile
flutter build apk --release
从这里拿走的
如果你遇到了这个问题,但你不能像我一样用任何一个修复程序来解决它,你可能会有不同的口味。我必须为每个口味运行run和run--release命令,然后才能无错误地构建一个。
因此,flutter run--有风味的dev…(为每个风味执行此操作)flutter run--有风味的lastFlavor然后flutter build apk--有风味的dev(错误)…(为每个风味执行此操作)flutter build apk--有风味的lastFlavor(成功!)
从现在开始,您可以毫无错误地构建每种口味:)