CodenameOne - FirebaseApp not initializing

狂风中的少年 提交于 2019-12-06 09:27:33

问题


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.

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

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.

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

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

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.

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();

I get an error like this:

IllegalStateException: Default FirebaseApp is not initialized in this process

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'}

Please help.

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

  1. Inject an apply plugin statement after the dependencies section
  2. Inject a clsspath statement in the buildscript dependencies section

回答1:


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

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



来源:https://stackoverflow.com/questions/52278220/codenameone-firebaseapp-not-initializing

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