Skip to content

sentry-android-ndk proguard rule keeps all native class #4426

@ghasemdev

Description

@ghasemdev
Contributor

Integration

sentry-android-ndk

Build System

Gradle

AGP Version

8.9.2

Proguard

Enabled

Version

7.22.5

Steps to Reproduce

Some third-party libraries include the following ProGuard rule:

-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

This rule is too broad and prevents class name obfuscation for all classes with native methods — not just those from the library itself.
This impacts security and maintainability in downstream projects, especially in cases where native methods contain security-sensitive logic and developers want to obscure their names.

  1. Include a library that contains the following rule in its ProGuard file:

    -keepclasseswithmembernames,includedescriptorclasses class * {
        native <methods>;
    }
    
  2. Add your own class with a native method:

    public class SecureNative {
        public native void signTransaction(byte[] input);
    }
  3. Build with R8 enabled.

  4. Inspect the mapping file or APK — the class and method names will not be obfuscated.

Log output

No error, but the obfuscation is blocked unexpectedly.

Expected Result

Third-party libraries should scope ProGuard rules only to their own package, for example:

-keepclasseswithmembernames,includedescriptorclasses class io.sentry.** {
    native <methods>;
}

🔐 Security concern

In our project, we use native methods for security-critical operations (e.g., cryptographic signing, hardware access). These method names should be obfuscated to prevent easy reverse engineering.
However, the use of overly broad ProGuard rules from dependencies prevents that, and we are forced to manually clean the merged configuration.txt before release — which is fragile and error-prone.

Actual Result

Update the ProGuard rule to scope it only to your own package:

-keepclasseswithmembernames,includedescriptorclasses class io.sentry.** {
    native <methods>;
}

Activity

moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on May 21, 2025
changed the title [-]sentry-androi-ndk proguard rule keeps all native class[/-] [+]sentry-android-ndk proguard rule keeps all native class[/+] on May 21, 2025
markushi

markushi commented on May 21, 2025

@markushi
Member

@ghasemdev thanks for opening this up! This is indeed an issue on our end, seems like it's always been this way, but we should definitely fix this!

moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on May 21, 2025
romtsn

romtsn commented on May 21, 2025

@romtsn
Member

@markushi I guess we could actually remove this proguard-rules.pro file altogether since we consume the ndk artifact from sentry-native now, right? And make the actual fix there.

14 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

    Participants

    @supervacuus@markushi@romtsn@stefanosiano@lcian

    Issue actions

      sentry-android-ndk proguard rule keeps all native class · Issue #4426 · getsentry/sentry-java