Crashlytics NDK Proguard config is incorrect
nathan3d opened this issue · 5 comments
[READ] Step 1: Are you in the right place?
Issues filed here should be about bugs in the code in this repository.
If you have a general question, need help debugging, or fall into some
other category use one of these other channels:
- For general technical questions, post a question on StackOverflow
with the firebase tag. - For general Firebase discussion, use the firebase-talk
google group. - For help troubleshooting your application that does not fall under one
of the above categories, reach out to the personalized
Firebase support channel.
[REQUIRED] Step 2: Describe your environment
- Android Studio version: Jellyfish
- Firebase Component: Crashlytics NDK
- Component version: 19.2.1
[REQUIRED] Step 3: Describe the problem
The keep rules for the Crashlytics NDK are limited to public classes, but at the minimum JniNativeApi is not a public class, so the included rules don't actually apply.
The Android Gradle Plugin includes this rule that mitigates the issue when used, but for builds using other build systems, this may not be present.
-keepclasseswithmembernames,includedescriptorclasses class * {
native <methods>;
}
Hi @nathan3d, thank you for reaching out. According to Firebase SDK docs,
Firebase SDKs do not proguard themselves, but support proguarding. Firebase SDKs themselves are proguard friendly, but the dependencies of Firebase SDKs may not be.
From what I gather, Android Gradle Plugin (AGP) seamlessly integrates ProGuard into the build process; other build systems require manual configuration. For more information, you can check this for reference.
However, based on proguard documentation for processing native methods,
ProGuard doesn't look at your native code, so it won't automatically preserve the classes or class members that are invoked by the native code.
I suggest checking DexGuard, this is a commercial extension of ProGuard. DexGuard is specialized for Android applications and libraries: it optimizes and obfuscates not just the bytecode, but also the manifest file, resources, resource files, asset files, and native libraries.
Hi @lehcar09,
There are Proguard/R8 rules for the NDK published as part of the project here: https://github.com/firebase/firebase-android-sdk/blob/main/firebase-crashlytics-ndk/firebase-crashlytics-ndk-proguard.txt.
They're just not correct.
Thank you for your clarification. Based on my understanding with proguard, the rule;
-keepclasseswithmembernames,includedescriptorclasses class * { native <methods>; }
aims to keep all classes with native methods across your entire project. While the rule,
-keep public class com.google.firebase.crashlytics.ndk.JniNativeApi { native <methods>; }
specific rules for Firebase Crashlytics that are designed to preserve particular classes and their native methods. However, adding the broad rule might have side effects on optimizations. I’ll raise this to our engineers and see what we can do here. Thanks!
Right. The problem is JNINativeApi isn't public, so this rule has no effect.
Replacing:
-keep public class com.google.firebase.crashlytics.ndk.JniNativeApi { native <methods>; }
with:
-keep class com.google.firebase.crashlytics.ndk.JniNativeApi { native <methods>; }
would fix the issue, at least for JniNativeApi
. I think some of the others may need updating as well. I haven't had a chance to verify all of the rules.