Flutter build apk: Build failed with an exception (annotations 26.1.0)

1,879

Solution 1

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

Solution 2

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

Share:
1,879
ThiagoAM
Author by

ThiagoAM

Updated on December 09, 2022

Comments

  • ThiagoAM
    ThiagoAM over 1 year

    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?