Exception thrown in build by image_picker

For those who didn't know (including myself) there are two build.gradle files

  1. android/build.gradle
  2. android/app/build.gradle

step 1 inside android/build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        // classpath 'com.android.tools.build:gradle:3.5.0' before
        classpath 'com.android.tools.build:gradle:4.0.1' // after
    }
}

step 2 inside android/gradle/wrapper/gradle-wrapper.properties


distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

# BEFORE
# distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
# AFTER
distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip

step 3 rebuild project

it might take while because it will download new gradle


This is because tag was introduced with new package visibility options for Android 11 and upwards (SDK 30+). Because of that, you need to update your build.gradle with a version that includes this changes. Below is a list of supported gradle options.

'3.3.3', '3.4.3', '3.5.4', '3.6.4', '4.0.1'

Don't forget to update your ditributionUrl in your gradle-wrapper.properties as well. For example, for gradle 4.0.1, you should have:

distributionUrl=https://services.gradle.org/distributions/gradle-6.1.1-all.zip

reference: https://github.com/miguelpruivo/flutter_file_picker/wiki/Troubleshooting#android