Android - FirebaseApp / Firebase - 初始化不开始 [英] Android - FirebaseApp / Firebase-Initialization is not starting

查看:495
本文介绍了Android - FirebaseApp / Firebase - 初始化不开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Android应用程序中实施Firebase消息传递插件。
我从github的quickstart-android-master / messaging例子开始: https://github.com/firebase/quickstart-android/tree/master/messaging



这适用于我!
日志输出:

  D / FirebaseApp:com.google.firebase.auth.FirebaseAuth未关联。跳过初始化。 
D / FirebaseApp:已初始化的类com.google.firebase.iid.FirebaseInstanceId。
D / FirebaseApp:com.google.firebase.crash.FirebaseCrash未链接。跳过初始化
D / FirebaseApp:已初始化的类com.google.android.gms.measurement.AppMeasurement。
I / FirebaseInitProvider:FirebaseApp初始化成功




希望将插件
com.google.firebase:firebase-messaging:9.0.2实现到我的应用中,
FirebaseApp不会被初始化!所以FirebaseApp插件没有启动! - 没有收到日志或令牌!

我也在app目录下添加了apply插件build.gradle文件: / p>

  apply plugin:'com.android.application'

android {
//。 ..
}

依赖关系{
// ...
编译'com.google.firebase:firebase-messaging:9.0.2'
}

//在底部添加
apply plugin:'com.google.gms.google-services'

和google-services插件build.gradle在root目录下:

  buildscript {
// ...
依赖项{
// ...
classpath'com.google.gms:google-services:3.0.0'




$ block $ $ $ b $ p $问题可能是:





>

解决方案

问题是Android的Manifest Merger。
如果我使用

  xmlns:tools =http://schemas.android.com/tools

 <$ c在清单的Application Tag中,$ c> tools:node =replace

,FirebaseApp会不会初始化!



摘要:如果在 tools:node 中使用替换 attr,
会将您的低优先级声明替换为带注释的声明(请参阅更多 here )。您应该使用合并合并属性。



所以我确实做了:



这是行不通的:

 < application 
android :name =xxx
android:icon =@ mipmap / ic_launcher
android:label =@ string / application_name
android:theme =@ style / Theme.TemplateStyle
tools:node =replace>

这个工作:

 
android:label =@ string / application_name
android:theme =@ style / Theme.TemplateStyle>
<! - tools:node =replace - >


I want to implement the Firebase-Messaging plugin into my Android-App. I've started with the "quickstart-android-master/messaging"-example from github: https://github.com/firebase/quickstart-android/tree/master/messaging

This works for me! Log-Output:

D/FirebaseApp﹕ com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
D/FirebaseApp﹕ Initialized class com.google.firebase.iid.FirebaseInstanceId.
D/FirebaseApp﹕ com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization
D/FirebaseApp﹕ Initialized class com.google.android.gms.measurement.AppMeasurement.
I/FirebaseInitProvider﹕ FirebaseApp initialization successful

But if I want to implement the Plugin "com.google.firebase:firebase-messaging:9.0.2" into my app, the FirebaseApp isn't initialized! So the FirebaseApp plugin isn't starting! - No Log or token received!

I've also added apply plugin to build.gradle file in "app"-directory:

    apply plugin: 'com.android.application'

android {
  // ...
}

dependencies {
  // ...
  compile 'com.google.firebase:firebase-messaging:9.0.2'
}

// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'

And the google-services plugin to build.gradle in the "root" directory:

buildscript {
    // ...
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

Problems could be:

  • AndroidAnnotations, Proguard, Product flavors...

解决方案

The problem is the "Manifest Merger" of Android. If I use the

xmlns:tools="http://schemas.android.com/tools"

and

tools:node="replace"

in the Application Tag of the Manifest, the FirebaseApp will not be initialized!

Summary: if you use replace attr on tools:node it will replace your lower priority declaration with the annotated one (see more here). You should use merge or merge only attributes instead.

So what I've exactly done:

This doesn't work:

<application
            android:name="xxx"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/application_name"
            android:theme="@style/Theme.TemplateStyle"
            tools:node="replace">

this works:

<application
            android:name="xxx"
            android:icon="@mipmap/ic_launcher"
            android:label="@string/application_name"
            android:theme="@style/Theme.TemplateStyle">
            <!-- tools:node="replace"-->

这篇关于Android - FirebaseApp / Firebase - 初始化不开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