The app can not start up if its decompiled jar is instrumented by jacoco while working well by ASM

731 views
Skip to first unread message

Tool Ply

unread,
Jan 29, 2018, 8:14:28 AM1/29/18
to JaCoCo and EclEmma Users
Just like the title.

I decompiled the apk and use ASM and Jacoco to instrument it jar separately. The result shows that ASM work well. However, the apk instrumented by Jacoco could not start up and I did not find any .exec files by command `find . -name jacoco`

In order to verificate if it was caused by file read and write errors, I have tried to config 'output=none' in jacoco-agent.properties in the Dalvik and added the path to classpath. It does not work.


How to fix it?

Marc Hoffmann

unread,
Jan 29, 2018, 11:51:34 AM1/29/18
to jac...@googlegroups.com

> the apk instrumented by Jacoco could not start up

Is there any error message?

Regards,
-marc

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/ee34d583-c01c-4340-809b-2a6d43faf23d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Tool Ply

unread,
Jan 30, 2018, 4:18:57 AM1/30/18
to jac...@googlegroups.com
Yes, as the following:

Ply Truth, [30.01.18 17:11]
01-30 01:07:48.058  1360  1650 D EGL_emulation: eglMakeCurrent: 0x8d8bf4c0: ver 2 0 (tinfo 0x8d8b7ac0)
01-30 01:07:48.344  2831  2831 D AndroidRuntime: Shutting down VM
01-30 01:07:48.355  2831  2831 E AndroidRuntime: FATAL EXCEPTION: main
01-30 01:07:48.355  2831  2831 E AndroidRuntime: Process: com.tsinghua.date.sample, PID: 2831
01-30 01:07:48.355  2831  2831 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_290345e/Offline;
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at com.tsinghua.date.sample.SettingsActivity.$jacocoInit(Unknown Source:13)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at com.tsinghua.date.sample.SettingsActivity.<clinit😠Unknown Source:0)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at java.lang.Class.newInstance(Native Method)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.app.Instrumentation.newActivity(Instrumentation.java:1174)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2669)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.app.ActivityThread.access$1300(ActivityThread.java:176)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.os.Handler.dispatchMessage(Handler.java:106)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.os.Looper.loop(Looper.java:164)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at android.app.ActivityThread.main(ActivityThread.java:6494)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at java.lang.reflect.Method.invoke(Native Method)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:816)
01-30 01:07:48.355  2831  2831 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_290345e.Offline" on path: DexPathList[[zip file "/data/app/com.tsinghua.date.sample-O4Rk5hb51sr4_D96mT2MnQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tsinghua.date.sample-O4Rk5hb51sr4_D96mT2MnQ==/lib/arm, /system/lib, /vendor/lib]]
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
01-30 01:07:48.355  2831  2831 E AndroidRuntime:   ... 14 more
01-30 01:07:48.382  1180  1674 W ActivityManager:   Force finishing activity com.tsinghua.date.sample/.SettingsActivity


2018-01-30 0:51 GMT+08:00 Marc Hoffmann <hoff...@mountainminds.com>:

> the apk instrumented by Jacoco could not start up

Is there any error message?

Regards,
-marc

 

On 2018-01-29 14:14, Tool Ply wrote:

Just like the title.
 
I decompiled the apk and use ASM and Jacoco to instrument it jar separately. The result shows that ASM work well. However, the apk instrumented by Jacoco could not start up and I did not find any .exec files by command `find . -name jacoco`
 
In order to verificate if it was caused by file read and write errors, I have tried to config 'output=none' in jacoco-agent.properties in the Dalvik and added the path to classpath. It does not work.
 
 
How to fix it?

 

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe@googlegroups.com.

 

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/908fd65bd2a56db22477265e6a525716%40mountainminds.com.

Tool Ply

unread,
Jan 30, 2018, 4:59:12 AM1/30/18
to jac...@googlegroups.com
I tried the Missing Jacoco Components Jar in this questions java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_14f7ee5/Offline

The classpath in android is:

/sdcard/app_test/:/sdcard/app_test/lib/org.jacoco.report-0.8.0.jar:/sdcard/app_test/lib/org.jacoco.report-0.8.0.201801022044.jar:/sdcard/app_test/lib/org.jacoco.core-0.8.0.jar:/sdcard/app_test/lib/org.jacoco.core-0.8.0.201801022044.jar:/sdcard/app_test/lib/org.jacoco.cli-0.8.0-nodeps.jar:/sdcard/app_test/lib/org.jacoco.ant-0.8.0.jar:/sdcard/app_test/lib/org.jacoco.ant-0.8.0.201801022044.jar:/sdcard/app_test/lib/org.jacoco.ant-0.8.0-nodeps.jar:/sdcard/app_test/lib/org.jacoco.agent-0.8.0.jar:/sdcard/app_test/lib/org.jacoco.agent-0.8.0.201801022044.jar:/sdcard/app_test/lib/org.jacoco.agent-0.8.0-runtime.jar:/sdcard/app_test/lib/junit-4.12.jar:/sdcard/app_test/lib/jacococli.jar:/sdcard/app_test/lib/jacocoant.jar:/sdcard/app_test/lib/jacocoagent.jar:/sdcard/app_test/lib/hamcrest-core-1.3.jar:/sdcard/app_test/lib/asm-5.2.jar:/sdcard/app_test/lib/args4j-2.0.28.jar:/sdcard/app_test/lib/android-jacoco-the-missing.jar:

it doesn't work👽

2018-01-30 0:51 GMT+08:00 Marc Hoffmann <hoff...@mountainminds.com>:

> the apk instrumented by Jacoco could not start up

Is there any error message?

Regards,
-marc

 

On 2018-01-29 14:14, Tool Ply wrote:

