Search code examples
androidxamarinandroid-instrumentation

When is instrumentation involved in app start?


I have a Xamarin Android app in production, and I see quite a few following crashes in reports in Google Play Developer Console:

java.lang.UnsatisfiedLinkError: Native method not found:
mono.android.Runtime.register:(Ljava/lang/String;Ljava/lang/Class;Ljava/lang/String;)V
at mono.android.Runtime.register(Native Method)
at speedcamapp.SpeedcamApplication.onCreate(SpeedcamApplication.java:18)
at
android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1008)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4506)
at android.app.ActivityThread.access$1500(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1306)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5196)
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:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)

Since this seems like Xamarin bug, I asked them and I was told the problem is this line :

at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1008)

that it is not normal for app to be started with instrumentation and it means that somebody is "tinkering" with my app.

But I can see many of these errors, from many different devices, and some users even left the message "it stopped working" with their crash report...

I tried googling "android.app.Instrumentation.callApplicationOnCreate" and I found many app logs with this line in log.

So my question is, that does "android.app.Instrumentation.callApplicationOnCreate" really mean? When can this happen to ordinary user out there?


Solution

  • Actually this is normal stack trace of Application.onCreate() method. Instrumetnation is used every time when any lifecycle method's of Application or Activity is called.

    Take a look on this stack trace. I made it in my normal (not Xamarin) application. I launched it without any mention of instrumentation of course:

    java.lang.UnsatisfiedLinkError
        at com.example.asdf.MyApplication.onCreate(MyApplication.java:11)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4518)
        at android.app.ActivityThread.access$1500(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1339)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
    

    For me it is clear that Instrumentation is envolved every time when onCreate() is called. But we can check whether if it is really every time or not. It is in source code. As you can see onCreate() called from a few places:

    1. android.app.Instrumentation.callApplicationOnCreate()
    2. android.app.ActivityThread.attach(boolean)
    3. android.test.ApplicationTestCase.createApplication()

    (Other calls are super.onCreate() and not our case)

    ApplicationTestCase is not our case obviously. ActivityThread.attach() is something similar. But it calls Application.onCreate() only for system applications. You can see it if you go above on source code. So the rest is Instrumentation.callApplicationOnCreate().

    We can say that you have normal stack trace and nothing special in Instrumentation.callApplicationOnCreate(). So your problem with UnsatisfiedLinkError is somewhere else. Unfortunately I didn't use Xamarin and I cannot help you with it