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

Aperta
#8,040 1 commento 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
android, typescript
Ambito
cli, mobile

Direzione di ricerca

Inizia da android/app/build.gradle e dal percorso di esecuzione Android invocato da npx cap run android; esamina come la CLI seleziona l’APK in android/app/build/outputs/apk/debug. Confronta questa logica con output-metadata.json e con l’APK rinominato nella riproduzione collegata, quindi verifica che cap run distribuisca l’output generato senza presupporre app-debug.apk.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

cli platform: android type: bug
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
`npm --version` output: 10.9.2
`node --version` output: v22.14.0
Platforms Affected
  • iOS
  • 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:

× 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, 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.

Lingua principale
TypeScript
Stelle
17.1k
Fork
1.3k
Merge medio
1g 22h
PR unite (30g)
26

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor

Tutte le issue di ionic-team/capacitor

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.