【问题标题】:Flutter build apk: Build failed with an exception (annotations 26.1.0)Flutter build apk:构建失败并出现异常(注释 26.1.0)
【发布时间】:2019-07-19 10:56:38
【问题描述】:

我正在尝试构建我的 Flutter 应用的发布版本,但它一直给我以下错误:

出了什么问题:

任务“:app:lintVitalRelease”执行失败。

无法解析配置“:app:debugAndroidTestRuntimeClasspath”的所有工件。

无法解析 com.android.support:support-annotations:26.1.0。 要求:.......

我已经花了几个小时寻找答案,但没有任何效果。 我不知道这是否有帮助,但这是我的 android/build.gradle 文件:

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.1'
        classpath 'com.google.gms:google-services:3.2.1'
    }
}

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
}

这是我的 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 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "br.com.thiagoam.testieprototype"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

我需要做什么来解决这个“com.android.support:support-annotations:26.1.0”?如何将其添加到我的项目中?项目构建调试很好,为什么只是发布版本给我这个错误?

【问题讨论】:

    标签: android dart flutter build.gradle


    【解决方案1】:

    就我而言,项目中flutter.gradleandroidTestImplementation 所需的依赖项之间存在冲突:

    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 
    

    因为我没有原生 android 测试,所以我只是删除了那些依赖项

    附:此解决方案不适用于进行本机测试的人

    【讨论】:

      【解决方案2】:

      如果有人仍然面临这个问题。这就是我解决问题的方法,只需将以下行放入 app/build.gradle 文件中:

      android {
      compileSdkVersion 28
      
      lintOptions {
          disable 'InvalidPackage'
          //Put the following line
          checkReleaseBuilds false
          //abortOnError false
      }
      

      希望这对某人有所帮助

      【讨论】:

      • 风险太大的解决方案
      【解决方案3】:

      您是否尝试在 android/build.gradle 中添加 maven url?

      allprojects {
          repositories {
              maven { url 'https://maven.google.com' } //this should be added
              google()            
              jcenter()
          }
      }
      

      您使用的是 Gradle 3.xgoogle() 存储库是 Gradle 4.x

      中引入的 Google maven 存储库的快捷方式

      Check this thread

      【讨论】:

      • 不起作用,按照您的建议更新 build.gradle 后,运行“flutter clean”和“flutter build apk”,它仍然给我同样的错误。
      • 这很奇怪。你在 github 上有这个项目吗?
      猜你喜欢
      • 2022-07-07
      • 2020-06-29
      • 2019-02-23
      • 2022-01-06
      • 2020-06-13
      • 2021-01-25
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多