flutter-mapbox-gl / maps

A Mapbox GL flutter package for creating custom maps
Other
1.04k stars 501 forks source link

Donot works in release apk - java.lang.IllegalAccessError #573

Closed Satendra124 closed 3 years ago

Satendra124 commented 3 years ago

When i try to run the flutter run --release the app opens and when mapbox needs to be shown then it crashes. Commenting the mapbox code the app works fine so am guessing there is some problem with the plugin.

MapboxMap(
            compassEnabled: true,
            initialCameraPosition:
                CameraPosition(target: LatLng(25.265, 82.991), zoom: 13.5),
            onMapCreated: _onMapCreated,
            accessToken: ACCESS_TOKEN,
            myLocationEnabled: true,
            myLocationTrackingMode: MyLocationTrackingMode.TrackingGPS,
            myLocationRenderMode: MyLocationRenderMode.GPS,
            onMapClick: (point, latLng) async {},
            onMapLongClick: (point, latLng) async {},
            styleString:
                "mapbox://styles/satendra124/ckll3sr9q0t4317lnzo5zg2nj",
          ),

this is the error I get in log:

E/AndroidRuntime(21917): FATAL EXCEPTION: main
E/AndroidRuntime(21917): Process: com.iitbhu.cht, PID: 21917
E/AndroidRuntime(21917): java.lang.IllegalAccessError: Interface androidx.lifecycle.b implemented by class com.mapbox.mapboxgl.MapboxMapController is inaccessible (declaration of 'com.mapbox.mapboxgl.MapboxMapController' appears in /data/app/com.iitbhu.cht-B_YbWLvpQCmQiY8CCjuvFg==/base.apk)
E/AndroidRuntime(21917):        at com.mapbox.mapboxgl.s.a(Unknown Source:2)
E/AndroidRuntime(21917):        at io.flutter.plugin.platform.SingleViewPresentation.onCreate(Unknown Source:116)
E/AndroidRuntime(21917):        at android.app.Dialog.dispatchOnCreate(Dialog.java:554)
E/AndroidRuntime(21917):        at android.app.Dialog.show(Dialog.java:394)
E/AndroidRuntime(21917):        at android.app.Presentation.show(Presentation.java:281)
E/AndroidRuntime(21917):        at io.flutter.plugin.platform.l.<init>(Unknown Source:55)
E/AndroidRuntime(21917):        at io.flutter.plugin.platform.l.a(Unknown Source:65)
E/AndroidRuntime(21917):        at io.flutter.plugin.platform.k$a.d(Unknown Source:110)
E/AndroidRuntime(21917):        at io.flutter.embedding.engine.i.j$a.b(Unknown Source:152)
E/AndroidRuntime(21917):        at io.flutter.embedding.engine.i.j$a.N(Unknown Source:144)
E/AndroidRuntime(21917):        at d.a.c.a.j$a.a(Unknown Source:17)
E/AndroidRuntime(21917):        at io.flutter.embedding.engine.e.b.e(Unknown Source:57)
E/AndroidRuntime(21917):        at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(Unknown Source:4)
E/AndroidRuntime(21917):        at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime(21917):        at android.os.MessageQueue.next(MessageQueue.java:336)
E/AndroidRuntime(21917):        at android.os.Looper.loop(Looper.java:197)
E/AndroidRuntime(21917):        at android.app.ActivityThread.main(ActivityThread.java:7948)
E/AndroidRuntime(21917):        at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(21917):        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/AndroidRuntime(21917):        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

Please help

shroff commented 3 years ago

This is an open issue in flutter with Android Gradle Plugin 4.0+. See flutter/flutter#58479 for the full discussion.

tl;dr downgrade android gradle plugin to 3.x and/or add the following proguard rule:

-keep class androidx.lifecycle.DefaultLifecycleObserver
shroff commented 3 years ago

Keeping open for reference

petodavid commented 3 years ago

Any update? I'm still experiencing this issue

Satendra124 commented 3 years ago

Yes! Adding READ_PHONE_STATE permission in the manifest did the magic for me.

petodavid commented 3 years ago

Still doesn't work in release mode

martinsellergren commented 3 years ago

Simply add the dependency https://pub.dev/packages/flutter_plugin_android_lifecycle

smartdev123 commented 2 years ago

Keeping open for reference

It Works for me thanks ...

jay23794 commented 2 years ago

Simply add the dependency https://pub.dev/packages/flutter_plugin_android_lifecycle

works for me

davideduardotech commented 1 year ago

Simply add the dependency https://pub.dev/packages/flutter_plugin_android_lifecycle

it solved my problem, thank you very much, I was breaking my head for hours trying to solve this bug haha