kodika / MutataApp

49 stars 9 forks source link

How do I include Swift Package Manager packages that also use Objective-C into the project while compiling the Android project? #2

Closed OmerFlame closed 2 years ago

OmerFlame commented 2 years ago

I am trying to compile my app that uses Swift Package Manager packages from repos around GitHub. It gives me errors like this:

https://app.warp.dev/block/BphzG0hwZshxBzkbGPqizs

The first issue is that the package is not resolved at all. The second issue (which is outside the scope of the log I sent) is packages that interface with the Objective-C runtime as well as packages fully written in Objective-C.

Can you help me compile my project along with my Swift Package Manager dependencies? You have no documentation about this...

kostassite commented 2 years ago

There is no direct support for the only Objective-C packages but it is something we are investigating. At the moment we have converted the ones that we needed to Swift. Could you please send us which ones you need?

In order to add Swift Packages, the packages will need to be able to compile in Android so again it depends on their dependencies. You will need to add them as dependencies in the Package.swift file in build/iOSSources and then compiler should find them. Could you please send us the github repos of the needed swift packages?

OmerFlame commented 2 years ago

The first one is Haptica (I am not sure what Objective-C dependencies this has or anything of the sort), and the second one I need is Sentry.

Regarding the Package.swift step, does the file get overwritten every time I run 100-UpdateAndRun.sh? From the very limited testing I did, it seems to do that...

kostassite commented 2 years ago

Haptica: It should work without any changes. We are looking at it and will have an update in the next hours.

Sentry: Are you using any special feature of it or just the setup in their Readme

import Sentry

// ....

SentrySDK.start { options in
    options.dsn = "___PUBLIC_DSN___"
    options.debug = true // Helpful to see what's going on
}   
OmerFlame commented 2 years ago

I am definitely just using Sentry as is. And no, Haptica doesn't just work for me, it says that it has issues with the Objective-C runtime or something like that. Long story short, it didn't compile whatsoever. I am very sure that this is reproducible. If you somehow get it to compile in a project then let me know how you did it.

kostassite commented 2 years ago

Yeah, we just saw the Haptica problem. Could you please send me the ways that you are using Haptica? Which functions are you using? And I will create an Android version of it today which you will be able to compile.

About Sentry we are working on making the code to use Android SDK when run on Mutata.

kostassite commented 2 years ago

Also, about SentrySDK. Could you please send us the code on how you initialize it? Of course, remove your personal details.

OmerFlame commented 2 years ago

The way you sent is exactly how I do it.

OmerFlame commented 2 years ago

I am currently checking about Haptica.

OmerFlame commented 2 years ago

Yeah, we just saw the Haptica problem. Could you please send me the ways that you are using Haptica? Which functions are you using? And I will create an Android version of it today which you will be able to compile.

This is the only time where I use Haptica in my app:

var shouldBeSelected = false {
    didSet {
        if self.shouldBeSelected {
            self.doneAnimationView.removeAnimatableLayer()
        }

        UIView.animate(withDuration: 0.4, animations: {
            self.dimView.alpha = self.shouldBeSelected ? 0.6 : 0
        }, completion: { _ in
            if self.shouldBeSelected {
                self.doneAnimationView.isHidden = false
                self.doneAnimationView.show()
                Haptic.notification(.success).generate()
            } else {
                self.doneAnimationView.isHidden = true
        }
        })
    }
}

That Haptic.notification line is the line.

kostassite commented 2 years ago

If this is the only place that you are using Haptica then you can use the official UIKit code which we already support.

Just replace Haptic.notification(.success).generate() with

        let generator = UINotificationFeedbackGenerator()
        generator.prepare()
        generator.notificationOccurred(.success)

and remove the import of it. It should work in both iOS and Android.

kostassite commented 2 years ago

For Sentry we are creating now the code but you can temporary comment it out

OmerFlame commented 2 years ago

For Sentry we are creating now the code but you can temporary comment it out

Essentially what I did already.

If this is the only place that you are using Haptica then you can use the official UIKit code which we already support.

Just replace Haptic.notification(.success).generate() with

        let generator = UINotificationFeedbackGenerator()
        generator.prepare()
        generator.notificationOccurred(.success)

and remove the import of it. It should work in both iOS and Android.

I will try it out now, thank you very much! I will tell you if it worked or not.

OmerFlame commented 2 years ago

Also, do you have support for SPAlert? Or is it just supposed to work out of the box as well?

kostassite commented 2 years ago

Also, do you have support for SPAlert? Or is it just supposed to work out of the box as well?

No, it will not work out of the box as it uses some low-level CALayer functions, but it doesn't look impossible to implement it in Android.

OmerFlame commented 2 years ago

As far as I know, I got all SPM issues solved for the time being, but now comes Cocoapods. This is beyond the scope of this issue though, and I will talk about it in another issue.