I'm trying to obfuscate an Android JAR using Proguard (4.7, but 4.6 problematic too). I could break down the problem into a simple sample project.
The problem: For some functions (unclear for what reasons) the argument names of exposed functions are lost, sometimes "scrambled" (really). I would like to focus on the "lost" part first, because the scrambled thing is much more weird...
1) I created a library project in Eclipse. Android SDK is 2.1-update 1 for some reasons The project is marked as "Library Project" and has just one class MyJarEntry.java and one exported function foo
package com.decades.myjar;
import android.location.LocationListener;
public class MyJarEntry {
public void foo(String provider, long minTime, float minDistance, LocationListener listener) {
}
}
2) My project has a subdir "proguard" containing the latest proguard.jar plus the proguard.cfg, which looks like this
-printmapping out.map
-keepparameternames
-renamesourcefileattribute SourceFile
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,
SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keep public class * {
public protected *;
}
3) My Build.xml has targets for building the JAR and optimizing it like this, so after building the lib in Eclipse I do "ant jar" and "and optimize" in a terminal. This is build.xml
<project name="MyJar" default="jar" basedir=".">
<description>
Lib JAR builder
</description>
<!-- set global properties for this build -->
<property name="res" location="res" />
<property name="bin" location="bin" />
<!-- Output directories -->
<property name="out.dir" value="bin" />
<property name="out.absolute.dir" location="${out.dir}" />
<property name="out.classes.dir" value="${out.absolute.dir}/com" />
<property name="out.classes.absolute.dir" location="${out.classes.dir}" />
<!-- Pack the jar -->
<target name="jar">
<jar destfile="MyJar.jar" basedir="bin/">
<!-- replace 'com' by what ever you are using -->
<!-- as first part of the package name -->
<!-- e.g. de, org, ... -->
<!-- the ** is important to include the directory recursively -->
<include name="com/**" />
</jar>
</target>
<!-- Obfuscation with ProGuard -->
<property name="version" value="0.0.1"/> <!-- change this occasionally -->
<property name="proguard-dir" value="proguard"/>
<property name="unoptimized" value="MyJar.jar"/>
<property name="optimized" value="MyJar_${version}.jar"/>
<target name="optimize" unless="nooptimize">
<!-- Run obfuscator -->
<java jar="${proguard-dir}/proguard.jar" fork="true" failonerror="true">
<jvmarg value="-Dmaximum.inlined.code.length=16"/>
<arg value="@${proguard-dir}/proguard.cfg"/>
<arg value="-injars ${unoptimized}"/>
<arg value="-outjars ${optimized}"/>
<arg value="-libraryjars /Users/decades/android-sdk-mac_x86/platforms/android-7/android.jar"/>
</java>
</target>
Build and obfuscation is fine, but after importing the resulting MyJar_0.0.1.jar into a test project the code completion does not show up the right parameter names, instead foo is presented as
foo(String arg0, long arg1, float arg2, LocationListener arg3)
although "keepparameternames" is specified.
I have spent hours and hours and couldn't make it work. All is fine if I import the unobfuscated JAR. Some other functions in the package do also show up with their correct parameter names...
Having no clue, do you?
Regards
ProGuard 4.7 (and older) appears to remove the names of unused parameters. I've now fixed this for future releases. You can work around it by switching off optimization (-dontoptimize).
Note that you can always report bugs on ProGuard's bug tracker.
来源:https://stackoverflow.com/questions/8656447/weird-behaviour-while-obfuscating-a-jar-with-proguard