CodenameOne-FirebaseApp无法初始化 [英] CodenameOne - FirebaseApp not initializing

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

问题描述

我正尝试从gcm切换到fcm。尽管FirebaseApp并未初始化,但我已遵循从gcm到fcm的迁移指南中详细介绍的步骤。

I'm trying to swith from gcm to fcm. I've followed the steps detailed in the gcm to fcm migration guide, although the FirebaseApp doesn't initializes.

我发现了几个可能的问题,但是codenameone却没有帮助解决它们。

I have identified couple possbile issues, however codenameone doesn't help solving them.

显然,需要将Google服务添加到buildscript依赖项中,如下所示:

Apparently, google-services needs to be added to the buildscript dependencies, like this:

buildscript {
    repositories {
        ...
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

但是,我找不到任何代号的构建提示来帮助我做到这一点。

However, I can't find any codenameone build hint to help me do that.

此外,还需要添加google-services插件,例如

Also, the google-services plugin needs to be added, like this:

apply plugin: 'com.google.gms.google-services'

我已经通过使用android.gradlePlugin构建提示完成了此操作:

I have accomplished this by using android.gradlePlugin build hint:

codename1.arg.android.gradlePlugin=apply plugin\:'com.google.gms.google-services'

但是该构建无法抱怨找不到插件,因为它可能需要如上所述的定义。

But the build fails complaining that it can't find the plugin, as it probably needs that defined as described above.

另外,我已经看到,在大多数情况下,此行应在依赖项部分之后而不是在当前构建提示之前的后面进行。

Also, I have seen that in most cases this line should apper after the "dependencies" section, not before, as the current build hint does.

不确定该是否是问题在这一点上。

Not really sure if this is an issue at this point.

我还尝试过手动启动Firebas eApp通过一些本地代码,例如:

I have also tried manually starting the FirebaseApp, via some native code, like this:

Context context = AndroidNativeUtil.getContext();
FirebaseApp.initializeApp(context);

,但这无济于事。不会引发任何错误,但是当尝试通过

but it doesn't help. No error is thrown, but when trying to retrieve the token via

String token = FirebaseInstanceId.getInstance().getToken();

我收到这样的错误:

IllegalStateException: Default FirebaseApp is not initialized in this process

My由codenameone构建服务器生成的build.gradle文件如下所示:

My build.gradle file, generated by codenameone build servers looks like this:

apply plugin: 'com.android.application'

buildscript {
    repositories {
     jcenter()
     mavenLocal()
      mavenCentral()
      google()
    maven { url "https://maven.google.com" }
     mavenLocal()
      mavenCentral()
      google()
    }
    dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
    }
}

android {
    compileSdkVersion 27
    buildToolsVersion '27'

    dexOptions {
        preDexLibraries = false
        incremental false
        jumboMode = true
        javaMaxHeapSize "3g"
    }
    defaultConfig {
        applicationId "<appid>"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 85
        versionName "0.85"
        multiDexEnabled true
    }
    sourceSets {
        main {
            aidl.srcDirs = ['src/main/java']
        }
    }

    lintOptions {
        lintOptions {
        checkReleaseBuilds false
        abortOnError false
        }
    }
    signingConfigs {
        release {
            storeFile file("keyStore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
    }
buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
            signingConfig signingConfigs.release
        }
        debug {
            signingConfig signingConfigs.release
        }
    }
}

repositories {
    jcenter()
    maven { url "https://maven.google.com" }
     mavenLocal()
      mavenCentral()
      google()
    flatDir{
              dirs 'libs'
       }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:27.+'
     implementation 'com.android.support:appcompat-v7:27.+'

 compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.gms:google-services:4.1.0'
compile 'com.google.firebase:firebase-core:16.0.3'
compile 'com.google.firebase:firebase-messaging:17.3.0'}

请帮助。

更新:因此,似乎需要两个新的构建提示可以允许:

Update: So it seems that there's a need for two new build hints that can allow:



  1. 在之后插入一条应用插件语句r依存关系部分

  2. 在buildscript依存关系部分中插入clsspath语句



推荐答案

我发现了一种无需使用google-services插件即可初始化FirebaseApp的解决方法。

I have found a workaround to initialize the FirebaseApp without the google-services plugin.

我必须按照此处所述手动对其进行初始化:是否可以在不使用google-services.json的情况下初始化Firebase?

I had to manually initialize it as described here: Can I initialize Firebase without using google-services.json?

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

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