presentation-displays icon indicating copy to clipboard operation
presentation-displays copied to clipboard

Second display not working in Release APK

Open ziakhan110 opened this issue 4 years ago • 31 comments

Describe the bug When we make release APK , second display does not work.

ziakhan110 avatar Jun 15 '21 13:06 ziakhan110

u run "flutter build apk --release" right?

VNAPNIC avatar Jun 16 '21 02:06 VNAPNIC

Yes i did that, When app is running i get this,

Tried to automatically register plugins with FlutterEngine (io.flutter.embedding.engine.FlutterEngine@4748c80) but could not find and invoke the GeneratedPluginRegistrant.

ziakhan110 avatar Jun 16 '21 12:06 ziakhan110

the problem might be related to proguard shrinking

ziakhan110 avatar Jun 16 '21 12:06 ziakhan110

i don't use proguard shrinking in the project. u can add to manifest

<meta-data
    android:name="flutterEmbedding"
    android:value="2" />

VNAPNIC avatar Jun 17 '21 08:06 VNAPNIC

on debug work normaly, same problem here when run "Flutter run --release"

[ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(showPresentation, Value null at displayId of type org.json.JSONObject$1 cannot be converted to int, null, null) E/flutter ( 6899): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597) E/flutter ( 6899): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:158) E/flutter ( 6899):

MarcoGolin avatar Jun 17 '21 20:06 MarcoGolin

@MarcoGolin What device are you using? I think maybe both devices are not connected yet

VNAPNIC avatar Jun 18 '21 02:06 VNAPNIC

@MarcoGolin What device are you using? I think maybe both devices are not connected yet

is the Sunmi D2-mini

MarcoGolin avatar Jun 18 '21 11:06 MarcoGolin

Sunmi D2-mini i think u should use flutter_nearby_connections for it We're use flutter_nearby_connections for D2-mini in the my project

VNAPNIC avatar Jun 19 '21 03:06 VNAPNIC

i don't use proguard shrinking in the project. u can add to manifest

<meta-data
    android:name="flutterEmbedding"
    android:value="2" />

my project is already using V2

ziakhan110 avatar Jun 21 '21 15:06 ziakhan110

Same error to me, release apk is not working and at same place debug one is working.

vagers2000 avatar Aug 08 '21 09:08 vagers2000

Same issue, Not working on the release version.

mjafartp avatar Aug 13 '21 06:08 mjafartp

Worked for me by adding a progaurd rule

-keep class com.namit.** { *; }

EbramTawfik avatar Aug 19 '21 04:08 EbramTawfik

its because flutter release mode using obfuscating code on it, and DisplayJson.kt in native code will be obfuscated. But I fixed this issue by using klutzy way haha, try this https://github.com/arbyazra123/presentation-displays, I changed the parameter in native android to a = displayId, b = flags, c = rotation, d = displayName, because the compiler obfuscate the fields of DisplayJson.kt, and I tried to generalize it.

Or you may use the way above me to avoid obfuscating code by using -keep class com.namit.** { *; }

arbyazra123 avatar Aug 26 '21 14:08 arbyazra123

i was use two condition but nothing change

azhura14 avatar Mar 08 '22 12:03 azhura14

https://developer.android.com/reference/android/support/annotation/Keep Use this to ignore the DisplayJson.kt from obfuscating.

ziakhan110 avatar Mar 10 '22 08:03 ziakhan110

Another solution will be to use GSON field name annotations on the DisplayJson.kt fields, this way if the variable name changes the annotated name will remain , and it will work fine.

ziakhan110 avatar Mar 10 '22 09:03 ziakhan110

i have added the -keep class com.namit.** { *; } in proguard . but when i release the apk, the get display shows "null null"

but works with debug mode.

Release mode error:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Null check operator used on a null value #0 _DisplayManagerScreenState._getDisplays... (package:hi/test_project.dart:232) #1 List.forEach (dart:core-patch/growable_array.dart:416) #2 _DisplayManagerScreenState._getDisplays.. (package:hi/test_project.dart:231) #3 State.setState (package:flutter/src/widgets/framework.dart:1203) #4 _DisplayManagerScreenState._getDisplays. (package:hi/test_project.dart:226)

Even when i open example app in release mode, it will show null, null..

I am new to this. could you please help me on this?

johnfriend88 avatar Feb 01 '24 06:02 johnfriend88

It seems like with the latest flutter, that problem also exists in the example app... Just clone the repo, run flutter pub get, cd example, flutter build apk --release and install the apk. Get Displays returns null, null, null, null...

hrueger avatar Apr 26 '24 19:04 hrueger

@VNAPNIC Could you please help here. When we test using release apk its not working

patelnirav48 avatar Apr 30 '24 13:04 patelnirav48

@patelnirav48 I'm using @arbyazra123's fork successfully (https://github.com/VNAPNIC/presentation-displays/issues/7#issuecomment-906461804)

hrueger avatar Apr 30 '24 14:04 hrueger

@hrueger I'm using iMin device (connected through HDMI) will it work on that too?

patelnirav48 avatar May 18 '24 05:05 patelnirav48

I have no idea - try it and report your findings ;-)

hrueger avatar May 18 '24 12:05 hrueger

@hrueger Tested, and it works. Thanks a lot.

patelnirav48 avatar May 21 '24 08:05 patelnirav48

displays_manager.dart line 68-70: displays.add(kReleaseMode ? displayReleaseFromJson(map as Map<String, dynamic>) : displayFromJson(map as Map<String, dynamic>));

What is the reason for this code? It changes the list keys, breaking the code in release

dan8551 avatar Jun 17 '24 20:06 dan8551

This code is not needed. The author used obfuscated keys for parsing json, but those keys change on each compilation. The actual soltion is to add this file to prguard rules file to not be obfuscated in release.

Check it here https://github.com/VNAPNIC/presentation-displays/pull/42

ziakhan110 avatar Jun 18 '24 13:06 ziakhan110

Here is prguard rules, this should be added to the readme.md of this library so people know its needed in release apk.

-keep class com.namit.** { *; }

ziakhan110 avatar Jun 19 '24 07:06 ziakhan110

When i release the apk file, the secondary display didn't work.Why?? Please tell me

khamenkhai avatar Jun 26 '24 09:06 khamenkhai

Hello guys, please help me when I release the apk the second display didn't work.Only worked in the debug apk.why is that??

khamenkhai avatar Jun 28 '24 14:06 khamenkhai

I'm using @arbyazra123's fork successfully (#7 (comment))

Check @arbyazra123's fork (https://github.com/VNAPNIC/presentation-displays/issues/7#issuecomment-906461804) It worked for me.

patelnirav48 avatar Jul 01 '24 05:07 patelnirav48