I have a login flow in my app that uses Firebase Auth for authentication. I’m using both Google OAuth and Email based auth. The problem I’m facing is that login works just fine in debug build but not in release build. I get this error:
024-10-16 15:34:52.847 18432-18432 AuthViewModel com.logomo.logomo E Error fetching API key: java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType package com.logomo.logomo.data.login.
private suspend fun loginAndGetApiKey(uid: String) {
try {
_isLoading.value = true
logInResponse = logInRepository.signInUser(uid)
// Suspends here until API call finishes
logInResponse?.let {
_apiKey.value = it.api_key
Log.d(TAG, "getApiKey: ${it.status}")
Log.d(TAG, "getApiKey: ${apiKey.value}")
// Save the API key and retrieve it safely
apiKey.value?.let { it1 -> saveApiKey(apiKey = it1) }
val savedApiKey = getApiKey()
Log.d(TAG, "getApiKeyFunc: $savedApiKey")
} ?: run {
Log.e(TAG, "Login response is null, failed to retrieve API key")
}
} catch (e: Exception) {
signOut()
Log.e(TAG, "Error fetching API key: ${e.message}")
} finally {
_isLoading.value = false
}
}
I’m getting api key from the api end point and storing it in EncryptedSharedPreferences so that I can use it every subsequent api call for app functionalities.
//This is the ApiService class
import com.logomo.logomo.retrofit.SignInUserData
import retrofit2.http.Field
import retrofit2.http.FormUrlEncoded
import retrofit2.http.POST
interface LogInApiService {
@FormUrlEncoded
@POST("users/user_login.php")
suspend fun signInUser(
@Field("uid") uid: String,
): SignInUserData
}
//This is the Repository class
import com.logomo.logomo.retrofit.SignInUserData
import javax.inject.Singleton
@Singleton
class NetworkLogInRepository(
private val logInApiService: LogInApiService
) {
suspend fun signInUser(uid: String): SignInUserData {
return logInApiService.signInUser(uid)
}
}
I tried several proguard rules so that I can prevent obfuscation of retrofit2 classes. But nothing seems to work. I**’m sure it’s proguard issue since I tried switching isMinifyEnabled to false and it worked fine.** How can I change the rules or something so that I can get it to work?
2
Answers
I was able to solve this myself. The issue was with proguard-rules.pro. I was using keep rules for Retrofit, Gson and other crucial libraries but not for Hilt due to which it was having issues. When I added keep rules for Hilt, everything is working correctly.
Did you add the pro-guard rules from Gson?
Also there is something called
You can try turning this off as well, in newer AGP and gradle versions this is enabled by default. You can find this
gradle.properties.