Just like the title.
 
I decompiled the apk and use ASM and Jacoco to instrument it jar separately. The result shows that ASM work well. However, the apk instrumented by Jacoco could not start up and I did not find any .exec files by command `find . -name jacoco`
 
In order to verificate if it was caused by file read and write errors, I have tried to config 'output=none' in jacoco-agent.properties in the Dalvik and added the path to classpath. It does not work.
 
 
How to fix it?

 

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe@googlegroups.com.

 

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/908fd65bd2a56db22477265e6a525716%40mountainminds.com.

Marc Hoffmann

unread,
Jan 30, 2018, 3:26:43 PM1/30/18
to jac...@googlegroups.com

Hi,

the problem is here that the correct JaCoCo runtime (provided by jacocoagent.jar) cannot be found:

01-30 01:07:48.355  2831  2831 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_290345e.Offline" on path: DexPathList[[zip file "/data/app/com.tsinghua.date.sample-O4Rk5hb51sr4_D96mT2MnQ==/base.apk"],nativeLibraryDirectories=[/data/app/com.tsinghua.date.sample-O4Rk5hb51sr4_D96mT2MnQ==/lib/arm, /system/lib, /vendor/lib]]

Please include jacocoagent.jar in you application class path.

Important: The jacocoagent.jar file must be from the exact same release than the JaCoCo version used for offline instrumentation. In your case 0.8.0.

Regards,
-marc

To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/CAEqeQ9Gn7QQMEfJguH557ZC19g19frYXWJPd_t7jgz2%2BVjur1Q%40mail.gmail.com.

Evgeny Mandrikov

unread,
Jan 30, 2018, 5:16:57 PM1/30/18
to JaCoCo and EclEmma Users


On Tuesday, January 30, 2018 at 10:59:12 AM UTC+1, Tool Ply wrote:


As Marc said : you should not use some random JAR from internet, but jacocoagent.jar that is part of JaCoCo distribution ( http://www.jacoco.org/jacoco/ ) of a version that you use for offline instrumentation. In your case this is 0.8.0, so you'll find jacocoagent.jar in folder "lib" of http://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.0/jacoco-0.8.0.zip

Alternatively exactly the same JAR can be obtained from Maven Central repository - as described on page http://www.jacoco.org/jacoco/trunk/doc/repo.html it has groupId "org.jacoco" artifactId "org.jacoco.agent" classifier "runtime" and version 0.8.0, so http://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.0/org.jacoco.agent-0.8.0-runtime.jar

Of course placing it in classpath won't be enough - it should be loadable by Android VM as like instrumented application, so should be translated to Dalvik bytecode.

Tool Ply

unread,
Jan 31, 2018, 11:27:06 PM1/31/18
to jac...@googlegroups.com
Thanks, Marc and Evgeny.
In fact, I have tried what Evgeny said before asking this question, however, it did not work. According to what both you said, I tried it as following steps.

My experiment is based on an emulator with API Level 24, these are the details
内嵌图片 1
and the error in the emulator is changed to 

02-01 03:35:45.421  1934  1934 E AndroidRuntime: FATAL EXCEPTION: main

02-01 03:35:45.421  1934  1934 E AndroidRuntime: Process: com.tsinghua.date.sample, PID: 1934

02-01 03:35:45.421  1934  1934 E AndroidRuntime: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jacoco/agent/rt/internal_290345e/Offline;

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at com.tsinghua.date.sample.SettingsActivity.$jacocoInit(Unknown Source)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at com.tsinghua.date.sample.SettingsActivity.<clinit>(Unknown Source)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at java.lang.Class.newInstance(Native Method)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.app.Instrumentation.newActivity(Instrumentation.java:1078)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2538)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.app.ActivityThread.-wrap12(ActivityThread.java)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6077)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jacoco.agent.rt.internal_290345e.Offline" on path: DexPathList[[zip file "/data/app/com.tsinghua.date.sample-1/base.apk"],nativeLibraryDirectories=[/data/app/com.tsinghua.date.sample-1/lib/arm, /system/lib, /vendor/lib]]

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:380)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: at java.lang.ClassLoader.loadClass(ClassLoader.java:312)

02-01 03:35:45.421  1934  1934 E AndroidRuntime: ... 14 more

02-01 03:35:45.518   938  1487 W ActivityManager:   Force finishing activity com.tsinghua.date.sample/.SettingsActivity


What I did:
Step 1: I parse the jacoco-0.8.0/lib/jacocoagent.jar to Dalvik class. by using $ANDROID_SDK_PATH/build-tools/24.0.3/dx.
Step 2: adb start, to get root
Step 3: push the parsed jacocoagent.jar to /data/app/com.tsinghua.date.sample-1/lib/arm/
Step 4: add the jacocoagent.jar to CLASSPATH, export CLASSPATH=/data/app/com.tsinghua.date.sample-1/lib/arm/jacocoagent.jar:$CLASSPATH
and the CLASSPATH was indeed changed successfully.
Step 5: restart the app, and the error was still there, I was confused.

PS: 
       PS 1: My little app, sample, was indeed instrumented with jacoco-0.8.0, as the maven config shows.
内嵌图片 2
     PS 2: to confirm whether it is because of the differences between jacocoagent.jar from jacoco-0.8.0.zip and the jar from maven, I have tried to replace the jacoco-0.8.0.jar in Step 1 and Step 3 with org.jacoco.agent-0.8.0-runtime.jar which is from maven, .m2/library/... and also contain org.jacoco.agent.rt.internal_290345e.Offline
     PS 3: In Step 4, I have alse tried to remount /system and /vendor, and push the jar into /vendor/lib/, it also did't work.


I was fully confused.....please save me🤕

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages