我正在尝试在我的 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'
最佳答案
我通过改变解决了这个问题
'com.google.gms:google-services:3.0.0'
到
'com.google.gms:google-services:3.1.0'
在我的项目级别build.gradle
。
关于java - Firebase 可调用函数出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49712858/