Netty: StrictMode Violations on Android Due to Non-SDK API Usage

9 views
Skip to first unread message

Igor Khrupin

unread,
May 1, 2025, 12:29:28 AMMay 1
to ne...@googlegroups.com, Maxime Roussy

Hi Netty Team,

We’re encountering two StrictMode violations on Android when using Netty, both related to usage of non-SDK interfaces. These occur with StrictMode.VmPolicy.Builder().detectNonSdkApiUsage() enabled on Android 9 and above.
Reference: StrictMode Documentation

Environment:

  • Netty version: 4.1.72 (also reproduced on 4.1.99)

  • Android version: 10+

  • Use case: MQTT client via HiveMQ (which uses Netty internally)


Violation 1: sun.misc.VM.maxDirectMemory()

StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Lsun/misc/VM;->maxDirectMemory()J at android.os.StrictMode.lambda$static$1(StrictMode.java:430) at java.lang.Class.getDeclaredMethodInternal(Native Method) at io.netty.util.internal.PlatformDependent.maxDirectMemory0(PlatformDependent.java:1097) ...
  • Module: common

  • Class: PlatformDependent

  • Method: maxDirectMemory0()

Violation 2: SelectorImpl.selectedKeys

StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Lsun/nio/ch/SelectorImpl;->selectedKeys:Ljava/util/Set; at android.os.StrictMode.lambda$static$1(StrictMode.java:430) at java.lang.Class.getDeclaredField(Native Method) at io.netty.channel.nio.NioEventLoop.openSelector(NioEventLoop.java:209) ...
  • Module: transport

  • Class: NioEventLoop

Reproduction Steps:

  1. Integrate Netty into an Android application

  2. Enable this StrictMode config on Android 9+:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { StrictMode.setVmPolicy( new StrictMode.VmPolicy.Builder() .detectNonSdkApiUsage() .penaltyLog() .build() ); }
  3. Run the app on a device or emulator

  4. Observe the violations in Logcat


Request:
Could you advise whether these internal API usages can be eliminated or optionally isolated behind a configurable flag?

We appreciate your work and contributions to the Netty project — thank you!

Best regards,

--

Igor Khrupin

Senior Software Engineer II | Life360 Inc.

1900 S Norfolk St #310,
San Mateo, CA 94403


Check out our open positions: life360.com/careers


Reply all
Reply to author
Forward
0 new messages