KMM에서 해당에러가 발생하는 파일들 1번라인에 다음을 추가하자(package 위에)
@file:JvmMultifileClass
나 같은 경우에는 shared 모듈에서
//CommonMain
expect class LoginHelper {
val loginIn : CommonMutableStateFlow<Boolean>
val auth : FBAuth
fun registerTokenAction(
result : GoogleResult,
failAction: (msg:String) -> Unit,
successAction: (credential : FBAuthCredential) -> Unit,
)
}
fun LoginHelper.registerGoogleToken(
result : GoogleResult,
successAction: (FBAuthResult) -> Unit,
) {
loginIn.value = true
registerTokenAction(result, {}) { credential ->
auth.signInWithCredential(credential, { loginIn.value = false }) {
loginIn.value = false
successAction(it)
}
}
}
fun LoginHelper.registerAnonymousToGoogle(
result: GoogleResult,
failAction: (msg:String) -> Unit,
successAction: () -> Unit
) {
registerTokenAction(result, failAction) { credential ->
auth.linkWithCredential(credential, failAction) {
successAction()
}
}
}
fun LoginHelper.signOut() {
this.auth.signOut()
}
fun LoginHelper.delete() {
this.auth.delete()
}
//AndroidMain
actual class LoginHelper(
private val context: Context
) {
private val googleIdOption: GetGoogleIdOption = GetGoogleIdOption.Builder()
.setFilterByAuthorizedAccounts(false)
.setServerClientId("private ID")
.build()
private val credentialManager by lazy {
CredentialManager.create(context)
}
actual val loginIn: CommonMutableStateFlow<Boolean> = MutableStateFlow(false).toCommonMutableStateFlow()
actual val auth: FBAuth = FBAuth(Firebase.auth)
actual fun registerTokenAction(
result: GoogleResult,
failAction: (msg: String) -> Unit,
successAction: (credential: FBAuthCredential) -> Unit
) {
val token = result.idToken
try {
val firebaseCredential = GoogleAuthProvider.getCredential(token, null)
successAction(FBAuthCredential(firebaseCredential))
} catch (e: ApiException) {
loginIn.value = false
when (e.statusCode) {
CommonStatusCodes.CANCELED -> {
// failAction("One-tap dialog was closed.")
}
CommonStatusCodes.NETWORK_ERROR -> {
failAction("One-tap encountered a network error.")
}
else -> {
failAction("Couldn't get credential from result. (${e.localizedMessage})")
}
}
}
}
이런식으로 사용중이였는데
Duplicate JVM class name 'com/wonddak/loacell/auth/LoginHelperKt' generated from: LoginHelperKt, LoginHelperKt
위와같이 오류가 나서 찾아보다가 @file:JvmMultifileClass를 추가하고 해결되었다.
JvmMultifileClass는 @JvmName 과 함께 사용되며, top-level 함수가 여러 파일이 걸쳐 선언되어 있을 때 마치 하나의 파일에 선언되어 있는 것 처럼 사용하고 싶을 때 사용한다.