https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
b

brandonmcansh

11/26/2023, 10:39 PM
Getting an interesting issue with cocoapods setup.
Copy code
/ios/ios/iOSApp.swift:3:8: error: no such module 'GoogleSignIn'
import GoogleSignIn
when compiling from Android Studio but compiles and runs from XCode without an issue.
Copy code
listOf(
        iosArm64(),
        iosSimulatorArm64(),
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "shared"
            isStatic = true
        }
    }

    cocoapods {
        version = "1.0.0"
        summary = "Some description for the Shared Module"
        homepage = "Link to the Shared Module homepage"
        ios.deploymentTarget = "14.1"
        podfile = project.file("../ios/Podfile") // why doesn't it load the cocoapods from the iosApp podfile?

        pod("GoogleSignIn") {
            version = "7.0.0"
        }
    }
build.gradle.kts for shared
Copy code
source '<https://cdn.cocoapods.org>'

target 'ios' do
  use_frameworks!
  platform :ios, '14.1'
  pod 'GoogleSignIn', '7.0.0'
end
Podfile
oh duh. I forgot to switch the run configuration in Android Studio to use xcworkspace instead of xcproject
👀 1
woot! Got GoogleSignIn with Firebase working in 100% kotlin
🎉 7
👍 5
🚀 3
👍🏾 1
🙌 1
r

Raed Ghazal

11/27/2023, 3:42 AM
Good for you! working on implementing that in my project at the moment, coming to you if I got stuck xD
j

Joel Denke

11/27/2023, 3:52 AM
Hehe we need to collect all of these gotchas in a article or blog post. Feels many of us get stuck on Firebase and cocoapods/spm setups. Glad worked out for you! I take with me the switch run config as had similar issue but reverse. Wasnt aware there was multiple iOS workspace files 😁
b

brandonmcansh

11/27/2023, 12:49 PM
@Raed Ghazal of course! Gonna see if I can extract it back into my compose mp template possibly with placeholders and update the README
r

Raed Ghazal

11/27/2023, 1:44 PM
so with all the complicated stuff that I had now after fixing them, the small stuff are what not working now 😅 context: my project was android only project and it used google sign in, with google-services.json file in the
app
directory now I migrated my app to KMP, where should my json file be stored to use the
default_web_client_id
string? initially I moved it to the shared module and had to create a new app in firebase
[Name]Shared
with package
[package].shared
it would be used for both android and iOS, but then it didn’t work and knew that i had to implement the id of iOS differently and the android app package name wasn’t changed to
.shared
so the new firebase app didn’t match the package name so I went back to using my old json file from the android directory but now this doesn’t work as well for some reason the google dialog launches but picking an account doesn’t do anything, the activity result is not called at all, any idea where things might have went wrong here? I’ll post snippets to make it easier to understand in the next message
Application.kt
Copy code
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
    .requestIdToken(androidContext().getString(R.string.default_web_client_id))
    .requestEmail()
    .build()


val googleSignInClient = GoogleSignIn.getClient(androidContext(), gso)

setupGoogleSignIn(googleSignInClient) <- this function is in shared/androidMain
androidMain/ShowGoogleSignIn.kt
Copy code
private var googleSignInClient: GoogleSignInClient? = null
fun setupGoogleSignIn(id: GoogleSignInClient) {
    googleSignInClient = id
}

@Composable
actual fun ShowGoogleSignIn(
    onSignInWithGoogleResultReceived: (Boolean, Task<String>) -> Unit
) {
    val signInWithGoogleLauncher = rememberLauncherForActivityResult(
        ActivityResultContracts.StartActivityForResult()
    ) {
        val result = it.resultCode == Activity.RESULT_OK
        val task = GoogleSignIn.getSignedInAccountFromIntent(it.data)
        onSignInWithGoogleResultReceived(result, task)
    }

    googleSignInClient?.signOut()

    LaunchedEffect(Unit) {
        signInWithGoogleLauncher.launch(
            googleSignInClient?.signInIntent
        )
    }
}
commonMain/SignInScreen.kt
Copy code
ShowGoogleSignIn { result, task ->
    viewModel.onEvent(SignInEvents.OnSignInWithGoogleResultReceived(result, task))
}
json file is in
androidApp
directory and debug SHA1 & SHA-256 are taken by running this
signingReport
j

Joel Denke

11/27/2023, 3:59 PM
@Raed Ghazal You need to download a separate iOS google play services plist file and put in root, same way as in Android app. It will be applied when play services plugin applies on app launch. Hence also need to boot it in iOS AppDelegate. This need to happen before using GoogleSignIn or any Firebase things.
1
r

Raed Ghazal

11/27/2023, 4:00 PM
I’m still in the android part
that isn’t working as well
j

Joel Denke

11/27/2023, 4:00 PM
I put the google play json file in Android app folder, NOT shared one. And make sure apply google play services plugin.
Plugin is com.google.gms.google-services
r

Raed Ghazal

11/27/2023, 4:01 PM
cool, same so far
j

Joel Denke

11/27/2023, 4:02 PM
Not sure if matters but I also added this into manifest file:
Copy code
<meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version"/>
r

Raed Ghazal

11/27/2023, 4:03 PM
where do you have the
GoogleSignIn.getClient
part? androidApp or androidMain?
j

Joel Denke

11/27/2023, 4:03 PM
I have it wrapped in an interface creating google sign in launcher expect actual 😛
Which is in a separate data gradle module, used in shared module as well as android and iOS app.
r

Raed Ghazal

11/27/2023, 4:04 PM
cool but the implementation is in which module? androidApp or shared?
j

Joel Denke

11/27/2023, 4:05 PM
Send code in DM now, to not spam this more than we already did 😄
Its neitehr app or shared, separate module 🙂
That module is used in both androidApp and shared module.
c

Colton Idle

01/17/2024, 5:59 PM
So I'm moving my android app to kotlin multiplatform. So far so good i suppose. but i have a free and paid variant of my app. I now renamed those directories to androidFree and androidPaid, but now it google-services can't find the .json as it's looking only in free and paid. any ideas?
j

Joel Denke

01/17/2024, 6:45 PM
Not sure if mean flavour or such, but copy google service json file into both root folder of free and paid Android app folders should work. Dont remember if can specify path somewhere.
c

Colton Idle

01/17/2024, 7:35 PM
darn. i do have a copy in free and paid.
but its not working.
let me know how this looks I have free and paid build variants. in my apps build.gradle.kts the root android {} block i have
Copy code
productFlavors {
  create("free") {
    dimension = "stage"
    applicationIdSuffix = ".free"
  }

  create("paid") { dimension = "stage" }
}
then in the root kotlin {} block i have
Copy code
sourceSets {
    sourceSets.invokeWhenCreated("androidFree") {
    }
    sourceSets.invokeWhenCreated("androidPaid") {
    }
I updated my dirs from /free and /paid to androidFree and androidPaid. does that all seem correct?
4 Views