Home > Enterprise >  flutter gradle build failed with gradle 4.2.2 and sdk version 31
flutter gradle build failed with gradle 4.2.2 and sdk version 31

Time:04-17

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.

CodePudding user response:

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

dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        ...        
}

CodePudding user response:

It seems like some configuration files for android are missing.

Try reinstalling the Android SDK.

To do this, you need to uninstall from SDK Manager and then reinstall it.

Find it by: Clicking Tools > SDK Manager.

  • Related