Skip to content

Fuse: "Unable to bridge Swift instance" when passing a delegate #576

@dfabulich

Description

@dfabulich

Consider this branch of the Fuse Showcase. https://github.com/dfabulich/skipapp-showcase-fuse/tree/audio-bug-example

In dfabulich/skipapp-showcase-fuse@3b4d8c4 there's a very basic start of an audio playground.

import SwiftUI
#if canImport(SkipAV)
import SkipAV
#else
import AVKit
#endif

struct AudioPlayerPlayground: View {
    let audioPlayer = try? AVAudioPlayer(contentsOf: URL(string: "https://dare.wisc.edu/wp-content/uploads/sites/1051/2017/08/HI009clip.mp3")!)
    var body: some View {
        Text("Hello, World!")
            .task {
                logger.log("creating delegate")
                let delegate = AudioPlayerDelegate()
                logger.log("setting delegate")
                audioPlayer?.delegate = delegate
                logger.log("playing")
                audioPlayer?.play()
            }
    }
}

class AudioPlayerDelegate: NSObject, AVAudioPlayerDelegate {
    func audioPlayerDidFinishPlaying(_ player: AVAudioPlayer, successfully flag: Bool) {
        print("Finished playing")
    }
}

It builds just fine, but if you launch it on Android and navigate to the audio playground, the app will crash, with this error:

SkipBridge/BridgedTypes.swift:198: Fatal error: Unable to bridge Swift instance <AudioPlayerDelegate: 0xb40000706ae94ab0> of type: AudioPlayerDelegate

It seems like it's not possible to implement a protocol in Fuse code and pass it to transpiled Kotlin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bridgingIssues around bridging Swift to Kotlin or Kotlin to SwiftbugSomething isn't workingfuseIssues with natively-compiled Swift (Skip Fuse) and bridge generation between Swift and Kotlin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions