frogermcs / AndroidDevMetrics

Performance metrics library for Android development (includes dagger2metrics)
1.54k stars 118 forks source link

RuntimeException when launch my app #21

Open nicopasso opened 8 years ago

nicopasso commented 8 years ago

Hi, my app crashes with this stack trace.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nicopasso.android.debug/com.nicopasso.android.ui.start.StartingActivity}: java.lang.RuntimeException: MethodsTracingManager must be initialized by init(..)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                at android.os.Looper.loop(Looper.java:148)
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                at java.lang.reflect.Method.invoke(Native Method)
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                             Caused by: java.lang.RuntimeException: MethodsTracingManager must be initialized by init(..)
                                                                                at com.frogermcs.androiddevmetrics.internal.MethodsTracingManager.checkInitialized(MethodsTracingManager.java:90)
                                                                                at com.frogermcs.androiddevmetrics.internal.MethodsTracingManager.shouldTraceMethod(MethodsTracingManager.java:84)
                                                                                at com.frogermcs.androiddevmetrics.aspect.ActivityLifecycleAnalyzer.executeWithTracingIfEnabled(ActivityLifecycleAnalyzer.java:77)
                                                                                at com.frogermcs.androiddevmetrics.aspect.ActivityLifecycleAnalyzer.ajc$inlineAccessMethod$com_frogermcs_androiddevmetrics_aspect_ActivityLifecycleAnalyzer$com_frogermcs_androiddevmetrics_aspect_ActivityLifecycleAnalyzer$executeWithTracingIfEnabled(ActivityLifecycleAnalyzer.java:1)
                                                                                at com.frogermcs.androiddevmetrics.aspect.ActivityLifecycleAnalyzer.logAndExecute(ActivityLifecycleAnalyzer.java:66)
                                                                                at com.nicopasso.android.ui.start.StartingActivity.onCreate(StartingActivity.java:43)
                                                                                at android.app.Activity.performCreate(Activity.java:6251)
                                                                                at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                at android.os.Looper.loop(Looper.java:148) 
                                                                                at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                at java.lang.reflect.Method.invoke(Native Method) 
                                                                                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

I've already tried to implement

MethodsTracingManager.getInstance().init(this);

in my StartingActivity as the stack trace says but still I have the same issue.

How can I solve this problem? Thanks

frogermcs commented 8 years ago

Hey!

AndroidDevMetrics should be initialized in Application class, not Activity (it's too late if you would do this).

Here is example code:

public class ExampleApplication extends Application {

 @Override
 public void onCreate() {
     super.onCreate();
     //Use it only in debug builds
     if (BuildConfig.DEBUG) {
         AndroidDevMetrics.initWith(this);
     }
  }
}
nicopasso commented 8 years ago

Yes yes I've done that of course :)

novalu commented 8 years ago

I have same issue with 4.0, getting that runtime exception.

I've tried AndroidDevMetrics.initWith(this); and MethodsTracingManager.getInstance().init(this); in Application onCreate() but with no success.

I have errors only in version 0.4, version 0.3.1 is working. Thanks.

tokou commented 8 years ago

I have the same issue with 4.0

It crashes when I do not initialize it. It shouldn't it should just do nothing.

This behavior was correct in 0.3.1

Max01010101010101 commented 8 years ago

Me too... uff.. i would like to test AndroidDevMetrics

ar-g commented 8 years ago

It crashes when I put

if (isInDebugMode) {
      AndroidDevMetrics.initWith(this);
    }

on top of onCreate of all initializations, but it fine when I put it at the end. It appears that it clashes with some other initialisations. I can say that I have other ActivityLifecycleListeners might be because of it.

drd commented 6 years ago

The plugin for android dev metrics assumes you will be using it for any debug build. I ran into this issue because I was disabling it when certain properties were passed to gradle. In order for this to work, I did following:

build:

In app/build.gradle, conditionally apply plugin based on a property passed through gradle (could be any condition of course):

if (project.hasProperty('ENABLE_TOOLS')) {
  apply plugin: 'com.frogermcs.androiddevmetrics'
}

If the tool is disabled, add a debugCompile dependency on the noop package:

if (project.hasProperty('ENABLE_TOOLS')) {
  debugCompile 'com.frogermcs.androiddevmetrics:androiddevmetrics-runtime-noop:0.5'
}

If you do not have an Application subclass for Debug builds:

Only initialize AndroidDevMetrics for debug builds:

onCreate() {
  // ...
  if (BuildConfig.DEBUG) {
    AndroidDevMetrics.initWith(this);
  }
  // ...
}

If you do have a DebugApplication class:

Always initialize for debug builds:

onCreate() {
  // ...
  AndroidDevMetrics.initWith(this);
  // ...
}
leeGYPlus commented 6 years ago

i meet this problem when i update my gradle`s version, i solve this problem by decreasing the gradle's version .Maybe the problem is the compatibility of the author's plugin.