DalvikVM could not find field after ProGuard Obfuscation

603 views
Skip to first unread message

GDroid

unread,
Nov 4, 2009, 11:37:05 AM11/4/09
to Android Developers
I've been trying obfuscate my application for the last 2 days.
I must add that I'm new to Java, Eclipse, Ant and Android as well.

Currently I've managed to build the correct build.xml file and run
ProGuard 4.4. However, every time I install my apk I get multiple
errors from the "dalvikvm" such as "Found field 'e' but sig is 'J' not
'B'" or ".. sig is 'Lc' not '[c'" (Which has something to do with
arrays and enums).

This is my current proguard configuration:
<target name="obfuscate" depends="compile">
<jar basedir="${out-classes}" destfile="temp.jar"/>
<java jar="C:\onefone\proguard4.4\lib\proguard.jar" fork="true"
failonerror="true">
<jvmarg value="-Dmaximum.inlined.code.length=32"/>
<arg value="-injars temp.jar"/>
<arg value="-outjars optimized.jar"/>
<arg value="-libraryjars ${android-jar}"/>
<arg value="-dontpreverify"/>
<!-- <arg value="-dontoptimize"/> -->
<arg value="-dontusemixedcaseclassnames"/>
<arg value="-repackageclasses ''"/>
<arg value="-printmapping mappings.txt"/>
<arg value="-allowaccessmodification"/>
<arg value="-overloadaggressively"/>
<arg value="-useuniqueclassmembernames"/>
<arg value="-dontshrink"/>
<arg value="-keep public class * extends android.app.Activity"/>
<arg value="-keep public class * extends android.app.Service"/>
<arg value="-keep public class * extends
android.content.BroadcastReceiver"/>
<arg value="-keep public class * extends
android.content.ContentProvider"/>
<arg value="-keep public class * extends android.view.View"/
>
<arg value="-keep interface * "/>
<arg value="-keepclassmembernames class * { java.lang.Class class$
(java.lang.String); java.lang.Class class$(java.lang.String,
boolean); }"/>
<arg value="-keepclassmembernames class
com.GCompany.GCompanyStart"/>
<arg value="-keep enum * "/>
<arg value="-microedition" />
<arg value="-keepclassmembers public enum * "/>
<arg value="-keepclassmembers enum * { public static **[] values
(); public static ** valueOf(java.lang.String); static **[] $VALUES;}
"/>
<arg value="-optimizations !code/simplification/arithmetic"/>
<arg value="-adaptresourcefilenames
**.properties,**.gif,**.jpg"/>
<arg value="-adaptresourcefilecontents **.properties,META-INF/
MANIFEST.MF"/>
<arg value="-optimizationpasses 1"/>
<arg value="-printseeds seeds.txt"/>
<arg value="-keepattributes
Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod"/
>
<arg value="-verbose"/>
</java>
<delete file="temp.jar"/>
<delete dir="${out-classes}"/>
<mkdir dir="${out-classes}"/>
<unzip src="optimized.jar" dest="${out-classes}"/>
<delete file="optimized.jar"/>
</target>

When I look at the mapping.txt file I see duplicate members changing
to the same name like:

com.GCompany.WiFiLocker -> ba:
android.net.wifi.WifiManager wifiManager -> a
android.net.wifi.WifiManager$WifiLock wifiLock -> a

I'm not sure if this is bad or not.

