Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid obfuscate app using proguard keeps obfuscating library jars - or is it?
    text
    copied!<p>I'm new to using Proguard so I'm probably making a newbie mistake. I've got an app that after I run the release build (which uses Proguard to obfuscate) it crashes pretty quickly. I believe I've narrowed it down to the fact that it seems like it is obfuscating my reference libraries. In my case my reference libraries are used to define my message classes that I am using to communicate to another device using Google Protobuffers. I am building using, ant release. My proguard config is:</p> <pre><code>-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 &lt;methods&gt;; } -keepclasseswithmembernames class * { public &lt;init&gt;(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembernames class * { public &lt;init&gt;(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 *; } </code></pre> <p>In my ant build.xml file I have the following defined:</p> <pre><code>&lt;target name="-obfuscate" unless="do.not.compile"&gt; &lt;if condition="${proguard.enabled}"&gt; &lt;then&gt; &lt;property name="obfuscate.absolute.dir" location="${out.absolute.dir}/proguard" /&gt; &lt;property name="preobfuscate.jar.file" value="${obfuscate.absolute.dir}/original.jar" /&gt; &lt;property name="obfuscated.jar.file" value="${obfuscate.absolute.dir}/obfuscated.jar" /&gt; &lt;!-- input for dex will be proguard's output --&gt; &lt;property name="out.dex.input.absolute.dir" value="${obfuscated.jar.file}" /&gt; &lt;!-- Add Proguard Tasks --&gt; &lt;property name="proguard.jar" location="${android.tools.dir}/proguard/lib/proguard.jar" /&gt; &lt;taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="${proguard.jar}" /&gt; &lt;!-- Set the android classpath Path object into a single property. It'll be all the jar files separated by a platform path-separator. --&gt; &lt;property name="android.libraryjars" refid="android.target.classpath"/&gt; &lt;!-- Build a path object with all the jar files that must be obfuscated. This include the project compiled source code and any 3rd party jar files. --&gt; &lt;path id="project.jars.ref"&gt; &lt;pathelement location="${preobfuscate.jar.file}" /&gt; &lt;path refid="jar.libs.ref" /&gt; &lt;/path&gt; &lt;!-- Set the project jar files Path object into a single property. It'll be all the jar files separated by a platform path-separator. --&gt; &lt;property name="project.jars" refid="project.jars.ref" /&gt; &lt;mkdir dir="${obfuscate.absolute.dir}" /&gt; &lt;delete file="${preobfuscate.jar.file}" /&gt; &lt;delete file="${obfuscated.jar.file}" /&gt; &lt;jar basedir="${out.classes.dir}" destfile="${preobfuscate.jar.file}" /&gt; &lt;proguard&gt; @${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 &lt;/proguard&gt; &lt;/then&gt; &lt;/if&gt; &lt;/target&gt; &lt;!-- Converts this project's .class files into .dex files --&gt; &lt;target name="-dex" depends="compile, -post-compile, -obfuscate" unless="do.not.compile"&gt; &lt;if condition="${manifest.hasCode}"&gt; &lt;then&gt; &lt;dex-helper /&gt; &lt;/then&gt; &lt;else&gt; &lt;echo&gt;hasCode = false. Skipping...&lt;/echo&gt; &lt;/else&gt; &lt;/if&gt; &lt;/target&gt; &lt;!-- Puts the project's resources into the output package file This actually can create multiple resource package in case Some custom apk with specific configuration have been declared in default.properties. --&gt; &lt;target name="-package-resources"&gt; &lt;echo&gt;Packaging resources&lt;/echo&gt; &lt;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}"&gt; &lt;res path="${resource.absolute.dir}" /&gt; &lt;!-- &lt;nocompress /&gt; forces no compression on any files in assets or res/raw --&gt; &lt;!-- &lt;nocompress extension="xml" /&gt; forces no compression on specific file extensions in assets and res/raw --&gt; &lt;/aapt&gt; &lt;/target&gt; &lt;!-- Packages the application and sign it with a debug key. --&gt; &lt;target name="-package-debug-sign" depends="-dex, -package-resources"&gt; &lt;package-helper output.filepath="${out.debug.unaligned.file}" /&gt; &lt;/target&gt; &lt;!-- Packages the application without signing it. --&gt; &lt;target name="-package-release" depends="-dex, -package-resources"&gt; &lt;package-helper output.filepath="${out.unsigned.file}"/&gt; &lt;/target&gt; &lt;target name="-set-release-mode"&gt; &lt;!-- release mode is only valid if the manifest does not explicitly set debuggable to true. default is false. We actually store build.packaging.debug, not build.release --&gt; &lt;xpath input="AndroidManifest.xml" expression="/manifest/application/@android:debuggable" output="build.packaging.debug" default="false"/&gt; &lt;!-- Enable proguard --&gt; &lt;property name="proguard.enabled" value="true"/&gt; &lt;property name="proguard.config" value="proguard.cfg"/&gt; &lt;!-- signing mode: release --&gt; &lt;property name="build.signing.debug" value="false" /&gt; &lt;if condition="${build.packaging.debug}"&gt; &lt;then&gt; &lt;echo&gt;*************************************************&lt;/echo&gt; &lt;echo&gt;**** Android Manifest has debuggable=true ****&lt;/echo&gt; &lt;echo&gt;**** Doing DEBUG packaging with RELEASE keys ****&lt;/echo&gt; &lt;echo&gt;*************************************************&lt;/echo&gt; &lt;/then&gt; &lt;else&gt; &lt;!-- property only set in release mode. Useful for if/unless attributes in target node when using Ant before 1.8 --&gt; &lt;property name="build.mode.release" value="true"/&gt; &lt;/else&gt; &lt;/if&gt; &lt;/target&gt; &lt;target name="release" depends="-set-release-mode, -release-obfuscation-check, -package-release, -release-prompt-for-password, -release-nosign" if="has.keystore" description="Builds the application. The generated apk file must be signed before it is published."&gt; &lt;!-- Signs the APK --&gt; &lt;echo&gt;Signing final apk...&lt;/echo&gt; &lt;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}" /&gt; &lt;!-- Zip aligns the APK --&gt; &lt;zipalign-helper in.package="${out.unaligned.file}" out.package="${out.release.file}" /&gt; &lt;echo&gt;Release Package: ${out.release.file}&lt;/echo&gt; &lt;/target&gt; </code></pre> <p>I'd appreciate any ideas. I copied in most of my build and proguard config from online templates, I suspect that I am actually intructing Proguard to obfuscate the library jars or I have something lisconfigured. I am seeing the following output in my cmd window at the end of the build:</p> <pre><code>[proguard] Writing output... [proguard] Preparing output jar [C:\Workspace\UI\MyApp\build\proguard\obfuscated.jar] [proguard] Copying resources from program jar [C:\Workspace\UI\MyApp\build\proguard\original.jar] [proguard] Copying resources from 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 from 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 to [C:\Workspace\Riptide1_1_ptr_74\WPG_HAWKSBILL\UI\MyApp\build\proguard\dump.txt]... </code></pre> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload