应用程序启动何时涉及检测?

When is instrumentation involved in app start?

我有一个正在生产中的 Xamarin Android 应用程序,我在 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.access00(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)

因为这看起来像是 Xamarin 错误,I asked them and I was told 问题是这一行:

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

使用检测启动应用程序是不正常的,这意味着有人 "tinkering" 使用我的应用程序。

但我可以从许多不同的设备上看到许多这样的错误,一些用户甚至在他们的崩溃报告中留下了消息 "it stopped working"...

我尝试使用谷歌搜索 "android.app.Instrumentation.callApplicationOnCreate",我在日志中发现了很多带有这一行的应用程序日志。

所以我的问题是,"android.app.Instrumentation.callApplicationOnCreate" 真的是这个意思吗? 普通用户什么时候能遇到这种情况?

实际上这是 Application.onCreate() 方法的正常堆栈跟踪。每次调用 ApplicationActivity 的任何生命周期方法时都会使用 Instrumentnation。

查看此堆栈跟踪。我在我的普通(不是 Xamarin)应用程序中完成了它。当然,我在没有提及仪器的情况下启动了它:

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.access00(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)

对我来说很明显,每次调用 onCreate() 时都会涉及 Instrumentation。但是我们可以检查它是否真的每次都是。它在 source code 中。如您所见,onCreate() 从几个地方调用:

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

(其他调用是super.onCreate()而不是我们的情况)

ApplicationTestCase 显然不是我们的情况。 ActivityThread.attach() 是类似的东西。但它只为系统应用程序调用 Application.onCreate()。如果你在上面查看源代码,你可以看到它。所以剩下的就是Instrumentation.callApplicationOnCreate()

我们可以说您有正常的堆栈跟踪,Instrumentation.callApplicationOnCreate() 中没有什么特别之处。所以你的 UnsatisfiedLinkError 问题出在其他地方。不幸的是我没有使用 Xamarin,我无法帮助你