Flutter_blue: not working in release

Created on 4 Feb 2021  Â·  20Comments  Â·  Source: pauldemarco/flutter_blue

the prob in Stream to get the state and scan devices, it work fine on debug but in release doesn't work

Most helpful comment

        shrinkResources false    // this line
        minifyEnabled false       // this line

@jimykhan add this code in [project_name]/android/app/build.gradle

    buildTypes {
        release {
            signingConfig signingConfigs.release
            shrinkResources false    // this line
            minifyEnabled false       // this line
        }
    }

This solves the problem for me with Version 0.8.0.

All 20 comments

Make sure you added the right permissions

No, I have already added the correct permissions and it was it works fine, and same case for the example existing in this plugin, and it appears in flutter 1.22.5

Fix for this is discussed in #726

Use v0.7.2. In pubspec.yaml change to

 dependencies:
   flutter_blue: '0.7.2'

or for v0.7.3 compile with
flutter build apk --no-shrink

Thanks, yes I have fixed the issue by adding
buildTypes {
release {
signingConfig signingConfigs.debug
shrinkResources false
minifyEnabled false
}
}

@SamiraIhsan same issue i am facing i try to create apk in release mode but flutter blue not working can you please guide how u fixed this issue please
where u add the following code

@jimykhan add this code in [project_name]/android/app/build.gradle

    buildTypes {
        release {
            signingConfig signingConfigs.release
            shrinkResources false    // this line
            minifyEnabled false       // this line
        }
    }

thank you sir for ur response i did this but it not work for me
i am using flutter_blue 0.7.3 and flutter version 1.22.6 stable please let
me know if u have solution

On Mon, 22 Feb 2021 at 01:24, SamiraIhsan notifications@github.com wrote:

add this code in [project_name]/android/app/build.gradle

buildTypes {
    release {
        signingConfig signingConfigs.release
        shrinkResources false    // this line
        minifyEnabled false       // this line
    }
}

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/pauldemarco/flutter_blue/issues/772#issuecomment-783229078,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AM7AZWFDK6HEIVFPQYAJWCLTAIPFNANCNFSM4XCUTXBA
.

I have the same issue
Did you try with 0.7.2?

i solved the issue by adding
--no-shrink

to my build command

Yes, I did. But not working

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon
Virus-free.
www.avast.com
https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, Feb 23, 2021 at 1:30 AM Kobi notifications@github.com wrote:

I have the same issue
Did you try with 0.7.2?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/pauldemarco/flutter_blue/issues/772#issuecomment-784034306,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AM7AZWDF6ZTQ3LIICRDUM5LTANYUXANCNFSM4XCUTXBA
.

mDevices size: 1 brother i also face this issue when i connect device it
not show in connected device

On Tue, 23 Feb 2021 at 02:01, Jamshed Khan jkbjd007@gmail.com wrote:

Yes, I did. But not working

https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon Virus-free.
www.avast.com
https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link
<#m_-1689485638635840774_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Tue, Feb 23, 2021 at 1:30 AM Kobi notifications@github.com wrote:

I have the same issue
Did you try with 0.7.2?

—
You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/pauldemarco/flutter_blue/issues/772#issuecomment-784034306,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AM7AZWDF6ZTQ3LIICRDUM5LTANYUXANCNFSM4XCUTXBA
.

I made another issue with some proguard rules that work #784. They may be a bit too broad though.

@pauldemarco
Tried 0.8.0 and still seeing the problem. Building just in release mode, with none of the mods mentioned above:

