isEmulatorSync() crashes on Android 15/16 with compileSdk 36 — getEnabledInputMethodList() returns InputMethodInfoSafeList
Summary
isEmulatorSync() throws on Android 15/16 devices when the library is built with compileSdk 36. Because it is declared isBlockingSynchronousMethod = true, the exception propagates synchronously into JS:
Exception in HostFunction: Couldn't convert result of type java.util.ArrayList
to com.android.internal.inputmethod.InputMethodInfoSafeListThe failure is in the hasKeyboard("memuime") branch, which calls InputMethodManager.getEnabledInputMethodList(). API 36 changed the declared return type of that method to InputMethodInfoSafeList, and the bridge conversion to List<InputMethodInfo> fails at runtime.
This affects real devices, not just emulators — see Why this always fires below.
Environment
react-native-device-info15.0.2 (current latest;masteris unchanged at the time of writing)- React Native 0.86.2, New Architecture
compileSdk = 36← required to reproduce- Physical hardware, Android 15, arm64 (reproduced on a Samsung foldable)
compileSdk is the key variable. getEnabledInputMethodList() resolves to a different return type depending on the SDK the library is compiled against, so a project on compileSdk 35 will not see this even when running on the same Android 15/16 device. That is likely why this has gone unreported so far — it is gated on build configuration, not on device population. As projects move to compileSdk 36 for Play's target-API requirements, the affected share will grow.
Note that the library picks this up automatically: android/build.gradle line 25 reads
compileSdkVersion safeExtGet('compileSdkVersion', 34)so any app that sets compileSdkVersion = 36 in its root project compiles this module at 36 too. No unusual Gradle setup is involved.
Why this always fires on real hardware
|| (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")
|| this.hasKeyboard("memuime"));The grouping here parses as (A && B) || C, so hasKeyboard(...) is not guarded by the Build.BRAND/Build.DEVICE test. The indentation suggests the intent was for all three to form one emulator heuristic, but as written the inner || escapes that grouping.
The practical consequence: on a real device every preceding Build.* check is false, so the || chain never short-circuits and hasKeyboard() is always reached. Every compileSdk 36 build calling isEmulatorSync() on Android 15/16 throws, regardless of whether it is an emulator.
RNDeviceModule.java:1115 then calls the enumeration unguarded:
private boolean hasKeyboard(String name) {
List<InputMethodInfo> inputMethodList = this.inputMethodManager.getEnabledInputMethodList();
...Impact
Because isEmulatorSync() is a blocking synchronous method, callers cannot always defend against it. If the call sits in a module-level constant initialiser, it throws during import evaluation — before any caller's try/catch has been established — and takes down cold launch. In our case two separate layers of app-side error handling around the calling function were both unreachable for that reason.
Suggested fix
Two independent changes, either of which stops the crash; together they also fix the latent logic bug.
1. Guard the enumeration. It is a best-effort heuristic for one emulator brand, so failing closed is safe:
private boolean hasKeyboard(String name) {
- List<InputMethodInfo> inputMethodList = this.inputMethodManager.getEnabledInputMethodList();
- if (inputMethodList != null && !inputMethodList.isEmpty()) {
- for (InputMethodInfo inputMethodInfo : inputMethodList) {
- String serviceName = inputMethodInfo.getServiceName() != null ? inputMethodInfo.getServiceName().toLowerCase() : "";
- String id = inputMethodInfo.getId() != null ? inputMethodInfo.getId().toLowerCase() : "";
- if (serviceName.contains(name.toLowerCase()) || id.contains(name.toLowerCase())) {
- return true;
+ try {
+ List<InputMethodInfo> inputMethodList = this.inputMethodManager.getEnabledInputMethodList();
+ if (inputMethodList != null && !inputMethodList.isEmpty()) {
+ for (InputMethodInfo inputMethodInfo : inputMethodList) {
+ String serviceName = inputMethodInfo.getServiceName() != null ? inputMethodInfo.getServiceName().toLowerCase() : "";
+ String id = inputMethodInfo.getId() != null ? inputMethodInfo.getId().toLowerCase() : "";
+ if (serviceName.contains(name.toLowerCase()) || id.contains(name.toLowerCase())) {
+ return true;
+ }
}
}
+ } catch (Throwable t) {
+ // Best-effort emulator heuristic — a platform change here must not take down the caller.
+ return false;
}
return false;
}2. Fix the parenthesisation so the input-method probe only runs for candidates that already look like an emulator:
- || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")
- || this.hasKeyboard("memuime"));
+ || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic"))
+ || this.hasKeyboard("memuime");This changes behaviour only for devices where exactly one of BRAND/DEVICE starts with generic — but it is worth doing regardless, since the current form reads as a mistake.
Worth considering beyond this specific fix: any future platform change to a Build.* or system-service call in the isEmulatorSync() chain will surface the same way — synchronously, potentially during module evaluation. Hardening the method as a whole would prevent the next instance of this.
Related: #1722 was a NullPointerException in this same loop, fixed by null-checking inside the iteration rather than guarding the call itself.
Workaround
For anyone hitting this before a fix lands: wrap the call so a failing probe degrades to a fallback instead of throwing, and make sure it is not invoked from a module-level initialiser. That stops the crash, at the cost of isEmulator reading permanently false on affected devices.
Happy to send the above as a PR if that is useful.
Source: react-native-device-info/react-native-device-info