2

When i run flutter run --release -v this command below error came

Caused by: java.lang.IllegalAccessError: Interface androidx.lifecycle.b implemented by class
com.mr.flutter.plugin.filepicker.FilePickerPlugin$LifeCycleObserver is inaccessible (declaration of 'com.mr.flutter.plugin.filepicker.FilePickerPlugin$LifeCycleObserver' appears in
/data/app/app.projects.xxx.mobile-1/base.apk)

My Gradle is classpath 'com.android.tools.build:gradle:4.0.0' //4.0.1 //3.3.2 //3.5.3 //3.4.2

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

Abdul Kadhar
  • 53
  • 2
  • 8

3 Answers3

4

This worked for me.

Go to build.gradle file at android/gradle and downgrade to version 3.6.2 like shown below,

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.2'

Answer taken from this thread.

Aadarsh Patel
  • 167
  • 4
  • 14
4

I had similar issue, its related to gradle 4+ version i guess, i was able to resolve this by following below steps.

Add bellow line to app/proguard-rules.pro (if file not present create one.)

-keep class androidx.lifecycle.DefaultLifecycleObserver

Error from logcat, it was only having issue in release build. The emulator was working fine. -

03-12 07:41:32.281 22847 22847 E AndroidRuntime: java.lang.IllegalAccessError: Interface androidx.lifecycle.b implemented by class com.mr.flutter.plugin.filepicker.FilePickerPlugin$LifeCycleObserver is inaccessible (declaration of 'com.mr.flutter.plugin.filepicker.FilePickerPlugin$LifeCycleObserver' appears in base.apk)

Related Discussion/Issue can be found here -https://github.com/flutter/flutter/issues/58479

Akshay
  • 657
  • 2
  • 19
  • 38
0

upgrade your grade classpath and distribution url to latest version. also filepicker to latext version in pubspec.yaml

check if it works... if not then open android/gradle.properties and see if the following lines are there or not if not then add

android.useAndroidX=true
android.enableJetifier=true

check if following are there in your android/app/build.gradle or not

minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true

then flutter clean

then instead of directly running flutter run --release -v use the following its not related to your issue but it will cause another you will get something missingFile exception.

flutter build apk --debug
then flutter build apk --profile;
then flutter build apk --release;
Dharman
  • 30,962
  • 25
  • 85
  • 135
Jagadish
  • 1,005
  • 11
  • 30