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
<https://developer.android.com/reference/android/os/StrictMode>
*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
--
You received this message because you are subscribed to the Google Groups
"Netty discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/netty/CAJFw7k2-Yz9P%3DSN_P%3Dbzqk8EUuh%2Bw7mUOeXoD6djXzt_fsDW_A%40mail.gmail.com.