Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Second display not working in Release APK #7

Open
ziakhan110 opened this issue Jun 15, 2021 · 29 comments
Open

Second display not working in Release APK #7

ziakhan110 opened this issue Jun 15, 2021 · 29 comments

Comments

@ziakhan110
Copy link
Contributor

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

@VNAPNIC
Copy link
Owner

VNAPNIC commented Jun 16, 2021

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

@ziakhan110
Copy link
Contributor Author

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
Copy link
Contributor Author

the problem might be related to proguard shrinking

@VNAPNIC
Copy link
Owner

VNAPNIC commented Jun 17, 2021

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

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

@MarcoGolin
Copy link

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):

@VNAPNIC
Copy link
Owner

VNAPNIC commented Jun 18, 2021

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

@MarcoGolin
Copy link

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

is the Sunmi D2-mini

@VNAPNIC
Copy link
Owner

VNAPNIC commented Jun 19, 2021

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

@ziakhan110
Copy link
Contributor Author

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

@vagers2000
Copy link

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

@mjafartp
Copy link

Same issue,
Not working on the release version.

@EbramTawfik
Copy link
Contributor

Worked for me by adding a progaurd rule

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

@arbyazra123
Copy link

arbyazra123 commented Aug 26, 2021

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.** { *; }

@azhura14
Copy link

azhura14 commented Mar 8, 2022

i was use two condition but nothing change

@ziakhan110
Copy link
Contributor Author

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

@ziakhan110
Copy link
Contributor Author

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.

@johnfriend88
Copy link

johnfriend88 commented Feb 1, 2024

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?

@hrueger
Copy link

hrueger commented Apr 26, 2024

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...

@patelnirav48
Copy link

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

@hrueger
Copy link

hrueger commented Apr 30, 2024

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

@patelnirav48
Copy link

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

@hrueger
Copy link

hrueger commented May 18, 2024

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

@patelnirav48
Copy link

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

@dan8551
Copy link

dan8551 commented Jun 17, 2024

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

@ziakhan110
Copy link
Contributor Author

ziakhan110 commented Jun 18, 2024

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
#42

@ziakhan110
Copy link
Contributor Author

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.** { *; }

@khamenkhai
Copy link

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

@khamenkhai
Copy link

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??

@patelnirav48
Copy link

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

Check @arbyazra123's fork (#7 (comment))
It worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests