Using Firebase in a Library

时光怂恿深爱的人放手 提交于 2019-12-11 06:19:25

问题


I am trying to create a connection library for use in all of our Android applications. They will all use Firebase, but only to store the FCM Token for the devices, and to receive messages from Firebase console. Mainly the apps will connect to our backend server, which will make calls to a Firebase Functions url to get a custom login token, that is sent back to the library/device with some other data from our server. The library will then login to Firebase using the custom token it gets from our server, and then get the FCM token and save it to the database under that users uuid. The problem I am having is, when I try to add Firebase with Android Studio I am getting the message

"Could not find the Android Application Module. Only Android Application Modules can be connected to Firebase online projects..."

In order to make this a library I have followed the guidelines https://developer.android.com/studio/projects/android-library <-there. It says to remove the applicationId from the build.gradle file and to change the

apply plugin: 'com.android.application'

to

apply plugin: 'com.android.library'

However as soon as you do that, you can no longer login to Firebase with Android Studio. I am trying to avoid having to rewrite the same connection/login/FCM logic on every Android app we have. I thought a library would be the smartest way to handle this, but it looks like Firebase doesn't allow use in a library. Is there any way to accomplish this, or am I going to have to just copy/paste the same connection logic to all of our apps? That seems like a terrible idea. Thank you.

来源:https://stackoverflow.com/questions/51525615/using-firebase-in-a-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!