Android 17 (API37) Firebase Emulator Fun

D9 Magazine Front Cover

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.

  1. It won't work (unless you did something else)
  2. Your manifest now has a permission only needed for debug
It's probably better just to try the fix above to start then solve the problems in order so you know it works.

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.



The only thing you need to worry about is resetting the settings and forgetting you need to do this.

Of course, you could also have the app prompt you for this.

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

And this is the entire manifest in that shared folder (it will pull the other details from the manifest in main):

<?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

Comments

Popular posts from this blog

Android AGP 8.x.x -> 9.0.0 Deprecations / Config Changes

KMP (Kotlin Multiplatform) Windows Quick Start

DataStore / SharedPreferences 2026 - Part 1 of 2