Skip to content

apps:init: Android module detected by first path segment instead of basename, producing app/app output path #10863

Closed

Description

@Zuhef

Which CLI command are you experiencing an issue with?

apps:init (Android)

Description

findIntelligentPathForAndroid in src/management/apps.ts decides "am I already inside the Android app module?" by looking at the first path segment instead of the last:

https://github.com/firebase/firebase-tools/blob/master/src/management/apps.ts#L794-L797

const paths = appDir.split("/");
// For when app/build.gradle is found
if (paths[0] === "app") {
  return appDir;
}

The docstring right above it says the intent is the opposite of what the code does:

android/build.gradle // if it's this, choose app
android/app/build.gradle // if it's this, choose current dir.

For any realistic appDir the first segment is not app — it is android for android/app, and "" for an absolute path like /home/me/proj/android/app. So the early return is effectively dead, and correctness falls through to the src heuristic below it. When the module has no src directory, the function appends app a second time and returns a path that does not exist:

appDir expected actual
android/app (contains src/) android/app android/app (via the src check, not the intended branch)
android/app (no src/, e.g. libs/ + build.gradle) android/app android/app/app

getSdkOutputPath then writes google-services.json into that non-existent nested directory.

There is a second, smaller problem in the same line: split("/") is separator-dependent, so it can never match on Windows, where appDir arrives with \ after path.join.

Steps to reproduce

Adding this case to the existing getAndroidPlatform table in src/management/apps.spec.ts reproduces it:

{
  desc: "Inside app folder without a src directory",
  folderName: "android/app",
  folderItems: { libs: {}, "build.gradle": "" },
  output: "android/app",
},
1 failing
  Inside app folder without a src directory:
  AssertionError: expected 'android\app\app' to equal 'android/app'

Expected behavior

An appDir whose basename is app should be treated as the app module and returned as-is, regardless of path separator or how many segments precede it.

Additional context

Using path.basename(appDir) === "app" fixes both the wrong-segment logic and the separator dependence.

Separately, while confirming this on Windows I found that three assertions in src/management/apps.spec.ts hardcode forward slashes while the implementation builds paths with path.join, so npm run mocha -- src/management/apps.spec.ts is red on a Windows checkout (expected 'android\app' to equal 'android/app', and the same for ios\abc). Unit tests only run on ubuntu-latest/macos-latest in node-test.yml, so CI doesn't surface it. I'll include that in the PR since it's the same line-of-code area.

Environment

  • firebase-tools: 15.24.0 (current master, commit 0636759)
  • Node: v22.18.0
  • OS: Windows 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions