How to disable code obfuscation in Flutter release apk?
Asked Answered
M

1

5

I have built out a video conferencing app in Flutter by leveraging the agora-rtc-engine (https://pub.dev/packages/agora_rtc_engine)

My app is working perfectly find on the debug version, but it crashes whenever I try to join a room/video conference in the release version of the app. The pub-dev page of the library mentions that it is due to code obfusciation by Flutter. The method they have shown to prevent the crash is outdated (proguard.rules). So, how do I go about fixing it now?

Here is the complete source code : https://github.com/CodeSarthak/Vartalap

Any help is appreciated. Thanks a lot!

Maunder answered 10/7, 2020 at 11:45 Comment(0)
N
6

It Normally Happens you just need to add a file with little settings :D

  • Create A proguard rule to define what's to prevent Here is What's Worked for me, based on your App you might need to add more things specific to your solution. :D
  • Create A ProGuard File

proguard screenshot

Code: Create a File: proguard-rules.pro

## Flutter wrapper
-keepattributes Signature
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.**  { *; }
-keep class io.flutter.util.**  { *; }
-keep class io.flutter.view.**  { *; }
-keep class io.flutter.**  { *; }
-keep class io.flutter.plugins.**  { *; }
-keep class com.google.firebase.** { *; }
-keepattributes JavascriptInterface
-keepattributes Annotation
-dontwarn com.razorpay.**
-keep class com.razorpay.** { *; }
-optimizations !method/inlining/
-keepclasseswithmembers class * {public void onPayment*(...);}
-keepclassmembers class * {@android.webkit.JavascriptInterface ;}
-keepclassmembers class com.yourpackagehere.models.** { *; }
-dontwarn io.flutter.embedding.**
  • And to Add it to app level gradle file

settings in gradle

Code:

Inside build.gradle

buildTypes {
   
        release {
            shrinkResources false
            signingConfig signingConfigs.release
            minifyEnabled false
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

Hope this Helps you :D

Nyctalopia answered 10/7, 2020 at 14:40 Comment(2)
-keepclassmembers class * {@android.webkit.JavascriptInterface ;} this line breaks the build... remove this to can build appbundleSlacker
shrinkResources true minifyEnabled trueTisbee

© 2022 - 2024 — McMap. All rights reserved.