Flutter构建APK:出现异常错误(annotations 26.1.0)导致构建失败。

3
我正在尝试构建Flutter应用程序的发布版本,但是它不断给我以下错误:
``` 发生了什么: 任务 ':app:lintVitalRelease' 的执行失败。 Could not resolve all artifacts for configuration ':app:debugAndroidTestRuntimeClasspath'. Could not resolve 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”这个问题呢?我该如何将其添加到我的项目中?我的项目在debug模式下可以正常构建,为什么只有release版本会出现这个错误?
3个回答

6

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

android {
compileSdkVersion 28

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

希望这对某些人有所帮助。


2
太冒险的解决方案 - CAMOBAP

1
在我的情况下,flutter.gradle所需的依赖项与项目中的androidTestImplementation存在冲突:
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 

由于我没有本地的Android测试,所以我只是删除了那些依赖项。
附注:这种解决方案对于具有本地测试的人不起作用。

0

你尝试在 android/build.gradle 中添加Maven URL了吗?

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

您正在使用 Gradle 3.x,而google()存储库是在Gradle 4.x中引入的到Google的Maven存储库的快捷方式。

查看此线程


更新了build.gradle文件,按照你的建议运行了"flutter clean"和"flutter build apk"命令,但还是出现了同样的错误。 - ThiagoAM
很奇怪,你在 Github 上有这个项目吗? - Victor Hugo Montes

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接