Better error reporting when an expected bridged method is not found

Aperta
#85 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@aabewhite ci sta già lavorando.

Dal 10/5/2025.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement

The R8/proguard process for Android release builds will often minify (i.e., mangle) Java names. When the Swift side of the bridge attempts to look up a method name that cannot be found like so:

let Java_set_count_methodID = Java_class.getMethodID(name: "setCount", sig: "(I)V")!

the program will simply crash with the unhelpful error:

Fatal error: Unexpectedly found nil while unwrapping an Optional value

What we might instead do is have the method lookup happen in a forced try! with a throwable function, so the error log will at least contain the name of the method that was sought:

let Java_set_count_methodID = try! Java_class.getMethodIDAndThrowErrorIfMissing(name: "setCount", sig: "(I)V")

That way, we can get an error like:

Fatal error: Could not find Java method setCount on the class APIClient bridged from APIClient.swift:1234 (release mode; did you add it to your proguard-rules.pro file?)

This will at least provide some guidance to the user at development time (and in Crashlytics reports if it happens in a deployed app) about the potential cause of the method not being found.

Lingua principale
Swift
Stelle
7
Fork
8
Merge medio
1g 2h
PR unite (30g)
2

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 skiptools/skip-bridge

Tutte le issue di skiptools/skip-bridge

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.