google / google/prefab

[BUG] Error: no such option | when <package_path> contains =

Open
#187 2 comments 2 reactions 0 assignees View on GitHub
bug
Dominant language
Kotlin
Stars
236
Forks
33
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

Prefab fails with `Error: no such option` when a `` positional argument contains an `=` character. Clikt's argument parser interprets the text before `=` as an option name (e.g. `--patch_hash=abc123`), even though the token is a positional argument, not an option.

This breaks all **pnpm** users who have patched dependencies, because pnpm encodes patch hashes in directory names:

```
node_modules/.pnpm/react-native-reanimated@4.1.0_patch_hash=f8d3886b.../
```

When AGP invokes prefab via `GeneratePrefabPackages.kt`, these paths are passed as positional `` arguments without a preceding `--`, causing the parse failure.

**To Reproduce**

1. Create a minimal prefab package:

```bash
mkdir -p /tmp/repro/pkg/modules/test/libs/android.arm64-v8a
echo '{"schema_version": 2, "name": "test", "version": "1.0.0", "dependencies": []}' \
> /tmp/repro/pkg/prefab.json
echo '{"export_libraries": [], "android": {"export_libraries": [], "library_name": null}}' \
> /tmp/repro/pkg/modules/test/module.json
echo '{"abi": "arm64-v8a", "api": 24, "ndk": 27, "stl": "c++_shared"}' \
> /tmp/repro/pkg/modules/test/libs/android.arm64-v8a/abi.json
touch /tmp/repro/pkg/modules/test/libs/android.arm64-v8a/libtest.so
```

2. Copy it to a path containing `=`:

```bash
mkdir -p "/tmp/repro/some-lib@1.0.0_patch_hash=abc123"
cp -r /tmp/repro/pkg "/tmp/repro/some-lib@1.0.0_patch_hash=abc123/pkg"
```

3. Run prefab with the `=`-containing path as a positional argument:

```bash
java -jar prefab-cli-2.1.0-all.jar \
--build-system cmake --platform android --abi arm64-v8a \
--os-version 24 --stl c++_shared --ndk-version 27 \
--output /tmp/repro/out \
"/tmp/repro/some-lib@1.0.0_patch_hash=abc123/pkg"
```

**Expected behavior**

Prefab should treat the path as a positional `` argument and process it normally, regardless of whether the path contains `=`.

**Logs**

```
Usage: prefab [] ...

Error: no such option /tmp/repro/some-lib@1.0.0_patch_hash
```

Adding `--` before the positional arguments works around the issue:

```bash
java -jar prefab-cli-2.1.0-all.jar \
--build-system cmake --platform android --abi arm64-v8a \
--os-version 24 --stl c++_shared --ndk-version 27 \
--output /tmp/repro/out \
-- "/tmp/repro/some-lib@1.0.0_patch_hash=abc123/pkg"
# exits 0
```

**Environment:**

Prefab version: 2.1.0
Host OS: macOS 26.3.1 (also reproduces on Linux EAS build workers)
Target platform: android
Target ABI: arm64-v8a
Target OS version: 24
Build system: cmake

**Additional context**

The root cause is in [`Cli.kt`](https://github.com/google/prefab/blob/master/cli/src/main/kotlin/com/google/prefab/cli/Cli.kt) where `PACKAGE_PATH` is declared as a clikt `argument()`:

```kotlin
private val rawPackagePaths: List by argument("PACKAGE_PATH").file(
canBeFile = false, mustBeReadable = true
).multiple(required = true)
```

Clikt treats any token containing `=` as `--option=value` syntax before considering positional arguments.

This affects pnpm monorepo users with React Native + New Architecture. pnpm appends `patch_hash=` to directory names when a package is patched. Since `react-native` is commonly patched, every native library that depends on it gets `=` in its resolved path. AGP's [`GeneratePrefabPackages.kt`](https://android.googlesource.com/platform/tools/base/+/refs/heads/mirror-goog-studio-main/build-system/gradle-core/src/main/java/com/android/build/gradle/tasks/GeneratePrefabPackages.kt) passes these paths without `--`:

```kotlin
.addArgs(prefabPackages.map { it.packageFolder.path })
```

**Suggested fix** (either one):

1. **In prefab:** Insert `--` before the `PACKAGE_PATH` arguments in the argument parser, or configure clikt to not interpret `=` in positional tokens.
2. **In AGP:** Add `.addArgs("--")` before `.addArgs(prefabPackages.map { it.packageFolder.path })` in `GeneratePrefabPackages.kt`.

Previously reported (and closed without fix) at:
- [software-mansion/react-native-reanimated#8252](https://github.com/software-mansion/react-native-reanimated/issues/8252)
- [expo/expo#40963](https://github.com/expo/expo/issues/40963)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.