Knowledge Base
ProGuard Rules for Android
optimize release builds by preserving essential classes and avoiding runtime crashes problem when building a release version of an android app with minification enabled, the app may crash at runtime due to proguard or r8 shrinking or obfuscating necessary code to ensure the app runs smoothly in release builds, it’s important to explicitly retain critical classes and methods this can be achieved by adjusting your proguard rules to prevent essential code from being removed or altered during the minification process symptoms the app compiles successfully with no errors the app crashes immediately upon launching in a release build logs or crash reports may indicate missing or improperly obfuscated classes/methods example crash log to help identify issues caused by missing or obfuscated classes, here’s a typical crash log that you might encounter when the necessary proguard rules are not applied // example crash log java lang nosuchmethoderror no static method "llive/ditto/internal/swig/ffi/dittoffijni; swigdirector retainable retain(llive/ditto/internal/swig/ffi/retainable;)v” how to diagnose build and deploy build the release apk or aab using the release variant with minification enabled deploy to a device or emulator install and run the app on a real device or emulator crash detection if the app crashes immediately at launch when ditto is created and starts to sync, check the logs via adb logcat or your crash reporting tool to determine the root cause look for missing classes, methods, or any classnotfoundexception or nosuchmethodexception errors solution to ensure optimal app performance when using the ditto sdk, update your proguard rules to retain critical classes depending on the features you're using, you’ll need to add specific rules to prevent proguard from stripping essential code ditto native bindings required for all ditto sdk use this rule ensures that all native bindings related to ditto are preserved and available at runtime keep class live ditto internal swig ffi { ; } ditto blanket exclusion required for presence this rule retains all ditto classes, which is essential for features like https //docs ditto live/sync/using mesh presence#jhjkk , and ensures jackson classes are preserved for proper json deserialization keep class live ditto { ; } keepnames class com fasterxml jackson { ; } explanation keep class live ditto internal swig ffi ensures that all classes and interfaces under the live ditto internal swig ffi package (including sub packages) are retained { ; } specifies that all members (fields, methods, constructors, etc ) of these classes should be preserved as well this rule prevents proguard from shrinking, obfuscating, or modifying these classes, ensuring that your app functions correctly in a minified release build additional tips proguard optimization while adding keep rules is essential, try to keep them as specific as possible to avoid retaining unnecessary classes, which can lead to a larger apk/aab size testing always thoroughly test your app in both debug and release modes use logging or crash reporting to capture issues during the release phase proguard mapping files generate and keep mapping files during your release builds (minifyenabled true) they are useful for decoding stack traces and identifying the causes of crashes related to proguard need additional help? https //docs ditto live/support our support team is ready to assist with any further questions