【问题标题】:Error with Firebase callable functionsFirebase 可调用函数出错
【发布时间】:2018-09-17 15:59:44
【问题描述】:

我正在尝试在我的 Android 应用中设置可调用的 Firebase 云功能。为此,根据this 教程,我需要使用以下代码来初始化 SDK:

FirebaseFunctions f = FirebaseFunctions.getInstance();

但是,当我这样做时,应用程序崩溃并出现以下错误:

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: mhealth.mvax.qa, PID: 5390
              java.lang.NullPointerException
                  at com.google.firebase.functions.internal.Preconditions.checkNotNull(Preconditions.java:876)
                  at com.google.firebase.functions.FirebaseFunctions.<init>(FirebaseFunctions.java:77)
                  at com.google.firebase.functions.FirebaseFunctions.getInstance(FirebaseFunctions.java:141)
                  at com.google.firebase.functions.FirebaseFunctions.getInstance(FirebaseFunctions.java:159)
                  at mhealth.mvax.auth.modals.ApproveUserModal.approveRequest(ApproveUserModal.java:143)
                  at mhealth.mvax.auth.modals.ApproveUserModal.lambda$null$0$ApproveUserModal(ApproveUserModal.java:92)

Firebase 代码中使用的 projectId 字段似乎为空,这会导致错误。我不确定如何解决这个问题。

编辑:这是我的build.gradle

apply plugin: 'com.android.application'

android {
    signingConfigs {
        development {
            keyAlias 'Development Key Store'
            keyPassword 'REDACTED'
            storeFile file('../keystores/development_key_store')
            storePassword 'REDACTED'
        }
    }
    compileSdkVersion 26
    defaultConfig {
        applicationId "mhealth.mvax"
        minSdkVersion 24
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    flavorDimensions "default"
    productFlavors {
        dev {
            applicationId 'mhealth.mvax.dev'
            minSdkVersion 24
            targetSdkVersion 24
            signingConfig signingConfigs.development
            testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
        }
        qa {
            applicationId 'mhealth.mvax.qa'
            minSdkVersion 24
            targetSdkVersion 24
            signingConfig signingConfigs.development
            testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
        }
        prod {
            applicationId 'mhealth.mvax.prod'
            minSdkVersion 24
            targetSdkVersion 24
            testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
        }
    }
    buildTypes {
        debug {
            debuggable true
            minifyEnabled false
        }
        release {
            debuggable false
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        // ultimately we may want checkReleaseBuilds and abortOnError to be true
        checkReleaseBuilds false
        abortOnError false
    }
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:support-v13:26.1.0' // must use v13 for ViewPager
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.jjoe64:graphview:4.2.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.firebase:firebase-database:12.0.1'
    implementation 'com.google.firebase:firebase-auth:12.0.1'
    implementation 'com.google.android.gms:play-services-auth:12.0.1'
    implementation 'com.google.firebase:firebase-invites:12.0.1'
    implementation 'com.google.firebase:firebase-functions:12.0.1'
    implementation 'com.algolia:algoliasearch-android:3.10.1'
    implementation 'joda-time:joda-time:2.9.9'
    androidTestImplementation 'junit:junit:4.12'
    testImplementation 'junit:junit:4.12'
    implementation files('libs/itext5-itextpdf-5.5.12.jar')
    testImplementation 'org.hamcrest:hamcrest-library:1.3'
    implementation files('libs/javax.mail.jar')
}

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

【问题讨论】:

  • 请更新您的问题以包含您的应用模块 build.gradle 文件的内容。
  • 完成——我已经把它包括在上面了。
  • FirebaseApp 的 projectId 似乎为空。当我执行FirebaseApp app = FirebaseApp.getInstance(); 时,projectId 为空,这会在 FirebaseFunctions 调用中引发错误。我不确定如何解决这个问题。
  • 啊,我通过在我的项目build.gradle 中将'com.google.gms:google-services:3.0.0' 更改为'com.google.gms:google-services:3.1.0' 解决了这个问题。

标签: java android firebase google-cloud-functions


【解决方案1】:

我通过改变解决了这个问题

'com.google.gms:google-services:3.0.0'

'com.google.gms:google-services:3.1.0'

在我的项目级别build.gradle

【讨论】:

    猜你喜欢
    • 2020-07-07
    • 2021-07-16
    • 1970-01-01
    • 2020-05-13
    • 2021-08-29
    • 2020-08-08
    • 1970-01-01
    • 2018-10-21
    • 2021-08-09
    相关资源
    最近更新 更多