3

I'm trying to build a release version of my Flutter app, and it keeps giving me the following error:

What went wrong:

Execution failed for task ':app:lintVitalRelease'.

Could not resolve all artifacts for configuration ':app:debugAndroidTestRuntimeClasspath'.

Could not resolve com.android.support:support-annotations:26.1.0. Required by: .......

I already spent hours searching for answers, but nothing works. I don't know if this helps, but here's my android/build.gradle file:

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
}

Here's my android/app/build.gradle file:

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'

What do I need to do to resolve this "com.android.support:support-annotations:26.1.0"? How to I add it to my project? The project builds for debug just fine, why is just the release version giving me this error?

Zoe
  • 27,060
  • 21
  • 118
  • 148
ThiagoAM
  • 1,432
  • 13
  • 20

3 Answers3

6

If anyone is still facing this issue. This is how i resolved the problem, Just put the following line in the app/build.gradle file:

android {
compileSdkVersion 28

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

Hope this helps someone

defemz
  • 519
  • 2
  • 7
  • 20
1

In my case, there was a conflict between the dependencies required by flutter.gradle and androidTestImplementation ones in the project:

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

And because I had no native android tests, I just removed those dependencies

P.S. This solution will not work for ones who have native tests

CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
0

Have you tried to add the maven url in you android/build.gradle?

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

You're using Gradle 3.x and google() repository is a shortcut to Google's maven repository introduced in Gradle 4.x

Check this thread

Victor Hugo Montes
  • 1,270
  • 1
  • 17
  • 28