Android obfuscate app using proguard keeps obfuscating library jars - or is it? -


i'm new using proguard i'm making newbie mistake. i've got app after run release build (which uses proguard obfuscate) crashes pretty quickly. believe i've narrowed down fact seems obfuscating reference libraries. in case reference libraries used define message classes using communicate device using google protobuffers. building using, ant release. proguard config is:

-optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontpreverify -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*  -keep public class * extends android.app.activity -keep public class * extends android.app.application -keep public class * extends android.app.service -keep public class * extends android.content.broadcastreceiver -keep public class * extends android.content.contentprovider -keep public class * extends android.app.backup.backupagenthelper -keep public class * extends android.preference.preference -keep public class com.android.vending.licensing.ilicensingservice  -keepclasseswithmembernames class *   {     native <methods>;  }  -keepclasseswithmembernames class *   {     public <init>(android.content.context, android.util.attributeset);  }  -keepclasseswithmembernames class *   {     public <init>(android.content.context, android.util.attributeset, int);  }  -keepclassmembers enum *   {     public static **[] values();     public static ** valueof(java.lang.string);  }  -keep class * implements android.os.parcelable   {     public static final android.os.parcelable$creator *;  } 

in ant build.xml file have following defined:

<target name="-obfuscate" unless="do.not.compile">     <if condition="${proguard.enabled}">         <then>             <property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" />             <property name="preobfuscate.jar.file"  value="${obfuscate.absolute.dir}/original.jar" />             <property name="obfuscated.jar.file"    value="${obfuscate.absolute.dir}/obfuscated.jar" />               <!-- input dex proguard's output -->             <property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" />              <!-- add proguard tasks -->             <property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" />             <taskdef name="proguard" classname="proguard.ant.proguardtask" classpath="${proguard.jar}" />              <!-- set android classpath path object single property. it'll                  jar files separated platform path-separator.             -->             <property name="android.libraryjars" refid="android.target.classpath"/>              <!-- build path object jar files must obfuscated.                  include project compiled source code , 3rd party jar                  files.              -->             <path id="project.jars.ref">                 <pathelement location="${preobfuscate.jar.file}" />                 <path refid="jar.libs.ref" />             </path>              <!-- set project jar files path object single property. it'll                  jar files separated platform path-separator.             -->             <property name="project.jars" refid="project.jars.ref" />              <mkdir  dir="${obfuscate.absolute.dir}" />             <delete file="${preobfuscate.jar.file}" />             <delete file="${obfuscated.jar.file}"   />             <jar basedir="${out.classes.dir}" destfile="${preobfuscate.jar.file}" />             <proguard>                 @${proguard.config}                 -injars ${project.jars}                 -outjars ${obfuscated.jar.file}                 -libraryjars ${android.libraryjars}                 -dump ${obfuscate.absolute.dir}/dump.txt                 -printseeds ${obfuscate.absolute.dir}/seeds.txt                 -printusage ${obfuscate.absolute.dir}/usage.txt                 -printmapping ${obfuscate.absolute.dir}/mapping.txt             </proguard>         </then>     </if> </target>  <!-- converts project's .class files .dex files --> <target name="-dex" depends="compile, -post-compile, -obfuscate"         unless="do.not.compile">     <if condition="${manifest.hascode}">         <then>             <dex-helper />         </then>         <else>             <echo>hascode = false. skipping...</echo>         </else>     </if> </target>  <!-- puts project's resources output package file      can create multiple resource package in case      custom apk specific configuration have been      declared in default.properties.      --> <target name="-package-resources">     <echo>packaging resources</echo>     <aapt executable="${aapt}"             command="package"             versioncode="${version.code}"             debug="${build.packaging.debug}"             manifest="androidmanifest.xml"             assets="${asset.absolute.dir}"             androidjar="${android.jar}"             apkfolder="${out.absolute.dir}"             resourcefilename="${resource.package.file.name}"             resourcefilter="${aapt.resource.filter}">         <res path="${resource.absolute.dir}" />         <!-- <nocompress /> forces no compression on files in assets or res/raw -->         <!-- <nocompress extension="xml" /> forces no compression on specific file extensions in assets , res/raw -->     </aapt> </target>  <!-- packages application , sign debug key. --> <target name="-package-debug-sign" depends="-dex, -package-resources">     <package-helper             output.filepath="${out.debug.unaligned.file}" /> </target>  <!-- packages application without signing it. --> <target name="-package-release" depends="-dex, -package-resources">     <package-helper             output.filepath="${out.unsigned.file}"/> </target>     <target name="-set-release-mode">         <!-- release mode valid if manifest not explicitly              set debuggable true. default false.              store build.packaging.debug, not build.release -->         <xpath input="androidmanifest.xml" expression="/manifest/application/@android:debuggable"                output="build.packaging.debug" default="false"/>          <!-- enable proguard -->         <property name="proguard.enabled" value="true"/>         <property name="proguard.config" value="proguard.cfg"/>          <!-- signing mode: release -->         <property name="build.signing.debug" value="false" />          <if condition="${build.packaging.debug}">             <then>                 <echo>*************************************************</echo>                 <echo>****  android manifest has debuggable=true   ****</echo>                 <echo>**** doing debug packaging release keys ****</echo>                 <echo>*************************************************</echo>             </then>             <else>                 <!-- property set in release mode.                      useful if/unless attributes in target node                      when using ant before 1.8 -->                 <property name="build.mode.release" value="true"/>             </else>         </if>     </target>      <target name="release"             depends="-set-release-mode, -release-obfuscation-check, -package-release, -release-prompt-for-password, -release-nosign"                 if="has.keystore"                 description="builds application. generated apk file must signed before                             published.">         <!-- signs apk -->         <echo>signing final apk...</echo>         <signjar                 jar="${out.unsigned.file}"                 signedjar="${out.unaligned.file}"                 keystore="${key.store}"                 storepass="${key.store.password}"                 alias="${key.alias}"                 keypass="${key.alias.password}"                 verbose="${verbose}" />          <!-- zip aligns apk -->         <zipalign-helper in.package="${out.unaligned.file}"                                    out.package="${out.release.file}" />         <echo>release package: ${out.release.file}</echo>     </target> 

