This an exception I encountered when trying to use FirebaseAuth and Firebase Crash Reporting. I am trying to sign in anonymously in my application onCreate
public class MainApplication extends Application {
#Override
public void onCreate() {
super.onCreate();
FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
firebaseAuth.signInAnonymously().addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Log.wtf("TAG", "Signed signInAnonymously successful ");
}
});
}
}
I also want to use crash reporting so my gradle dependencies looks like this.
dependencies {
// other dependencies
// ...
compile 'com.google.firebase:firebase-core:9.2.1'
compile 'com.google.firebase:firebase-storage:9.2.1'
compile 'com.google.firebase:firebase-auth:9.2.1'
compile 'com.google.firebase:firebase-config:9.2.1'
compile 'com.google.firebase:firebase-crash:9.2.1'
}
apply plugin: 'com.google.gms.google-services'
After a certain amount of time I will get a crash dialog and this exception. Its another process that crashes so the app itself will still run.
java.lang.RuntimeException: Unable to create application com.android.tools.fd.runtime.BootstrapApplication: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4612)
at android.app.ActivityThread.access$1600(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
at com.redstar.collectors.MainApplication.onCreate(MainApplication.java:22)
at com.android.tools.fd.runtime.BootstrapApplication.onCreate(BootstrapApplication.java:369)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1013)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4609)
at android.app.ActivityThread.access$1600(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1337)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5476)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
If I remove the firebase-crash dependency there will be no crash.
FirebaseApp with name [DEFAULT] doesn't exist is caused when you run Firebase code on the separate process that is created by Firebase Crash Reporting as your custom Application class is created for each process in your app.
You should move code from your Application class to somewhere else. This could be in your main activity (which would always be in your main process) or could be in the onCreate() of a separate ContentProvider you register in your Manifest (a ContentProvider's onCreate() is run once in the lifecycle of your app's process just like Application.onCreate(), but only runs in a single process).
Related
I want to use Sentry for my Multiplatform Kotlin project.
Sentry for Kotlin Multiplatform
So I was trying to prepare the setup of Sentry with Kotlin Multiplatform.
I was following the guide, made a mavenLocal() build etc.
Now I wanted to add it to the project.
However, when starting my (Android) project, even before starting the onCreate() of the Application I get a crash stating:
Unable to get provider io.sentry.android.core.SentryInitProvider:
java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
So to be clear this happens already when adding api("io.sentry:sentry-kotlin-multiplatform:0.0.1") to the dependencies. Long before the init call.
All I did was:
Configure shared build.gradle.kts and add
val commonMain by getting {
dependencies {
api("io.sentry:sentry-kotlin-multiplatform:0.0.1")
Adding the sample configuration
fun initializeSentry(context: Context) {
Sentry.init(context) { sentryOptions -> setDsnHere... }
}
and in the Android Application:
initializeSentry(this)
Then tried to run it. But I don't even get to the init call.
The configuration should be reached and the initializeSentry(this) block executed. (I can accept if it fails there but I don't even get that far.)
Instead the app fails stating
E/AndroidRuntime: FATAL EXCEPTION: main
Process: xyz, PID: 23056
java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
...
even before anything else.
So the mere adding to the gradle file causes the crash already (even if the other code is commented out).
-------- Full Stack trace-------
java.lang.RuntimeException: Unable to get provider io.sentry.android.core.SentryInitProvider: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
at android.app.ActivityThread.installProvider(ActivityThread.java:7467)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.IllegalArgumentException: DSN is required. Use empty string to disable SDK.
at io.sentry.Sentry.initConfigurations(Sentry.java:201)
at io.sentry.Sentry.init(Sentry.java:170)
at io.sentry.Sentry.init(Sentry.java:118)
at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:87)
at io.sentry.android.core.SentryAndroid.init(SentryAndroid.java:56)
at io.sentry.android.core.SentryInitProvider.onCreate(SentryInitProvider.java:27)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2451)
at android.content.ContentProvider.attachInfo(ContentProvider.java:2421)
at io.sentry.android.core.SentryInitProvider.attachInfo(SentryInitProvider.java:44)
at android.app.ActivityThread.installProvider(ActivityThread.java:7462)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744)
at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Turns out the manual had forgotten to mention the auto configuration.
Add this line to your Manifest:
<meta-data android:name="io.sentry.auto-init" android:value="false" />
and proceed with the tutorial.
For Reference:
https://github.com/getsentry/sentry-kotlin-multiplatform/issues/45
I am creating a thread in the following manner:
GraphThread thread = new GraphThread(context, handler, string);
Note that handler is a static Handler object, which could be causing the problem. I have been getting an error exactly at this line of code. But, the error does not appear in other virtual devices such as API 23 and 25, as well as my physical device(Nougat).
I did try to set up a try{}catch block, but it is not catching the exception, which is unusual. The stack trace is as follows:
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException**
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick**(AppCompatViewInflater.java:384)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.VerifyError: noodlesoup/solver/GraphThready
at noodlesoup.solver.MainActivity.clikButton(MainActivity.java:4985)
It comes down to java.lang Verifyerror that I believe is created by passing the parameter static Handler. I don't know why this is happening in API 19 virtual device and not in the other virtual device which I have tested.
Any ideas or suggestions?
After reading through many posts, I came across the following idea: The void run method in my Thread class was too complex. There were too many variables defined inside the run method; There were too many decisions to make in a method that contained over 4000 lines of code. The post and answer that gave me the idea was the following
VerifyError - Verifier rejected class
So, all I had to do was create extra methods within the Thread class were the sum of
their work was equal to the 4000+ lines of code inside the run method.
In the end the Thread class structure looks like this, and it compiles without no more verify errors:
public class GraphThready extends Thread{
//...
GraphThready(){
//...
}
public void run(){
super.run();
if(some condition)
methodToDoTask1();
if(another condition)
methodToDoTask2();
if(a different condition)
methodToDoTask3();
}
private void methodToDoTask1(){
}
private void methodToDoTask2(){
}
private void methodToDoTask3(){
}
}
This is my application class:
package com.example.myapp
import android.support.multidex.MultiDexApplication
import com.facebook.appevents.AppEventsLogger
import com.google.firebase.FirebaseApp
import com.google.firebase.FirebaseOptions
import com.google.firebase.firestore.FirebaseFirestore
import com.google.firebase.firestore.FirebaseFirestoreSettings
class App : MultiDexApplication() {
override fun onCreate() {
super.onCreate()
// Facebook
AppEventsLogger.activateApp(this)
// Firebase
FirebaseApp.initializeApp(this)
val settings = FirebaseFirestoreSettings.Builder()
.setPersistenceEnabled(false)
.setTimestampsInSnapshotsEnabled(true)
.build()
FirebaseFirestore.getInstance().firestoreSettings = settings
}
}
This is the error I'm getting. It's failing on the last line of the App class, FirebaseFirestore.getInstance(), saying it's not initialized, but you can see above that I am initializing it?
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapp, PID: 8328
java.lang.RuntimeException: Unable to create application com.example.myapp.App: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.myapp. Make sure to call FirebaseApp.initializeApp(Context) first.
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5876)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.example.myapp. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(com.google.firebase:firebase-common##16.0.1:219)
at com.google.firebase.firestore.FirebaseFirestore.getInstance(com.google.firebase:firebase-firestore##17.0.5:49)
at com.example.myapp.App.onCreate(App.kt:31)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1154)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5871)
at android.app.ActivityThread.access$1100(ActivityThread.java:199)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1650)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Does anybody know what I need to do to fix this?
This is an instant app. I have put the google services json inside every module (base + app + instant) and have also added the plugin to each gradle.
It's just weird that it's obviously going past the initialize statement and still failing.
For me none of the solution worked that were given any where. Only this worked.
Just had to download grade my google services from 4.1.0 to 4.0.0
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha08'
classpath 'com.google.gms:google-services:4.0.0'
/*classpath 'com.google.gms:google-services:4.1.0' <-- this was the problem */
}
So if you have updated the google services, just try to downgrade or change to an older version.
This worked for me..
dependencies {
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:4.2.0'
I'm trying to migrate app to hosted parse server.App start but when it tries to query to hosted parse server it gets crashed.I had the issue with dependencies in the past now i fixed it.
If i use the parse service the app works fine.
Parse.enableLocalDatastore(this);
// Parse.initialize(this, "<key>", "<key>");
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("appid")
.clientKey("<key>")
.server("http://192.168.1.177:1337/parse/") // '/' important after 'parse'
.build());
Dependencies:
dependencies {
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
}
Error:
04-03 12:44:28.409 2911-2911/com.app.nameapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.app.nameapp, PID: 2911
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3823)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at android.view.View$1.onClick(View.java:3818)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
Caused by: java.lang.IllegalStateException: Method requires Local Datastore. Please refer to `Parse#enableLocalDatastore(Context)`.
at com.parse.ParseQuery.throwIfLDSEnabled(ParseQuery.java:292)
at com.parse.ParseQuery.throwIfLDSDisabled(ParseQuery.java:286)
at com.parse.ParseQuery.access$200(ParseQuery.java:90)
Could not able to post entire error message as it was very long. I think there is something wrong with parse local data store. As far as i know when pointing my app to hosted parse server i just need to add those few lines(appid,clientkey,server address). Is there any more changes needed in the app?
try the following:
Parse.initialize(new Parse.Configuration.Builder(this) .applicationId("yourappid") .clientKey("yourclientkey") .server("serverurl") .enableLocalDataStore() .build() );
It seems like you are trying to initialize Parse from an onClickListener, therefore the object this you are passing to Parse is the wrong one.
if you refer to this from on OnClickListener you get a reference to the interface even though it's an inline declaration in the activity.
you need to manually point to the correct Context and use it.
try changing your code to look like this:
Parse.enableLocalDatastore(MyActivity.this);
// Parse.initialize(this, "<key>", "<key>");
Parse.initialize(new Parse.Configuration.Builder(MyActivity.this)
.applicationId("appid")
.clientKey("<key>")
.server("http://192.168.X.XXX:1337/parse/") // '/' important after 'parse'
.build());
I use my library Projects ActiveAndroid for which you want to create a class:
import com.activeandroid.app.Application;
public class App extends Application {
#Override
public void onCreate()
{
super.onCreate();
}
}
on the emulator everything works fine, the data stored in the database and so on. but when you start the phone, the application crashes. and immediately.
Error:
01-29 12:55:19.027 14098-14098/com.skip.client.customer E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.skip.client.customer, PID: 14098
java.lang.NoClassDefFoundError: android.support.v4.app.ActivityCompat21$SharedElementCallbackImpl
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:305)
at com.activeandroid.ReflectionUtils.getModelClasses(ReflectionUtils.java:83)
at com.activeandroid.DatabaseHelper.onCreate(DatabaseHelper.java:46)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.activeandroid.Registry.openDatabase(Registry.java:149)
at com.activeandroid.Registry.initialize(Registry.java:107)
at com.activeandroid.ActiveAndroid.initialize(ActiveAndroid.java:8)
at com.activeandroid.app.Application.onCreate(Application.java:9)
at com.skip.client.customer.App.onCreate(App.java:12)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4473)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5146)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
It looks like getModelClasses() in active android is trying to find a java class in your code that matches the model classes you would have specified in your AndroidManifest.xml. Can you please post your manifest? Specifically, I'm looking for a line like this:
<meta-data
android:name="AA_MODELS"
android:value="
com.example.myapp.Book,
com.example.myapp.Chapter,
com.example.myapp.Library
"/>
If classes Book, Chapter, and Library are not defined in your code, then you'd get the no-class-def-found exception.
Also, I'd recommend changing your app to have your custom app class derive from android.app.Application instead of from the ActiveAndroid app base class. And then explicitly initialize ActiveAndroid. This will allow you to have your own exception handling around ActiveAndroid.initialize() and then explore why your exception is being thrown. You can also use the debugger to step into the initialize() method and see where the exception is coming from.
import com.activeandroid.ActiveAndroid;
public class App extends android.app.Application {
#Override
public void onCreate()
{
super.onCreate();
// add your own exception handling around this. Not that you can do much
// in your app without a database, but at least you'd be able to log a
// meaningful error to the log so you can know details about the exception
// being thrown.
ActiveAndroid.initialize(this);
}
}