Java Firebase可调用函数出错
我正在尝试在我的Android应用程序中设置可调用的Firebase云函数。为此,根据教程,我需要使用以下代码初始化SDK:Java Firebase可调用函数出错,java,android,firebase,google-cloud-functions,Java,Android,Firebase,Google Cloud Functions,我正在尝试在我的Android应用程序中设置可调用的Firebase云函数。为此,根据教程,我需要使用以下代码初始化SDK: FirebaseFunctions f = FirebaseFunctions.getInstance(); 但是,当我执行此操作时,应用程序会因以下错误而崩溃: E/AndroidRuntime: FATAL EXCEPTION: main Process: mhealth.mvax.qa, PID: 5390
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)
我通过改变来解决这个问题
'com.google.gms:googleservices:3.0.0'
到
'com.google.gms:googleservices:3.1.0'
在我的项目级别
build.gradle
中,请更新您的问题,以包含应用程序模块build.gradle文件的内容。完成--我已将其包含在上面。FirebaseApp projectId似乎为空。当我执行FirebaseApp=FirebaseApp.getInstance()时代码>projectId为null,这将在FirebaseFunctions调用中引发错误。不过我不知道如何解决这个问题。啊,我已经通过在我的项目build.gradle
中将'com.google.gms:google services:3.0'
更改为'com.google.gms:google services:3.1.0'
解决了这个问题。
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'