i'd appreciate ideas. copied in of build , proguard config online templates, suspect intructing proguard obfuscate library jars or have lisconfigured. seeing following output in cmd window @ end of build:

[proguard] writing output... [proguard] preparing output jar [c:\workspace\ui\myapp\build\proguard\obfuscated.jar] [proguard]   copying resources program jar [c:\workspace\ui\myapp\build\proguard\original.jar] [proguard]   copying resources program jar [c:\workspace\ui\myapp\libs\libmessaging.jar] [proguard] warning: can't write resource [meta-inf/manifest.mf] (duplicate zip entry [libmessaging.jar:meta-inf/manifest.mf]) [proguard]   copying resources program jar [c:\workspace\ui\myapp\libs\protobuf-2.3.0.jar] [proguard] warning: can't write resource [meta-inf/manifest.mf] (duplicate zip entry [protobuf-2.3.0.jar:meta-inf/manifest.mf]) [proguard] printing classes [c:\workspace\riptide1_1_ptr_74\wpg_hawksbill\ui\myapp\build\proguard\dump.txt]... 

thanks!

you have commented library jar directives in proguard config.
change:

# -libraryjars /libs/protobuf-2.3.0.jar # -libraryjars /libs/libmessaging.jar 

to:

-libraryjars /libs/protobuf-2.3.0.jar -libraryjars /libs/libmessaging.jar 

(and don't bother defining library jars in build.xml)

edit:
found way make proguard leave library jars alone ask preserve package names, eg:

-keep class javax.** { *; } -keep class org.** { *; } -keep class twitter4j.** { *; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -