I have created a Firebase project and add google-services.json to app module.
I have setup Firebase remote config as follow :
private fun initFirebaseRemoteConfig() {
val remoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = if (BuildConfig.DEBUG) 0 else 3600
}
//remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
remoteConfig.setConfigSettingsAsync(configSettings)
remoteConfig.fetchAndActivate().addOnCompleteListener { task ->
val updated = task.result
if (task.isSuccessful) {
Timber.d("Config params updated: $updated")
} else {
Timber.d("Unsuccessful")
}
}
}
I receive following exception on this line task.result as follow :
com.google.android.gms.tasks.RuntimeExecutionException: com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException: Fetch failed: The user is not authorized to access the project. Please make sure you are using the API key that corresponds to your Firebase project.
at com.google.android.gms.tasks.zzu.getResult(com.google.android.gms:play-services-tasks##17.0.2:15)
at com.sample.android.tmdb.TmdbApp.initFirebaseRemoteConfig$lambda-0(TmdbApp.kt:34)
at com.sample.android.tmdb.TmdbApp.lambda$P4-jkzwf9-IJZ17_EtnpghkBXis(Unknown Source:0)
at com.sample.android.tmdb.-$$Lambda$TmdbApp$P4-jkzwf9-IJZ17_EtnpghkBXis.onComplete(Unknown Source:0)
at com.google.android.gms.tasks.zzi.run(com.google.android.gms:play-services-tasks##17.0.2:4)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.google.android.gms.internal.tasks.zzb.dispatchMessage(com.google.android.gms:play-services-tasks##17.0.2:6)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException: Fetch failed: The user is not authorized to access the project. Please make sure you are using the API key that corresponds to your Firebase project.
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.createExceptionWithGenericMessage(ConfigFetchHandler.java:380)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackend(ConfigFetchHandler.java:333)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackendAndCacheResponse(ConfigFetchHandler.java:278)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.lambda$fetchIfCacheExpiredAndNotThrottled$1$ConfigFetchHandler(ConfigFetchHandler.java:215)
at com.google.firebase.remoteconfig.internal.-$$Lambda$ConfigFetchHandler$PAoFtfQiOtbXSTeK4H2aFJ-JNJI.then(Unknown Source:8)
at com.google.android.gms.tasks.zzg.run(com.google.android.gms:play-services-tasks##17.0.2:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Caused by: com.google.firebase.remoteconfig.FirebaseRemoteConfigServerException: Forbidden
at com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.fetch(ConfigFetchHttpClient.java:195)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackend(ConfigFetchHandler.java:307)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackendAndCacheResponse(ConfigFetchHandler.java:278)
at com.google.firebase.remoteconfig.internal.ConfigFetchHandler.lambda$fetchIfCacheExpiredAndNotThrottled$1$ConfigFetchHandler(ConfigFetchHandler.java:215)
at com.google.firebase.remoteconfig.internal.-$$Lambda$ConfigFetchHandler$PAoFtfQiOtbXSTeK4H2aFJ-JNJI.then(Unknown Source:8)
at com.google.android.gms.tasks.zzg.run(com.google.android.gms:play-services-tasks##17.0.2:2)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
Related
I'm struggling to access postman gRPC mock server by Android/kotlin app for several days.
I created the mock server after reading official document. I got the URL for mock server and I could get a response by grpcurl and a Node.js gRPC client. However, I got a error when I used the URL by Android gRPC client.
Stacktrace is below.
java.lang.RuntimeException: Unable to start activity ComponentInfo{io.github.aniokrait.grpcsample/io.github.aniokrait.grpcsample.MainActivity}: io.grpc.StatusRuntimeException: UNAVAILABLE
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: io.grpc.StatusRuntimeException: UNAVAILABLE
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:271)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:252)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:165)
at com.book.BookServiceGrpc$BookServiceBlockingStub.getBook(BookServiceGrpc.java:312)
at io.github.aniokrait.grpcsample.MainActivity$Companion.startGrpc(MainActivity.kt:71)
at io.github.aniokrait.grpcsample.MainActivity$Companion.access$startGrpc(MainActivity.kt:34)
at io.github.aniokrait.grpcsample.MainActivity.onCreate(MainActivity.kt:30)
at android.app.Activity.performCreate(Activity.java:8000)
at android.app.Activity.performCreate(Activity.java:7984)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.RuntimeException: TLS ALPN negotiation failed with protocols: [h2]
at io.grpc.okhttp.OkHttpProtocolNegotiator.negotiate(OkHttpProtocolNegotiator.java:104)
at io.grpc.okhttp.OkHttpProtocolNegotiator$AndroidNegotiator.negotiate(OkHttpProtocolNegotiator.java:218)
at io.grpc.okhttp.OkHttpTlsUpgrader.upgrade(OkHttpTlsUpgrader.java:63)
at io.grpc.okhttp.OkHttpClientTransport$3.run(OkHttpClientTransport.java:551)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:923)
The messages says "TLS ALPN negotiation failed with protocols: [h2]", so I have an idea that the problem is around SSL/TLS, but I don't know how to solve it.
I do not think it is likely to be a certificate issue, as I am able to access the URL from Node.js and grpcurl but the issue of my Android app.
I've read tls-on-android and Update your security provider to protect against SSL exploits.
I added dependecies of play-services and installing code as below but still it doesn't work.
Here's my code.
MainActivity.kt
import android.content.Context
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import com.book.BookServiceGrpc
import com.book.Index.GetBookRequest
import com.google.android.gms.security.ProviderInstaller
import io.grpc.okhttp.OkHttpChannelBuilder
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ProviderInstaller.installIfNeeded(this#MainActivity)
startGrpc()
}
companion object {
private fun startGrpc() {
try {
val channel = OkHttpChannelBuilder
.forAddress("g-95d43o92ollxvwmm7nx895731r4g9y.srv.pstmn.io",443) //URL is slightly altered to prevent tampering
.useTransportSecurity()
.build()
val stub = BookServiceGrpc.newBlockingStub(channel)
val request = GetBookRequest.newBuilder().setIsbn(123).build()
val result = stub.getBook(request)
} catch (e: Exception) {
e.printStackTrace()
throw e
}
}
}
}
my proto file.
syntax = "proto3";
package com.book;
message Book {
int64 isbn = 1;
string title = 2;
string author = 3;
}
message GetBookRequest {
int64 isbn = 1;
}
service BookService {
rpc GetBook (GetBookRequest) returns (Book) {}
}
and dependecies relevant to gRPC
dependencies {
implementation 'io.grpc:grpc-okhttp:1.51.1'
implementation 'io.grpc:grpc-protobuf-lite:1.51.1'
implementation 'io.grpc:grpc-stub:1.51.1'
implementation 'org.apache.tomcat:annotations-api:6.0.53'
implementation 'com.google.android.gms:play-services-basement:18.1.0'
}
Update:
I found these messages in Debug logs.
W/DynamiteModule: Local module descriptor class for com.google.android.gms.providerinstaller.dynamite not found.
I/DynamiteModule: Considering local module com.google.android.gms.providerinstaller.dynamite:0 and remote module com.google.android.gms.providerinstaller.dynamite:0
W/ProviderInstaller: Failed to load providerinstaller module: No acceptable module com.google.android.gms.providerinstaller.dynamite found. Local version is 0 and remote version is 0.
I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
Perhaps The Dynamic Security Provider isn't installed properly, but still I don't know why.
I am getting an error the first time the user sign in, however, there is no error the second time the user open the app
from the logcat the awaiClose function is triggered. so where is the error come from?!
The code
val userIdFlow = callbackFlow {
val listener = FirebaseAuth.AuthStateListener { firebaseAuth ->
Timber.tag("Auth_Util").d("Changed")
firebaseAuth.currentUser?.let {
Timber.tag("Auth_Util").d("user exist, id = ${it.uid}")
trySend(it.uid) // the line mentioned in the error message (AuthUtil.kt:38)
}
}
auth.addAuthStateListener(listener)
awaitClose {
Timber.tag("Auth_Util").d("Closed")
auth.removeAuthStateListener(listener)
}
}
The Logcat
2022-10-13 16:00:11.541 6972-6972 Auth_Util com.hussienFahmy.myGpaManager D Changed
2022-10-13 16:00:11.541 6972-6972 Auth_Util com.hussienFahmy.myGpaManager D user exist, id = g11Hbz2EUWXGSE0WnbcF2nJRUPQ2
2022-10-13 16:00:11.543 6972-6972 Auth_Util com.hussienFahmy.myGpaManager D Closed
2022-10-13 16:00:11.716 6972-6972 AndroidRuntime com.hussienFahmy.myGpaManager E FATAL EXCEPTION: main
Process: com.hussienFahmy.myGpaManager, PID: 6972
java.lang.IllegalStateException: 'awaitClose { yourCallbackOrListener.cancel() }' should be used in the end of callbackFlow block.
Otherwise, a callback/listener may leak in case of external cancellation.
See callbackFlow API documentation for the details.
at kotlinx.coroutines.flow.CallbackFlowBuilder.collectTo(Builders.kt:343)
at kotlinx.coroutines.flow.internal.ChannelFlow$collectToFun$1.invokeSuspend(ChannelFlow.kt:60)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.EventLoop.processUnconfinedEvent(EventLoop.common.kt:69)
at kotlinx.coroutines.DispatchedTaskKt.resumeUnconfined(DispatchedTask.kt:245)
at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:161)
at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397)
at kotlinx.coroutines.CancellableContinuationImpl.completeResume(CancellableContinuationImpl.kt:513)
at kotlinx.coroutines.channels.AbstractChannel$ReceiveElement.completeResumeReceive(AbstractChannel.kt:908)
at kotlinx.coroutines.channels.ArrayChannel.offerInternal(ArrayChannel.kt:83)
at kotlinx.coroutines.channels.AbstractSendChannel.trySend-JP2dKIU(AbstractChannel.kt:155)
at kotlinx.coroutines.channels.ChannelCoroutine.trySend-JP2dKIU(Unknown Source:2)
at com.hussienFahmy.myGpaManager.network.AuthUtil$userIdFlow$1.invokeSuspend$lambda-1(AuthUtil.kt:38)
at com.hussienFahmy.myGpaManager.network.AuthUtil$userIdFlow$1.$r8$lambda$gz_nO4N2PXNldWwFNxezrd-NGHg(Unknown Source:0)
at com.hussienFahmy.myGpaManager.network.AuthUtil$userIdFlow$1$$ExternalSyntheticLambda0.onAuthStateChanged(Unknown Source:2)
at com.google.firebase.auth.zzk.run(com.google.firebase:firebase-auth##21.0.8:1)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:236)
at android.app.ActivityThread.main(ActivityThread.java:8057)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}#1daddb6, Dispatchers.Main.immediate]
I am trying to integrate Kommunicate Chatbot in my Android App.
After I have created KMUser with UserId and trying to login using Kommunicate.login(), it is giving me IllegalArgumentException, in onFailure() function.
This exception only occurs in release build, but not in debug build.
I have tried switching data in KMUser but didn't help.
Here is the code snippet.
Kommunicate.init(this#HomeActivity, APP_ID)
if (!(mHomeViewModel?.dbProfileResponseModel?.contactNum.isNullOrEmpty())) {
kmUser.userId = mHomeViewModel?.dbProfileResponseModel?.contactNum
} else {
kmUser = Kommunicate.getVisitor()
}
if (!(mHomeViewModel?.dbProfileResponseModel?.email.isNullOrEmpty())) {
kmUser.email = mHomeViewModel?.dbProfileResponseModel?.email
}
kmUser.applicationId = APP_ID
Kommunicate.login(this#HomeActivity, kmUser, object : KMLoginHandler {
override fun onSuccess(registrationResponse: RegistrationResponse?, context: Context?) {
val botIds = arrayListOf<String>()
botIds.add("beekun-yx526")
KmConversationBuilder(this#HomeActivity)
.setSingleConversation(false)
.setBotIds(botIds)
.setKmUser(kmUser)
.launchConversation(object : KmCallback {
override fun onSuccess(message: Any) {
progressDialog.dismiss()
}
override fun onFailure(error: Any) {
progressDialog.dismiss()
}
})
}
override fun onFailure(registrationResponse: RegistrationResponse?, exception: Exception?) {
if (progressDialog != null && progressDialog.isShowing) {
progressDialog.dismiss()
}
createLoginErrorDialog(registrationResponse, exception)
}
})
This is the exception raised.
W/System.err: java.lang.IllegalArgumentException: class c.b.g.a declares multiple JSON fields named a
W/System.err: at com.google.gson.b.a.i.a(ReflectiveTypeAdapterFactory.java:172)
W/System.err: at com.google.gson.b.a.i.a(ReflectiveTypeAdapterFactory.java:102)
W/System.err: at com.google.gson.Gson.a(Gson.java:458)
W/System.err: at com.google.gson.Gson.a(Gson.java:696)
W/System.err: at com.google.gson.Gson.a(Gson.java:683)
W/System.err: at com.google.gson.Gson.b(Gson.java:638)
W/System.err: at com.google.gson.Gson.b(Gson.java:618)
W/System.err: at com.applozic.mobicomkit.api.a.a.a.a(RegisterUserClientService.java:100)
W/System.err: at c.b.a.i.a(KmUserLoginTask.java:62)
W/System.err: at c.b.a.i.doInBackground(KmUserLoginTask.java:24)
W/System.err: at android.os.AsyncTask$2.call(AsyncTask.java:334)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err: at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err: at java.lang.Thread.run(Thread.java:764)
Please help me out resolving this issue.
This is not the issue with build flavor, you might have enabled proguard for release build and haven't added their proguard rules in your proguard-rules.pro file.
Checkout the doc to add the rules in your proguard file: https://docs.kommunicate.io/docs/android-installation#building-with-proguard
I'm trying to handle errors in Rx android networking but unable to do so can some help.
getCompositeDisposable().add(getManager().callApi(request)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.ui())
.subscribe(apiResponse -> Log.d(TAG,"success"),
throwable -> Log.e(TAG,throwable.getMessage)));
I want to handle errors in subscribe()
Logs:
io.reactivex.exceptions.OnErrorNotImplementedException: java.net.ConnectException: Failed to connect
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
at io.reactivex.internal.observers.ConsumerSingleObserver.onError(ConsumerSingleObserver.java:47)
at io.reactivex.internal.operators.single.SingleObserveOn$ObserveOnSingleObserver.run(SingleObserveOn.java:79)
at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:109)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7231)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: com.androidnetworking.error.ANError: java.net.ConnectException: Failed to connect to /192.168.1.42:8484
at com.rx2androidnetworking.Rx2InternalNetworking$SimpleANObservable.subscribeActual(Rx2InternalNetworking.java:235)
at io.reactivex.Observable.subscribe(Observable.java:10981)
at io.reactivex.internal.operators.observable.ObservableSingleSingle.subscribeActual(ObservableSingleSingle.java:35)
at io.reactivex.Single.subscribe(Single.java:2801)
at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
Unfortunately i can not comment. Could you be more specific? What error have you got? The common way to handle errors using rx looks like this:
Subscription subscribe = apiServices.endpointCall(...parameters...)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.unsubscribeOn(Schedulers.io());
.subscribe(response -> {
//do something with response
}, throwable -> {
//do something with error
});
Where apiService is created by retrofit using
service = retrofit.create(ApiServices.class);
I moved Firebase Cloud Messaging to a library, so that I can import this into any of my apps and provide push messages. So therefore I created a library and moved everything from this example to my library.
Then I compile this library in my build.gradle and use it as desired.
This works so far when I instantiate Firebase from app level:
FirebaseMessaging.getInstance().subscribeToTopic(topic)
Now, I thought of moving this down into my library:
fun initFirebaseMessaging(topic : String) : String
{
FirebaseMessaging.getInstance().subscribeToTopic(topic)
Timber.d("Push subscribeToTopic $topic")
val token = FirebaseInstanceId.getInstance().token!!
Timber.d("Push FirebaseinstanceId token $token")
sendRegistrationToServer(token)
return token
}
Since I do not hand over the app level context, I get:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.demo, PID: 8047
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.demo/com.example.MainActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.demo. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.demo. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source:58)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(Unknown Source:0)
at com.google.firebase.messaging.FirebaseMessaging.getInstance(Unknown Source:9)
at com.example.network.fcm.exampleFirebaseInstanceIdService$Companion.initFirebaseMessaging(exampleFirebaseInstanceIdService.kt:14)
at com.example.MainActivity.onCreate(MainActivity.kt:168)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
ADDENDUM: I added that line to my init
fun initFirebaseMessaging(topic : String, context : context) : String
{
FirebaseApp.initializeApp(context)
FirebaseMessaging.getInstance().subscribeToTopic(topic)
Timber.d("Push subscribeToTopic $topic")
val token = FirebaseInstanceId.getInstance().token!!
Timber.d("Push FirebaseinstanceId token $token")
sendRegistrationToServer(token)
return token
}
leads to very same error message.
Your error
Make sure to call FirebaseApp.initializeApp(Context) first.
In your library u need create function like
public static void Init(Context context) {
FirebaseApp.initializeApp(context);
}
and call it before using firebase. Best way its add to your application
example :
... extends Application /*** code **/
onCreate () {
YourLibrary.Init(this);
}