adding 'emma' to Android ant build triggers "local variable type mismatch" exception
Asked Answered
L

2

7

I am trying to run Emma on the tests for an Android project that is a combination of Java and C/JNI code. The build and tests work fine, but whenever I add emma, I get a mysterious exception. I'm using the Android SDK v20.1 and NDK r8b.

The project is here, its an Android library project: https://github.com/guardianproject/IOCipher and the tests are here: https://github.com/guardianproject/IOCipherTests

The build.xml file is generated using android update test-project. Running ant clean debug install test works everytime while ant clean emma debug install test triggers the exception:

here's the exception:

-dex:
      [dex] Converting compiled files and external libraries into /var/lib/jenkins/workspace/IOCipherTests/IOCipherTests/bin/classes.dex...
       [dx] 
       [dx] EXCEPTION FROM SIMULATION:
       [dx] local variable type mismatch: attempt to set or access a value of type int using a local variable of type info.guardianproject.libcore.io.ErrnoException. This is symptomatic of .class transformation tools that ignore local variable information.
       [dx] 
       [dx] ...at bytecode offset 0000002e
       [dx] locals[0000]: Linfo/guardianproject/iocipher/File;
       [dx] locals[0001]: Linfo/guardianproject/iocipher/FileDescriptor;
       [dx] locals[0002]: <invalid>
       [dx] locals[0003]: <invalid>
       [dx] locals[0004]: <invalid>
       [dx] locals[0005]: [Z
       [dx] stack[top0]: int{0x00000001 / 1}
       [dx] ...while working on block 002c
       [dx] ...while working on method createNewFile:()Z
       [dx] ...while processing createNewFile ()Z
       [dx] ...while processing info/guardianproject/iocipher/File.class
       [dx] 
       [dx] 1 error; aborting
BUILD FAILED
/opt/android-sdk/tools/ant/build.xml:850: The following error occurred while executing this line:
/opt/android-sdk/tools/ant/build.xml:852: The following error occurred while executing this line:
/opt/android-sdk/tools/ant/build.xml:864: The following error occurred while executing this line:
/opt/android-sdk/tools/ant/build.xml:266: null returned: 1
Liquid answered 30/8, 2012 at 19:10 Comment(6)
Add some related parts of your ant build file plz.Pharmacopoeia
The ant build file is the one generated using android update test-project. I wouldn't really know which parts to post.Liquid
FWIW I have the same error with a library project that has no C or JNI code.Grilled
you may want to add emma.filter=-<guardianproject_package> in ant.properties of the project . I had the same problem and from what I could make out was that emma was trying to re-instrument already instrumented code and that might be causing the problemSubtraction
just tried again with SDK v21 and emma.filter, but have the same error still. For filters, I tried info.guardianproject.iocipher and info.guardianproject.iocipher.testsLiquid
Did you ever fix this? My team currently has the same problem.Hesiod
G
3

I was getting the same error. In my project we had a unit test app in one project, which wrapped another project containing the unit tests themselves. Both projects held references to my SDK which, as chaitanya suggested, was causing emma to instrument the SDK code twice. By removing the reference to the SDK in the unit test project I was able to resolve the error.

Galyak answered 10/5, 2013 at 18:22 Comment(2)
Yes, this solved it for me too. My SDKs tests are in a directory under my main project. In my test project in ant.properties I commented out this line: #tested.project.dir=/Users/audrey/Developer/MyProject-SDK and then I stopped getting these errors.Cleocleobulus
What do you mean by 'my SDKs'? The Android SDK, or your self-made own library?Hesiod
M
0

I build the Android APK project from the command line (without ant, but with some help of CMake. I guess this is not important here) and I met the same error, two things helped me:

  1. From here, I got the info that "If you instrument class files that have local variable debug information in them emma does not correctly maintain the local variable table. This will cause an error when you try to convert the class files for Android. The workaround for this to compile the java classes with only line and source debug information, not local information.", so I add a flag to java compiler-g:{lines,source}

  2. I also excluded Emma classes itself from instrumentation. My instrumentation command is java -cp emma/emma_device.jar emma instr -ix -*.test.*,-com.google.android.*,-com.vladium.* -m overwrite -cp ${CMAKE_JAVA_TARGET_OUTPUT_DIR}. Pay attention to -ix -com.vladium.* parameter, this excludes Emma classes

Matador answered 10/3, 2015 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.