我想将FCM集成到在框架构建中使用Android.mk构建系统的Android应用程序中
在Andorid.mk或Android.bp其他构建系统中是否可以使用“ apply plugin:'com.google.gms.google-services'”替代方案?
答案 0 :(得分:0)
插件的本质是解析您的google-services.json
文件,并将其中的值复制到xml资源文件中。然后,它将一些代码注入到您的项目中,以便为您调用FirebaseApp.initializeApp
。
如果愿意,您当然可以自己做所有这一切。
在您的AndroidManifest.xml中:
<provider
android:authorities="yourapp.package.name.myFcmInitProvider"
android:name=".MyFcmInitProvider"
android:exported="false" />
<!-- Make sure that Google's FirebaseInitProvider isn't included in your app -->
<provider
android:name="com.google.firebase.provider.FirebaseInitProvider"
android:authorities="yourapp.package.name.firebaseinitprovider"
android:exported="false"
tools:node="remove" />
MyFcmInitProvider.kt:
class MyFcmInitProvider : ContentProvider() {
override fun onCreate(): Boolean {
// Application ID can be found in google-services.json.
// Add additional credentials as necessary.
val builder = FirebaseOptions.Builder().setApplicationId(myApplicationId)
if (null == FirebaseApp.initializeApp(context, builder.build())) {
// Initialization failed
}
return false
}
// Required overrides
override fun getType(uri: Uri?): String? = null
override fun delete(uri: Uri?, selection: String? selectionArgs: Array<out String>?): Int = 0
override fun update(uri: Uri?, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
override fun insert(uri: Uri?, values: ContentValues?): Uri? = null
override fun query(uri: Uri?, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
}