E/flutter ( 1455): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(startScan, Field androidScanMode_ for c.c.a.y not found. Known fields are [private int c.c.a.y.f, private c.a.c.b0$i c.c.a.y.g, private boolean c.c.a.y.h, private static final c.c.a.y c.c.a.y.i, private static volatile c.a.c.a1 c.c.a.y.j], java.lang.RuntimeException: Field androidScanMode_ for c.c.a.y not found. Known fields are [private int c.c.a.y.f, private c.a.c.b0$i c.c.a.y.g, private boolean c.c.a.y.h, private static final c.c.a.y c.c.a.y.i, private static volatile c.a.c.a1 c.c.a.y.j]
E/flutter ( 1455):  at c.a.c.v0.n0(Unknown Source:72)
E/flutter ( 1455):  at c.a.c.v0.T(Unknown Source:697)
E/flutter ( 1455):  at c.a.c.v0.R(Unknown Source:12)
E/flutter ( 1455):  at c.a.c.k0.e(Unknown Source:60)
E/flutter ( 1455):  at c.a.c.k0.a(Unknown Source:49)
E/flutter ( 1455):  at c.a.c.d1.d(Unknown Source:17)
E/flutter ( 1455):  at c.a.c.d1.e(Unknown Source:4)
E/flutter ( 1455):  at c.a.c.z$a.A(Unknown Source:9)
E/flutter ( 1455):  at c.a.c.z$a.z(Unknown Source:4)
E/flutter ( 1455):  at c.a.c.z$a.m(Unknown Source:0)
E/flutter ( 1455):  at c.a.c.a$a.l(Unknown Source:2)
E/flutter ( 1455):  at c.c.a.b.q(Unknown Source:10)
E/flutter ( 1455):  at c.c.a.b.onMethodCall(Unknown Source:1583)
E/flutter ( 1455):  at d.a.c.a.j$a.a(Unknown Source:17)
E/flutter ( 1455):  at io.flutter.embedding.engine.e.b.d(Unknown Source:57)
E/flutter ( 1455):  at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(Unknown Source:4)
E/flutter ( 1455):  at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 1455):  at android.os.MessageQueue.next(MessageQueue.java:336)
E/flutter ( 1455):  at android.os.Looper.loop(Looper.java:174)
E/flutter ( 1455):  at android.app.ActivityThread.main(ActivityThread.java:7405)
E/flutter ( 1455):  at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 1455):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502)
E/flutter ( 1455):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:980)
E/flutter ( 1455): , null)
E/flutter ( 1455): #0      FlutterBlue.scan (package:flutter_blue/src/flutter_blue.dart:123)

Same problem, and no-shrink doesn't solve the problem in 0.8.0

I solved this by creating proguard rules on Android:

-keep class com.pauldemarco.flutter_blue.Protos* { *; }

Have yet to test on iOS though

OK so for me the combination of --no-shrink and -keep class com.pauldemarco.flutter_blue.Protos* { *; }
worked finally.

Would be great to at least document it.

        shrinkResources false    // this line
        minifyEnabled false       // this line

@jimykhan add this code in [project_name]/android/app/build.gradle

    buildTypes {
        release {
            signingConfig signingConfigs.release
            shrinkResources false    // this line
            minifyEnabled false       // this line
        }
    }

This solves the problem for me with Version 0.8.0.

I solved this by creating proguard rules on Android:

-keep class com.pauldemarco.flutter_blue.Protos* { *; }

Have yet to test on iOS though

  1. Does -keep class com.pauldemarco.flutter_blue.* { *; } rule cover -keep class com.pauldemarco.flutter_blue.Protos* { *; } as well? (I think yes)
  2. Aren't ProGuard rules Android only?

@MrCsabaToth How do you create proguard rules in flutter? apologies, beginner question.

@alexflav23 sure, first you will need to create the proguards rules file at android/app/proguard-rules.pro. In this file add the proguard rules as described by ~@MrCsabaToth~ @d-wolf or in the issue #784. After this we will need to tell gradle that these rules exist.
Go into the android/app/build.gradle file and add the proguardFiles option to the correct build type. For you that would probably be:

android {
    release {
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

I've added them to my own project so you can copy what you need from there: https://github.com/jeroen1602/lighthouse_pm/tree/master/android/app

Edit: here is the same link at a specific commit in case it changes in the future and someone still needs help https://github.com/jeroen1602/lighthouse_pm/tree/10eeccbd2200f82dbbff5dee27c18f76ea9151ea/android/app

For more info you can check the developer documentation https://developer.android.com/studio/build/shrink-code

Was this page helpful?
0 / 5 - 0 ratings

Related issues

M3sca picture M3sca  Â·  3Comments

Fleximex picture Fleximex  Â·  5Comments

a-v-ebrahimi picture a-v-ebrahimi  Â·  4Comments

pauldemarco picture pauldemarco  Â·  4Comments

saulopef picture saulopef  Â·  4Comments