ionic-team / ionic-team/capacitor

[Bug]: `cap run` fails with renamed outputs

Open
#8,040 1 comment 1 reaction 0 assignees View on GitHub
cli platform: android type: bug
Dominant language
TypeScript
Stars
16.7k
Forks
1.3k
Avg merge
3d 15h
Merged PRs (30d)
10

Description

### Capacitor Version

Latest Dependencies:

@capacitor/cli: 7.4.0
@capacitor/core: 7.4.0
@capacitor/android: 7.4.0
@capacitor/ios: 7.4.0

Installed Dependencies:

@capacitor/ios: not installed
@capacitor/cli: 7.2.0
@capacitor/android: 7.2.0
@capacitor/core: 7.2.0

[success] Android looking great! 👌

### Other API Details

```Shell
`npm --version` output: 10.9.2
`node --version` output: v22.14.0
```

### Platforms Affected

- [ ] iOS
- [x] Android
- [ ] Web

### Current Behavior

In preparation for publishing an app to F-Droid, I've configured my gradle build to use a more descriptive output name, so the APK includes the version. To do this, I've added the following line to _~\android\app\build.gradle_:

```
android {
defaultConfig {
...
archivesBaseName = "$applicationId-v$versionCode"
...
```

This means that the output APK is now named _io.ionic.starter-1-debug.apk_ (for example), rather than _app-debug.apk_.

However, when I try to run the app via `npx cap run android`, it now fails with the error:

``` sh
× Deploying app-debug.apk to 28231FDH200GGJ - failed!
[error] Selected hardware device 28231FDH200GGJ
Error: ENOENT: no such file or directory, open 'C:\Dvt\myApp\android\app\build\outputs\apk\debug\app-debug.apk'
```

### Expected Behavior

I would expect the CLI to determine the name of the APK built and use that, rather than expecting it to be _app-debug.apk_.

### Project Reproduction

https://github.com/davidgeary/hardcoded-apk

### Additional Information

A similar error about the CLI hardcoding the APK name was reported (and fixed) in #4740, but this was in regard to the configuration of flavours resulting in different APK names being generated and as such, the fix was very specific to the use of flavours.

But since the APK name can also be changed via the `archivesBaseName` setting and [other ways](https://github.com/ionic-team/capacitor/issues/4740#issuecomment-989102489), a more generic fix is required. For example, @dragermrb's suggestion of parsing _~\android\app\build\outputs\apk\debug\output-metadata.json_ appears to be a much more robust way of identifying the output from the build and would work regardless of the way the output filename was set.

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.