After installing my application I get these errors:
11-04 15:59:15.323: INFO/PackageManager(564): /data/app/vmdl68172.tmp
changed; unpacking
11-04 15:59:15.414: DEBUG/installd(543): DexInv: --- BEGIN '/data/app/
vmdl68172.tmp'
---11-04 15:59:16.445: WARN/dalvikvm(1444): Found field 'a', but sig
is 'Landroid/net/wifi/WifiManager$WifiLock;' not 'Landroid/net/wifi/
WifiManager;'
11-04 15:59:16.455: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:16.564: WARN/dalvikvm(1444): Found field 'a', but sig is
'Lcom/OF/GCompany/Logger/ILogger;' not '[I'
11-04 15:59:16.574: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:16.584: WARN/dalvikvm(1444): Found field 'a', but sig is
'Lcom/OF/GCompany/Logger/ILogger;' not 'S'
11-04 15:59:16.595: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:16.634: WARN/dalvikvm(1444): Found field 'a', but sig is
'B' not 'Lcom/OF/GCompany/Logger/ILogger;'
11-04 15:59:16.634: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:16.825: WARN/dalvikvm(1444): Found field 'e', but sig is
'Lcom/GCompany/CallState;' not 'Z'
11-04 15:59:16.835: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:16.854: WARN/dalvikvm(1444): Found field 'e', but sig is
'Lcom/GCompany/CallState;' not 'Z'
11-04 15:59:16.854: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:16.864: WARN/dalvikvm(1444): Found field 'a', but sig is
'J' not 'Lcom/OF/GCompany/TServiceId;'
11-04 15:59:16.874: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:16.884: WARN/dalvikvm(1444): Found field 'e', but sig is
'Lcom/GCompany/CallState;' not 'Z'
11-04 15:59:16.894: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:17.025: WARN/dalvikvm(1444): Found field 'a', but sig is
'Landroid/net/wifi/WifiManager$WifiLock;' not 'Landroid/net/wifi/
WifiManager;'
11-04 15:59:17.035: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:17.145: WARN/dalvikvm(1444): Found field 'a', but sig is
'Lcom/OF/GCompany/Logger/ILogger;' not 'Lcom/GCompany/comm/
CommHandler;'
11-04 15:59:17.154: DEBUG/dalvikvm(1444): DexOpt: couldn't find static
field
11-04 15:59:17.315: WARN/dalvikvm(1444): Found field 'e', but sig is
'Lcom/GCompany/CallState;' not 'Z'
--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Also, when trying to run the application I get one
11-04 16:17:25.074: WARN/dalvikvm(1448): Found field 'a', but sig is
'Landroid/net/wifi/WifiManager$WifiLock;' not 'Landroid/net/wifi/
WifiManager;'
And the application exit with:
11-04 16:17:25.134: ERROR/AndroidRuntime(1448): Uncaught handler:
thread main exiting due to uncaught exception
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): java.lang.VerifyError:
com.GCompany.GCompanyStart
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
java.lang.Class.newInstanceImpl(Native Method)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
java.lang.Class.newInstance(Class.java:1472)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.app.Instrumentation.newActivity(Instrumentation.java:1097)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2186)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2284)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.app.ActivityThread.access$1800(ActivityThread.java:112)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.os.Handler.dispatchMessage(Handler.java:99)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.os.Looper.loop(Looper.java:123)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
android.app.ActivityThread.main(ActivityThread.java:3948)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
java.lang.reflect.Method.invokeNative(Native Method)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
java.lang.reflect.Method.invoke(Method.java:521)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:782)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
11-04 16:17:25.173: ERROR/AndroidRuntime(1448): at
dalvik.system.NativeStart.main(Native Method)

When skipping the obfuscate target during the build I don't get these
errors.

Any help will be appreciated…

Thank you
GDroid

fadden

unread,
Nov 6, 2009, 4:52:47 PM11/6/09
to Android Developers
On Nov 4, 8:37 am, GDroid <baron...@gmail.com> wrote:
> Currently I've managed to build the correct build.xml file and run
> ProGuard 4.4. However, every time I install my apk I get multiple
> errors from the "dalvikvm" such as "Found field 'e' but sig is 'J' not
> 'B'" or ".. sig is 'Lc' not '[c'" (Which has something to do with
> arrays and enums).

If these are static fields, I'm guessing you've run afoul of this:

http://code.google.com/p/android/issues/detail?id=2422

In short, the VM spec allows you to have multiple fields with the same
name but different types, but Dalvik was rejecting them.

The fix should be in 2.0. What version of the Android software are
you testing against?

ProGuard is very good about letting you configure specific things.
Looking through the online manual, it looks like turning off "-
overloadaggressively" may avoid this behavior.

GDroid

unread,
Nov 18, 2009, 4:47:04 AM11/18/09
to Android Developers


I was testing against 1.5.
I removed the "- overloadaggressively" and it worked.

Thanks for the help.
Reply all
Reply to author
Forward
0 new messages