Hi :) Has anyone managed to add Firebase in a pro...
# multiplatform
a
Hi :) Has anyone managed to add Firebase in a project generated by Kotlin's Wizard for Android and iOS? I mean, there is only one gradle file for composeApp module and the project level gradle. So, I am confused about the necessary dependencies and plugins and where to add them. Reference: https://medium.com/@niranjanky14/how-do-you-configure-your-firebase-project-for-android-app-in-compose-multiplatform-c239c8cb4d4a
j
Yes I have. What do you want to know and which Firebase products using?
1
https://github.com/GitLiveApp/firebase-kotlin-sdk I use this. But depending on use case could need tweak per platform. Google provides firebase for iOS, web and Android. iOS variant is objc supported, so can use cocoapods for iOS and use directly if KMP Firebase not suits all needs. Be aware need setup google play services different per platform.
a
Great :) I just need firestore and storage (desirable). For this moment I already managed to make it work on Android by configuring FirebaseApp with an options object. I just had to add the dependencies in commonMain. Later I will check if it also works for iOS by just adding that initialization, I hope I don't have to add more dependencies with Cocoapods because it has only caused me problems. I will check also the provided link :) If iOS not works, guess I will change the approach.
j
I use KMP Firebase Firestore with iOS and Android without issue :)
a
Can you guide to configure Firestore on iOS? 😅 It’s the only remaining step… Android is working well and I just added the gitlive dependencies in commonMain and initializing FirebaseApp manually. So, guess I need to share the Firebase Kotlin Sdk though the binaries or install dependencies (manually or with cocoapods 🙁) But, it is only about that, initialize firestore on iOS. ..
j
If initialize Firebase from iOS AppDelegate you should be able use KMP Firestore in commonMain for both Android and iOS. Its just call FirebaseFirestore. If need serialized objects, make sure using kotlinx serialization.
In Xcode make also sure link binaries to firebase libs.
a
Yes, I will try using the AppDelegate to init Firestone on iOS. About your second comment, can you explain it? I do not have almost any experience on iOS development 😅 😅
j
Yeah I am primary Android dev myself so Xcode not my expertise. But if open your iOS project in Xcode. Then go to build phases in project settings I think and add in link binaries. I tried do this without Xcode and use cocoapods static linking but failed.
Worth adding devlive firebase includes these cocoapods for iOS target already but seems not working as should in Kotlin cocoapods plugin link these into shared modules in multi modules. At least I never succeded. If youre able to please tell me how 😁
a
After many attempts, I decided to use cocoapods, but iOS app still showing problems linking libraries I think 🥲 🥲 🥲 🥲 Xcode does not find Firebase imports but I can write code 😂
j
Yes follow my post above and add them manually 🙂
1
a
A few weeks ago I installed them manually and the same error was displaying XD but I will trust this time should work. May I remove cocoapods first? I did not linked the shared module through the pod file. It was just to install the Firebase dependencies.
j
Dont know how your setup looks like. I use cocoapods and also using framework isStatic = false in my shared module.
Need to link both the shared module and the cocoapods modules kind a.
Also can try rebuild the project, sometimes help to rebuild iOS things.
I often struggle with these kind of problems myself:
Copy code
> Task :data:linkPodDebugFrameworkIosSimulatorArm64
w: ATTENTION!
This build uses unsafe internal compiler arguments:

-XXLanguage:+ImplicitSignedToUnsignedIntegerConversion

This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!


> Task :data:linkPodDebugFrameworkIosSimulatorArm64 FAILED
e: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld invocation reported errors
Please try to disable compiler caches and rerun the build. To disable compiler caches, add the following line to the gradle.properties file in the project's root directory:
    
    kotlin.native.cacheKind.iosSimulatorArm64=none
    
Also, consider filing an issue with full Gradle log here: <https://kotl.in/issue>
The /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld command returned non-zero exit code: 1.
output:
ld: warning: ignoring duplicate libraries: '-ldl', '-lsqlite3'
ld: framework 'FirebaseCore' not found
a
Ok, I am very confused right now 🥲 My current setup is just installing cocoapods. I mean I didn't add the cocoapods plugin and block in the gradle. After investigating (ChatGPT) it was assumed that I could only use cocoapods to install the firebase dependencies, anyway the shared module was already added in the configurations. So, my gradle look like this:
In other approaches I also tried installing manually, and other using cocoapods with the shared module included in the file. Both failed 😂 because Xcode does not find the imports. But I can write code 🤯 Similar error, “different” approaches
j
Yeah the issue is linking process. You get headers linked but not sources. Have you done the Xcode setup for build phases?
Its a huge pain get this right to be honest. Could be some linking flags or local Xcode project variations screw up build process. The start setup in Wizards is not enough in general. Wizard KMP.jetbrains.com I mean.
😧 1
a
I was confident that the wizard and cocoapods would generate all those sub-processes. So, I will take a breath and ask. What should I do? Remove cocoapods first, then install manually Firebase dependencies? Because not sure about the set up for build phases and if there are other requirements needed. Honestly I am not sure which phase or configuration I need to add/edit/remove from XCode to make this works. The plan is just to install native iOS libraries to init Firebase and use gitlive dependencies in Shared module.
j
No I wish they did it probably should. But depending on Gradle setup and Xcode setup can be complex. Start off with plain template from wizard, check if can run iOS app from that. Once that working, add cocoapods plugin and add pods. After that check linking section in Xcode build phase. Add iOS firebase deps there. Try rebuild. For devlive deps need I think for now link the firebase in Xcode setup. For some reason devlive firebase do not propagating transitive cocoapods they using into your Gradle module. Probably some export or link flag magic can use, but I never got it to work. Tried everything.
a
D: then, are you implementing Firebase native for Each platform? In that case, KMP is not my best option to continue, I prefer to learn native iOS. In fact by this moment 😂 it is being harder than native development.
j
Using Google play services plugin on Android and FirebaseCore on iOS Yes to initialize. After that only using devlive firebase in commonMain. No problem if want mixing KMP and native.
I think by comparing its much easier code in Kotlin interop with iOS than reverse. So much boilerplate in SwiftUi and UiKit. But yeah agree its confusing setup config in beginning.
a
Ok, it seems all the projects working fine with Firebase are the type that keeps structure with the androidApp folder :/ Not sure why, because as I said, Android is working well. Guess I will start a new project generated by android studio not by the wizard. Does your project have that structure? I mean, the androidApp, shared (androidMain, commonMain,iOSMain) and iOSApp. Omg, need a Jetbrains collaborator, please.
j
Uhm I created my own structure from scratch. Created iosApp from scratch and added from iOS guide. I have core, ui, feature/A,B,C, shared, androidApp etc. And yes often have issues with Xcode. I wish I never had to open Xcode ever, horrible IDE. Multiplatform using same Xcode process. Check sample apps from jetbrains as well, https://github.com/JetBrains/compose-multiplatform/tree/master/examples%2Fcocoapods-ios-example
a
Thanks for that, I will check it to understand and try to fix the problem.
j
Feel free slide in DMs if want elaborate more. I know how frustrating config is first time, especially with Firebase. Other libs much easier. Only thing I miss myself is Swift interop so I can use CryptoKit from KMP.
👍 1
a
Cool I already sent you a DM :)
517 Views