为什么会出现这些错误,我尝试发布apk
我运行“ flutter build apk --release”
任务':app:lintVitalRelease'的执行失败。 配置根项目“ android_intent”时出现问题。
- 出了什么问题:配置根项目“ android_intent”时出现问题。
找不到SDK位置。在local.properties文件中使用sdk.dir或使用ANDROID_HOME环境变量来定义位置。
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 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 }
答案 0 :(得分:35)
升级gradle构建工具似乎会减少一些毛刺。
当我从gradle构建工具3.3.1
-> 4.0.0
升级时,对我有用的是在 android / app / build中的checkReleaseBuilds false
中添加lintOptions
.gradle 文件。
android {
...
lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false //<- add this line
}
}
答案 1 :(得分:3)
如果您的错误显示 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
取自here
答案 2 :(得分:0)
我坚持使用3.x
系列(3.6.4
)中最新的Android Studio Gradle插件,并搭配最新的Gradle版本(AS插件3.6.4
+ Gradle { {1}}对我来说没有错误。
答案 3 :(得分:0)
如果您遇到此问题并且无法像我一样使用任何一种修复方法来修复它,那么您可能遇到了不同的问题。我必须为每种风格运行 run 和 run --release 命令,然后才能构建一个没有错误的版本。
所以 flutter run --flavor dev ...(对每种口味都这样做) flutter run --flavor lastFlavor 然后 flutter build apk --flavor dev(错误) ...(对每种口味都这样做) flutter build apk --flavor lastFlavor(成功!)
从现在开始,您可以毫无错误地构建每种口味:)