I am able to generate instrumented apk using JaCoCo Maven plugin as below:
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>${jacoco-plugin.version}</version>
<classifier>runtime</classifier>
</dependency>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-plugin.version}</version>
</plugin>
But when I install the app on the device and launch it, it crashes.
I see below in logcat:
D/dalvikvm( 9147): DexOpt: unable to opt direct call 0x6def at 0x23 in Lorg/jacoco/agent/rt/internal_9dd1198/Agent;.shutdown
D/dalvikvm( 9147): DexOpt: unable to opt direct call 0x6df0 at 0x30 in Lorg/jacoco/agent/rt/internal_9dd1198/Agent;.startup
D/dalvikvm( 9147): DexOpt: unable to opt direct call 0x6def at 0x37 in Lorg/jacoco/agent/rt/internal_9dd1198/Agent;.startup
W/System.err( 9147): android.os.NetworkOnMainThreadException
W/System.err( 9147): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
W/System.err( 9147): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
W/System.err( 9147): at java.net.InetAddress.getLocalHost(InetAddress.java:365)
W/System.err( 9147): at org.jacoco.agent.rt.internal_9dd1198.Agent.createSessionId(Agent.java:179)
W/System.err( 9147): at org.jacoco.agent.rt.internal_9dd1198.Agent.startup(Agent.java:122)
W/System.err( 9147): at org.jacoco.agent.rt.internal_9dd1198.Agent.getInstance(Agent.java:56)
W/System.err( 9147): at org.jacoco.agent.rt.internal_9dd1198.Offline.<clinit>(Offline.java:31)
W/System.err( 9147): at {app_ID}.MainApplication.$jacocoInit(MainApplication.java)
W/System.err( 9147): at {app_ID}.MainApplication.<clinit>(MainApplication.java)
W/System.err( 9147): at java.lang.Class.newInstanceImpl(Native Method)
....
W/System.err( 9147): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
W/System.err( 9147): at dalvik.system.NativeStart.main(Native Method)
Any help would be greatly appreciated.
Thanks!
I have now run into another issue:
java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)
I found below thread and see that it's resolved using offline instrumentation.
https://github.com/jacoco/jacoco/pull/58
On reading (http://www.eclemma.org/jacoco/trunk/doc/offline.html), I realized that I need to specify path for jacoco-agent.destfile. I tried updating the config as below, but I still see the same error. Since I am trying to get run the test manully, I can't set this property as part of some test run.
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-plugin.version}</version>
<configuration>
<systemPropertyVariables>
****** <jacoco-agent.destfile>sdcard/jacoco.exec</jacoco-agent.destfile> ******
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>instrument-classes</id>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<excludes>
<exclude>*test*</exclude>
<exclude>*/test/*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>restore-instrumented-classes</id>
<phase>package</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
</executions>
</plugin>
Thanks,
Rahul
To deploy jacoco-agent.properties with the app, I took below steps:
1. Updated Pom.xml of the main app to include <resources>:
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>src/main/resources/jacoco-agent.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-plugin.version}</version>
<executions>
<execution>
<id>instrument-classes</id>
<goals>
<goal>instrument</goal>
</goals>
<configuration>
<excludes>
<exclude>*test*</exclude>
<exclude>*/test/*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>restore-instrumented-classes</id>
<phase>package</phase>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
</executions>
</plugin>
2. Copied: jacoco-agent.properties to src/main/resources
I am doing all these changes in the main app. Since I am trying to get code coverage for manual testing, I have not other test project.
----
For MonkeyRunner tests, they run outside the maven configuration. I these tests are called from terminal.
I tried supplying jacocoagent at runtime, using below command:
$ANDROID_HOME/tools/monkeyrunner -u -PATH_TO_TEST/test_runner.py -javaagent:/Users/username/Desktop/AndroidCodeCoverage/jacoco-0.6.4-20131014.021613-14/lib/jacocoagent.jar=destfile=/sdcard/jacoco.exec
----
In both scenario, I am seeing the same error as before:
D/dalvikvm(28814): DexOpt: unable to opt direct call 0x6def at 0x23 in Lorg/jacoco/agent/rt/internal_3d5ada2/Agent;.shutdown
D/dalvikvm(28814): DexOpt: unable to opt direct call 0x6df0 at 0x30 in Lorg/jacoco/agent/rt/internal_3d5ada2/Agent;.startup
D/dalvikvm(28814): DexOpt: unable to opt direct call 0x6def at 0x37 in Lorg/jacoco/agent/rt/internal_3d5ada2/Agent;.startup
W/System.err(28814): java.io.FileNotFoundException: /jacoco.exec: open failed: EROFS (Read-only file system)
W/System.err(28814): at libcore.io.IoBridge.open(IoBridge.java:416)
W/System.err(28814): at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
Really appreciate you take a look at this.
Thanks,
Rahul
--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/9Atzd4Kq0NU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
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.