expo/expo

[Expo-46 || expo-device] Device.deviceName constant crashes Android 13

Closed this issue · 5 comments

Summary

When building expo-46 with expo-device on any Android 13 device, the application crashes right after launch with the following message:

<bluetooth_name> is only readable to apps with targetSdkVersion lower than or equal to: 31

This issue is related to this line of code: https://github.com/expo/expo/blob/main/packages/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt#L66

By simply making the constant return an empty string (via patching expo-device), my app is compiling and running fine again. I would suggest that you remove "deviceName" or use an alternative for the deviceName that works on all android levels.

What platform(s) does this occur on?

Android

Environment

expo-env-info 1.0.5 environment info:
System:
OS: macOS 12.5.1
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 3.2.2 - ~/.yarn/bin/yarn
npm: 8.5.0 - /usr/local/bin/npm
Managers:
CocoaPods: 1.11.3 - /Users/alex/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
Android SDK:
API Levels: 28, 29, 30, 31, 32, 33
Build Tools: 30.0.2, 30.0.3, 31.0.0, 32.0.0, 33.0.0
System Images: android-29 | Google Play Intel x86 Atom, android-31 | Google Play Intel x86 Atom_64, android-32 | Google APIs Intel x86 Atom_64, android-32 | Google Play Intel x86 Atom_64, android-33 | Google APIs Intel x86 Atom_64, android-33 | Google Play Intel x86 Atom_64
IDEs:
Android Studio: 2021.2 AI-212.5712.43.2112.8815526
Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
npmPackages:
expo: 46.0.8 => 46.0.8
react: 18.0.0 => 18.0.0
react-native: 0.69.4 => 0.69.4
Expo Workflow: bare

Minimal reproducible example

  • Use any expo 46 project with target sdk level of 32 or heigher.
  • Install expo-device
  • Consume deviceName from that package
  • Compile and run project on an Android 13 device

Thank you for filing this issue!
This comment acknowledges we believe this may be a bug and there’s enough information to investigate it.
However, we can’t promise any sort of timeline for resolution. We prioritize issues based on severity, breadth of impact, and alignment with our roadmap. If you’d like to help move it more quickly, you can continue to investigate it more deeply and/or you can open a pull request that fixes the cause.

We are running into this same issue now. Is there any update on this?

Our app is crashing on lunch on android 13.

I can also confirm commenting it out and replace it with empty string does fixes the crash

Same issue here. Does not happen on an Android 12 device though. Pixel 6 with Android 13 crashes immediately.

Here is my temp patch for this:

diff --git a/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt b/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt
index 0984d45..c3f5e08 100644
--- a/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt
+++ b/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt
@@ -62,7 +62,7 @@ class DeviceModule(private val mContext: Context) : ExportedModule(mContext) {
     "osInternalBuildId" to Build.ID,
     "osBuildFingerprint" to Build.FINGERPRINT,
     "platformApiLevel" to Build.VERSION.SDK_INT,
-    "deviceName" to Settings.Secure.getString(mContext.contentResolver, "bluetooth_name")
+    "deviceName" to ""
   )
 
   private val deviceYearClass: Int

For future reference, here https://github.com/expo/expo/pull/19666/files, another alternative for this issue

diff --git a/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt b/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt
index 0984d45..c3f5e08 100644
--- a/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt
+++ b/node_modules/expo-device/android/src/main/java/expo/modules/device/DeviceModule.kt
@@ -62,7 +62,7 @@ class DeviceModule(private val mContext: Context) : ExportedModule(mContext) {
     "osInternalBuildId" to Build.ID,
     "osBuildFingerprint" to Build.FINGERPRINT,
     "platformApiLevel" to Build.VERSION.SDK_INT,
-    "deviceName" to Settings.Secure.getString(mContext.contentResolver, "bluetooth_name")
+    "deviceName" to run {
+      if (Build.VERSION.SDK_INT <= 31)
+        Settings.Secure.getString(mContext.contentResolver, "bluetooth_name")
+      else
+        Settings.Global.getString(mContext.contentResolver, Settings.Global.DEVICE_NAME)
+    },
   )
 
   private val deviceYearClass: Int