Max
07/22/2024, 11:07 AMFirebase Crashlytics
work in a up to date KMP project, I had to do some manual changes. The google-services.json
is not picked up in the new project structure. Sharing here if someone needs it, I’m now not relying on the automatic init of the SDK, but do it manually:
fun initializeFirebase(context: Context) {
// Load google-services.json from the custom directory
val inputStream: InputStream = context.assets.open("config/google-services.json")
val json = inputStream.bufferedReader().use { it.readText() }
val jsonObject = JSONObject(json)
val options = FirebaseOptions.Builder()
.setProjectId(jsonObject.getString("project_id"))
.setApplicationId(jsonObject.getString("mobilesdk_app_id"))
.setApiKey(jsonObject.getString("current_key"))
.setGcmSenderId(jsonObject.getString("project_number"))
.setStorageBucket(jsonObject.getString("storage_bucket"))
.build()
FirebaseApp.initializeApp(context, options)
}
That was the base code ChatGPT gave me, I hardvoded the keys for now, not using the JSON loading. But base concept stays the same. Works for me.hafiz
07/22/2024, 10:46 PMMeet
07/23/2024, 4:53 AMFirebase.initialize(
applicationContext,
options = FirebaseOptions(
applicationId = "Add your firebase android appId here",
apiKey = "Add your firebase project api key here",
projectId = "Add your firebase projectId here"
)
)
Max
07/23/2024, 5:53 AMMeet
07/23/2024, 5:54 AM