flutter gradle build failed with gradle 4.2.2 and sdk version 31

197

I finally solve this issue by downgrade my Gradle version to 4.1.0

dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        ...        
}
Share:
197
questionasker
Author by

questionasker

I'm Web, Unity3D & Flutter Developer. I love to share my ideas at my web, please visit my website for any tutorial related to marketing, programming, docker, linux, etc

Updated on January 04, 2023

Comments

  • questionasker
    questionasker over 1 year

    I get below error when building flutter mobile apps:

    * What went wrong:
    Execution failed for task ':location_permissions:parseReleaseLocalResources'.
    > Could not resolve all files for configuration ':location_permissions:androidApis'.
       > Failed to transform android.jar to match attributes {artifactType=android-platform-attr, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
          > Execution failed for PlatformAttrTransform: C:\Users\zukijuki\AppData\Local\Android\sdk\platforms\android-29\android.jar.
             > C:\Users\zukijuki\AppData\Local\Android\sdk\platforms\android-29\android.jar
    

    my android/build.gradle conf:

    buildscript {
        repositories {
            google()
            mavenCentral()
            maven {
                url 'https://maven.fabric.io/public'
            }
            maven {
                url 'https://plugins.gradle.org/m2/'
            }
            maven {
                url 'https://maven.google.com'
            }
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:4.2.2'
            classpath 'com.google.gms:google-services:4.3.3'
            classpath 'io.fabric.tools:gradle:1.28.1'        
        }
    }
    

    and below app/build.gradle:

    ...
    
    android {
        compileSdkVersion 31
        buildToolsVersion '28.0.3'
    
        lintOptions {
            //disable 'InvalidPackage'
        }
    
        defaultConfig {
            applicationId "com.example"
            minSdkVersion 22
            multiDexEnabled true
            targetSdkVersion 30
            versionCode flutterVersionCode.toInteger()
            versionName flutterVersionName
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            resConfigs "en", "US"
        }
        
        ...
    
    }
    
    flutter {
        source '../..'
    }
    
    dependencies {
    
        implementation("com.google.android.gms:play-services-base:17.0.0"){ force = true } 
        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'
    
        implementation 'com.google.android.gms:play-services-location:16.0.0'
        implementation 'com.android.support:multidex:1.0.3'
        implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    
    
    }
    
    configurations {
        all*.exclude group: 'com.google.guava', module: 'listenablefuture'
    }
    
    
    apply plugin: 'com.google.gms.google-services'
    apply plugin: 'io.fabric'
    

    any idea to fix the above problem?

    Thank you in advance...

    ===update

    1. gradle.properties
    org.gradle.jvmargs=-Xmx1536M
    android.useAndroidX=true
    android.enableJetifier=true
    android.enableR8=true
    
    1. Build using Android Studio Bumblebee | 2021.1.1 Patch 3

    2. Reinstall API Level 29,30,31,32 still cant resolve.

  • questionasker
    questionasker about 2 years
    Hi, I have added it before
  • Gerry
    Gerry about 2 years
    Which IDE are you building from?
  • questionasker
    questionasker about 2 years
    Android Studio Bumblebee | 2021.1.1 Patch 3 Build #AI-211.7628.21.2111.8309675, built on March 17, 2022
  • Gerry
    Gerry about 2 years
    Okay, I've updated my answer now that I know this.
  • questionasker
    questionasker about 2 years
    I've tried reinstalling SDK 29,30,31 but nothing change