Android 17 (API37) Firebase Emulator Fun
Problem
I found I could no longer connect to my Firebase Emulator from my physical device. My emulated Android devices worked just fine.
Interesting...
At first I thought it may have been a problem with my app, setup, or device settings. It didn't take long to discover it was related to Android 17 Enforcement.
I updated my physical phone to Android 17 (API 37) earlier in the day so suspected that may be related.
The network status itself was easy to check from my phone. I just entered my hosting computer's IP address in my browser http://192.168.1.53:4000. This gave me the emulator dashboard so I knew it was connecting as expected and was not a network problem.
Solution
Took a little time to narrow down the least I needed to do to solve the problem, but it is basically just a single manifest permission - android.permission.ACCESS_LOCAL_NETWORK:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
<application
android:allowBackup="true"
I thought I may need to deal with networkSecurityConfig and usesCleartextTraffic in the manifest, but it turns out I didn't need to.
Of course, if you run your app with the fix above you still have two problems.
- It won't work (unless you did something else)
- Your manifest now has a permission only needed for debug
Fixes
Problem 1
For number one, you can add a permission dialogue to your app but its far easier just to go into the app settings and manually. Just go into App Info and set Allow Nearby Devices. I believe you would need to allow this for the device in general as well.
Problem 2
For number two, the manifest issue, you can solve this with Build Flavors, which you may already be using.
As you might be able to understand from the listing below, I'm using sharedEmulator and production flavors.
My sharedEmulator basically allows a bunch of my test projects to all use the same emulator so I can easily test different projects without needing to mess around with multiple emulator configs and instances.
android {
namespace = "...."
compileSdk {
version = release(37)
}
...
flavorDimensions += "environment"
productFlavors {
create("sharedEmulator") {
dimension = "environment"
applicationIdSuffix = ".emulator"
versionNameSuffix = "-EMU"
isDefault = true
}
create("production") {
dimension = "environment"
}
}
}
kotlin {
jvmToolchain(21)
}
Now we have build flavors, we can can simply make a new AndroidManifest.xml in the sharedEmulator folder:
- AppName\app\src\main
- AppName\app\src\production
- AppName\app\src\sharedEmulator
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Permission added ONLY for debug builds -->
<uses-permission android:name="android.permission.ACCESS_LOCAL_NETWORK" />
</manifest>
And don't forget to remove the permission from the original manifest if you added it there.
Links
Official Android 17 Related
- Android 17 Enforcement (part of Local network permission)
- Android 17 About
- Behavior changes: all apps
- Behavior changes: Apps targeting Android 17 or higher




Comments
Post a Comment