Flutter build apk:构建失败,但出现异常(注释26.1.0)

时间:2019-02-25 23:34:56

标签: android dart flutter build.gradle

我正在尝试构建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”?如何将其添加到我的项目中?该项目可以很好地进行调试,为什么发行版会给我这个错误?

3 个答案:

答案 0 :(得分:1)

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

android {
compileSdkVersion 28

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

希望这对某人有帮助

答案 1 :(得分:1)

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

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

并且因为我没有本机android测试,所以我删除了那些依赖项

P.S。此解决方案不适用于具有本机测试的人

答案 2 :(得分:0)

您是否尝试过在 android / build.gradle 中添加Maven网址?

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

您使用的是 Gradle 3.x ,而google()存储库是 Gradle 4.x

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

Check this thread