1b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 2b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<html> 3b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<head> 4b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> 5b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<meta http-equiv="content-style-type" content="text/css"> 6b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<link rel="stylesheet" type="text/css" href="style.css"> 7b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<title>ProGuard Examples</title> 8b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<script type="text/javascript" language="JavaScript"> 9b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<!-- 10b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangif (window.self==window.top) 11b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang window.top.location.replace("/index.html#"+window.location.pathname+window.location.hash); 12b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangelse { 13b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang var hash="#"+window.location.pathname.replace(window.top.location.pathname.replace("index.html", ""), ""); 14b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (window.top.location.hash!=hash) 15b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang window.top.location.hash=hash; 16b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 17b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang//--> 18b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</script> 19b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</head> 20b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<body> 21b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 22b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<h2>Examples</h2> 23b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 24b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoSome typical useful configurations: 25b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<ol> 26b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#application">A typical application</a></li> 27b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#applet">A typical applet</a></li> 28b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#midlet">A typical midlet</a></li> 29b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#jcapplet">A typical Java Card applet</a></li> 30b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#xlet">A typical xlet</a></li> 31b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#androidactivity">A simple Android activity</a></li> 32b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#androidapplication">A complete Android application</a></li> 33b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#library">A typical library</a></li> 34b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#applications">All possible applications in the input jars</a></li> 35b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#applets">All possible applets in the input jars</a></li> 36b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#midlets">All possible midlets in the input jars</a></li> 37b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#jcapplets">All possible Java Card applets in the input jars</a></li> 38b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#xlets">All possible xlets in the input jars</a></li> 39b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#servlets">All possible servlets in the input jars</a></li> 40b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#scala">Scala applications with the Scala runtime</a></li> 41b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#native">Processing native methods</a></li> 42b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#callback">Processing callback methods</a></li> 43b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#enumerations">Processing enumeration classes</a></li> 44b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#serializable">Processing serializable classes</a></li> 45b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#beans">Processing bean classes</a></li> 46b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#annotations">Processing annotations</a></li> 47b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#database">Processing database drivers</a></li> 48b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#componentui">Processing ComponentUI classes</a></li> 49b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#rmi">Processing RMI code</a></li> 50b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#injection">Processing resource injection</a></li> 51b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#resourcefiles">Processing resource files</a></li> 52b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#manifestfiles">Processing manifest files</a></li> 53b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#stacktrace">Producing useful obfuscated stack traces</a></li> 54b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#repackaging">Obfuscating package names</a></li> 55b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#logging">Removing logging code</a></li> 56b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#restructuring">Restructuring the output archives</a></li> 57b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#filtering">Filtering the input and the output</a></li> 58b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#multiple">Processing multiple applications at once</a></li> 59b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#incremental">Incremental obfuscation</a></li> 60b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#microedition">Preverifying class files for Java Micro Edition</a></li> 61b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#upgrade">Upgrading class files to Java 6</a></li> 62b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#deadcode">Finding dead code</a></li> 63b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#structure">Printing out the internal structure of class files</a></li> 64b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li><a href="#annotated">Using annotations to configure ProGuard</a></li> 65b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</ol> 66b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 67b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoYou can find some sample configuration files in the <code>examples</code> 68b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratodirectory of the ProGuard distribution. 69b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 70b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="application">A typical application</a></h3> 71b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 72b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangTo shrink, optimize, and obfuscate a simple Java application, you typically 73b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangcreate a configuration file like <code>myconfig.pro</code>, which can be used 74b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangwith 75b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 76b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangbin/proguard @myconfig.pro 77b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 78b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 79b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe configuration file specifies the input, the output, and the entry points 80b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangof the application: 81b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 82b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars myapplication.jar 83b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-outjars myapplication_out.jar 84b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 85b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-printmapping myapplication.map 86b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 87b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public class mypackage.MyMain { 88b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static void main(java.lang.String[]); 89b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 90b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 91b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 92b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangNote the use of the <code><java.home></code> system property. ProGuard 93b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangautomatically replaces it when parsing the file. 94b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 95b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe <a href="usage.html#keep"><code>-keep</code></a> option specifies the 96b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangentry point of the application that has to be preserved. 97b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe access modifiers <code>public</code> and <code>static</code> are not 98b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoreally required in this case, since we know a priori that the specified class 99b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoand method have the proper access flags. It just looks more familiar this way. 100b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 101b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangNote that all type names are fully specified: 102b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<code>mypackage.MyMain</code> and <code>java.lang.String[]</code>. 103b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 104b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're writing out an obfuscation mapping file with <a 105b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#printmapping"><code>-printmapping</code></a>, for 106b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratode-obfuscating any stack traces later on, or for incremental obfuscation of 107b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoextensions. 108b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 109b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe can further improve the results with a few additional options: 110b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 111b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-optimizationpasses 3 112b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-overloadaggressively 113b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 114b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 115b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 116b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options are not required; they just shave off some extra bytes from the 117b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooutput jar, by performing up to 3 optimization passes, and by aggressively 118b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoobfuscating class members and <a href="#repackaging">package names</a>. 119b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 120b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIn general, you might need a few additional options for processing <a 121b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#native">native methods</a>, <a href="#callback">callback methods</a>, 122b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<a href="#enumerations">enumerations</a>, <a href="#serializable">serializable 123b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses</a>, <a href="#beans">bean classes</a>, <a 124b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#annotations">annotations</a>, and <a href="#resourcefiles">resource 125b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfiles</a>. 126b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 127b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="applet">A typical applet</a></h3> 128b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 129b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate the applet 130b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>mypackage.MyApplet</code>: 131b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 132b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 133b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 134b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 135b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 136b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyApplet 137b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 138b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 139b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe typical applet methods will be preserved automatically, since 140b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>mypackage.MyApplet</code> is an extension of the <code>Applet</code> 141b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclass in the library <code>rt.jar</code>. 142b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 143b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf applicable, you should add options for processing <a href="#native">native 144b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a>, <a href="#callback">callback methods</a>, <a 145b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#enumerations">enumerations</a>, <a href="#serializable">serializable 146b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses</a>, <a href="#beans">bean classes</a>, <a 147b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#annotations">annotations</a>, and <a href="#resourcefiles">resource 148b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratofiles</a>. 149b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 150b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="midlet">A typical midlet</a></h3> 151b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 152b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, obfuscate, and preverify the midlet 153b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>mypackage.MyMIDlet</code>: 154b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 155b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 156b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 157b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/wtk2.5.2/lib/midpapi20.jar 158b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/wtk2.5.2/lib/cldcapi11.jar 159b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-overloadaggressively 160b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 161b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 162b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-microedition 163b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 164b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyMIDlet 165b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 166b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 167b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote how we're now targeting the Java Micro Edition run-time environment of 168b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>midpapi20.jar</code> and <code>cldcapi11.jar</code>, instead of the Java 169b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoStandard Edition run-time environment <code>rt.jar</code>. You can target 170b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoother JME environments by picking the appropriate jars. 171b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 172b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe typical midlet methods will be preserved automatically, since 173b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>mypackage.MyMIDlet</code> is an extension of the <code>MIDlet</code> 174b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclass in the library <code>midpapi20.jar</code>. 175b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 176b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#microedition"><code>-microedition</code></a> option 177b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomakes sure the class files are preverified for Java Micro Edition, producing 178b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocompact <code>StackMap</code> attributes. It is no longer necessary to run an 179b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoexternal preverifier. 180b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 181b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoBe careful if you do use the external <code>preverify</code> tool on a platform 182b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratowith a case-insensitive filing system, such as Windows. Because this tool 183b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratounpacks your processed jars, you should then use ProGuard's <a 184b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#dontusemixedcaseclassnames"><code>-dontusemixedcaseclassnames</code></a> 185b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooption. 186b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 187b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf applicable, you should add options for processing <a href="#native">native 188b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a> and <a href="#resourcefiles">resource files</a>. 189b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 190b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote that you will still have to adapt the midlet jar size in the 191b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocorresponding jad file; ProGuard doesn't do that for you. 192b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 193b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="jcapplet">A typical Java Card applet</a></h3> 194b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 195b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate the Java Card applet 196b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>mypackage.MyApplet</code>: 197b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 198b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 199b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 200b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/javacard2.2.2/lib/api.jar 201b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontwarn java.lang.Class 202b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-overloadaggressively 203b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 204b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 205b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 206b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyApplet 207b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 208b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 209b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe configuration is very similar to the configuration for midlets, except that 210b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoit now targets the Java Card run-time environment. This environment doesn't 211b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohave java.lang.Class, so we're telling ProGuard not to worry about it. 212b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 213b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="xlet">A typical xlet</a></h3> 214b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 215b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate the xlet 216b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>mypackage.MyXlet</code>: 217b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 218b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 219b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 220b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/jtv1.1/javatv.jar 221b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/cdc1.1/lib/cdc.jar 222b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/cdc1.1/lib/btclasses.zip 223b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-overloadaggressively 224b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 225b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 226b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 227b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyXlet 228b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 229b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 230b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe configuration is very similar to the configuration for midlets, except that 231b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoit now targets the CDC run-time environment with the Java TV API. 232b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 233b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="androidactivity">A simple Android activity</a></h3> 234b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 235b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThese options shrink, optimize, and obfuscate the single Android 236b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangactivity <code>mypackage.MyActivity</code>: 237b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 238b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars bin/classes 239b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-outjars bin/classes-processed.jar 240b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar 241b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 242b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-dontpreverify 243b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 244b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 245b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-optimizations !code/simplification/arithmetic 246b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 247b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyActivity 248b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 249b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 250b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangWe're targeting the Android run-time and keeping the activity as an entry 251b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangpoint. 252b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 253b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangPreverification is irrelevant for the dex compiler and the Dalvik VM, so we 254b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangcan switch it off with the 255b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<a href="usage.html#dontpreverify"><code>-dontpreverify</code></a> option. 256b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 257b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#optimizations"><code>-optimizations</code></a> option 258b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratodisables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. 259b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangNote that the Dalvik VM also can't 260b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wanghandle <a href="usage.html#overloadaggressively">aggressive overloading</a> 261b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang(of static fields). 262b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 263b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf applicable, you should add options for processing <a href="#native">native 264b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangmethods</a>, <a href="#callback">callback methods</a>, 265b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<a href="#enumerations">enumerations</a>, 266b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<a href="#annotations">annotations</a>, and 267b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<a href="#resourcefiles">resource files</a>. 268b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 269b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="androidapplication">A complete Android application</a></h3> 270b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 271b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<img class="float" src="attention.gif" width="64" height="64" alt="attention" /> 272b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe Ant and Eclipse build processes of the Android SDK already integrate 273b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangProGuard by default, with all the proper settings. You only need to enable 274b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangProGuard (for release builds), by uncommenting the line 275b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang"<code>proguard.config=.....</code>" in the file 276b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<code>project.properties</code> (created or updated by Android SDK revision 17 277b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangor higher). Notes: 278b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<ul> 279b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li>In case of problems, you may want to check if the configuration files that 280b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang are listed on this line (<code>proguard-project.txt</code>,...) contain 281b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang the necessary settings for your application.</li> 282b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li>Android SDK revision 20 and higher have a different configuration file for 283b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang enabling optimization: 284b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang <code>${sdk.dir}/tools/proguard/proguard-android-optimize.txt</code> 285b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang instead of the default 286b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang <code>${sdk.dir}/tools/proguard/proguard-android.txt</code>.</li> 287b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li>The build processes are already setting the necessary program jars, 288b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang library jars, and output jars for you — don't specify them again.</li> 289b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<li>If you get warnings about missing referenced classes: it's all too common 290b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang that libraries refer to missing classes. 291b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang See <a href="troubleshooting.html#unresolvedclass">"Warning: can't find 292b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang referenced class"</a> in the Troubleshooting section.</li> 293b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</ul> 294b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 295b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangFor more information, you can consult the official <a target="other" 296b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wanghref="http://developer.android.com/guide/developing/tools/proguard.html">Developer 297b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangGuide</a> in the Android SDK. 298b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 299b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf you're constructing a build process from scratch: these options shrink, 300b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangoptimize, and obfuscate all public activities, services, broadcast receivers, 301b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangand content providers from the compiled classes and external libraries: 302b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 303b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars bin/classes 304b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars libs 305b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-outjars bin/classes-processed.jar 306b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/android-sdk/platforms/android-9/android.jar 307b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 308b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-dontpreverify 309b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-repackageclasses '' 310b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-allowaccessmodification 311b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-optimizations !code/simplification/arithmetic 312b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepattributes *Annotation* 313b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 314b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public class * extends android.app.Activity 315b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public class * extends android.app.Application 316b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public class * extends android.app.Service 317b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public class * extends android.content.BroadcastReceiver 318b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public class * extends android.content.ContentProvider 319b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 320b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public class * extends android.view.View { 321b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public <init>(android.content.Context); 322b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public <init>(android.content.Context, android.util.AttributeSet); 323b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public <init>(android.content.Context, android.util.AttributeSet, int); 324b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void set*(...); 325b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 326b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 327b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclasseswithmembers class * { 328b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public <init>(android.content.Context, android.util.AttributeSet); 329b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 330b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 331b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclasseswithmembers class * { 332b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public <init>(android.content.Context, android.util.AttributeSet, int); 333b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 334b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 335b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembers class * extends android.content.Context { 336b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void *(android.view.View); 337b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void *(android.view.MenuItem); 338b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 339b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 340b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembers class * implements android.os.Parcelable { 341b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang static android.os.Parcelable$Creator CREATOR; 342b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 343b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 344b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembers class **.R$* { 345b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static <fields>; 346b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 347b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 348b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembers class * { 349b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang @android.webkit.JavascriptInterface <methods>; 350b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 351b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 352b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 353b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangMost importantly, we're keeping all fundamental classes that may be referenced 354b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangby the <code>AndroidManifest.xml</code> file of the application. If your 355b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangmanifest file contains other classes and methods, you may have to specify 356b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangthose as well. 357b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 358b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangWe're keeping annotations, since they might be used by custom 359b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<code>RemoteViews</code>. 360b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 361b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangWe're keeping any custom <code>View</code> extensions and other classes with 362b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangtypical constructors, since they might be referenced from XML layout files. 363b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 364b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangWe're also keeping possible <code>onClick</code> handlers in 365b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangcustom <code>Context</code> extensions, since they might be referenced from 366b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangXML layout files. 367b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 368b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangWe're also keeping the required static fields in <code>Parcelable</code> 369b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimplementations, since they are accessed by introspection. 370b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 371b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangWe're keeping the static fields of referenced inner classes of auto-generated 372b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang <code>R</code> classes, just in case your code is accessing those fields by 373b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangintrospection. Note that the compiler already inlines primitive fields, so 374b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangProGuard can generally remove all these classes entirely anyway (because the 375b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangclasses are not referenced and therefore not required). 376b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 377b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangFinally, we're keeping annotated Javascript interface methods, so they can be 378b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangexported and accessed by their original names. Javascript interface methods 379b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangthat are not annotated (in code targeted at Android versions older than 4.2) 380b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangstill need to be preserved manually. 381b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 382b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf you're using additional Google APIs, you'll have to specify 383b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangthose as well, for instance: 384b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 385b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/android-sdk/add-ons/google_apis-7_r01/libs/maps.jar 386b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 387b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 388b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf you're using Google's optional License Verification Library, you can 389b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangobfuscate its code along with your own code. You do have to preserve 390b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangits <code>ILicensingService</code> interface for the library to work: 391b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 392b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep public interface com.android.vending.licensing.ILicensingService 393b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 394b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 395b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf you're using the Android Compatibility library, you should add the 396b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfollowing line, to let ProGuard know it's ok that the library references some 397b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangclasses that are not available in all versions of the API: 398b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 399b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-dontwarn android.support.** 400b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 401b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 402b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf applicable, you should add options for processing <a href="#native">native 403b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangmethods</a>, <a href="#callback">callback methods</a>, 404b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<a href="#enumerations">enumerations</a>, 405b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangand <a href="#resourcefiles">resource files</a>. You may also want to add 406b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangoptions for producing <a href="#stacktrace">useful stack traces</a> and 407b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangto <a href="#logging">remove logging</a>. You can find a complete sample 408b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangconfiguration in <code>examples/android.pro</code> in the ProGuard 409b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangdistribution. 410b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 411b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="library">A typical library</a></h3> 412b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 413b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate an entire library, keeping all 414b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopublic and protected classes and class members, native method names, and 415b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangserialization code. The processed version of the library can then still be 416b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangused as such, for developing code based on its public API. 417b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 418b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 419b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 420b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 421b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printmapping out.map 422b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 423b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepparameternames 424b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-renamesourcefileattribute SourceFile 425b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepattributes Exceptions,InnerClasses,Signature,Deprecated, 426b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato SourceFile,LineNumberTable,*Annotation*,EnclosingMethod 427b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 428b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class * { 429b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public protected *; 430b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 431b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 432b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembernames class * { 433b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Class class$(java.lang.String); 434b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Class class$(java.lang.String, boolean); 435b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 436b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 437b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclasseswithmembernames class * { 438b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato native <methods>; 439b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 440b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 441b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembers enum * { 442b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static **[] values(); 443b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static ** valueOf(java.lang.String); 444b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 445b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 446b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembers class * implements java.io.Serializable { 447b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato static final long serialVersionUID; 448b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private static final java.io.ObjectStreamField[] serialPersistentFields; 449b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void writeObject(java.io.ObjectOutputStream); 450b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void readObject(java.io.ObjectInputStream); 451b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object writeReplace(); 452b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object readResolve(); 453b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 454b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 455b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 456b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis configuration should preserve everything we'll ever want to access in the 457b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratolibrary. Only if there are any other non-public classes or methods that are 458b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoinvoked dynamically, they should be specified using additional <a 459b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#keep"><code>-keep</code></a> options. 460b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 461b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a 462b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#keepclassmembernames"><code>-keepclassmembernames</code></a> 463b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooption for the <code>class$</code> methods is not strictly necessary. These 464b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods are inserted by the <code>javac</code> compiler and the 465b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<code>jikes</code> compiler respectively, in JDK 1.2 and older, to implement 466b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangthe <code>.class</code> construct. ProGuard will automatically detect them and 467b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangdeal with them, even when their names have been obfuscated. However, other 468b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangobfuscators may rely on the original method names. It may therefore be helpful 469b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangto preserve them, in case these other obfuscators are ever used for further 470b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangobfuscation of the library. 471b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 472b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe "Exceptions" attribute has to be preserved, so the compiler knows which 473b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoexceptions methods may throw. 474b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 475b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe "InnerClasses" attribute (or more precisely, its source name part) has to 476b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratobe preserved too, for any inner classes that can be referenced from outside the 477b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratolibrary. The <code>javac</code> compiler would be unable to find the inner 478b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses otherwise. 479b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 480b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe "Signature" attribute is required to be able to access generic types when 481b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocompiling in JDK 5.0 and higher. 482b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 483b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe <a href="usage.html#keepparameternames"><code>-keepparameternames</code></a> 484b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangoption keeps the parameter names in the "LocalVariableTable" and 485b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang"LocalVariableTypeTable" attributes of public library methods. Some IDEs can 486b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangpresent these names to the developers who use the library. 487b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 488b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoFinally, we're keeping the "Deprecated" attribute and the attributes for 489b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoproducing <a href="#stacktrace">useful stack traces</a>. 490b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 491b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe've also added some options for for processing <a href="#native">native 492b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a>, <a href="#enumerations">enumerations</a>, <a 493b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#serializable">serializable classes</a>, and <a 494b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#annotations">annotations</a>, which are all discussed in their 495b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratorespective examples. 496b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 497b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="applications">All possible applications in the input jars</a></h3> 498b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 499b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate all public applications in 500b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>in.jar</code>: 501b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 502b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 503b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 504b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 505b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printseeds 506b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 507b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclasseswithmembers public class * { 508b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static void main(java.lang.String[]); 509b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 510b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 511b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 512b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote the use of <a 513b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#keepclasseswithmembers"><code>-keepclasseswithmembers</code></a>. 514b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe don't want to preserve all classes, just all classes that have main 515b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods, and those methods. 516b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 517b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 518b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoout which classes exactly will be preserved, so we know for sure we're getting 519b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratowhat we want. 520b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 521b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf applicable, you should add options for processing <a href="#native">native 522b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a>, <a href="#callback">callback methods</a>, <a 523b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#enumerations">enumerations</a>, <a href="#serializable">serializable 524b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses</a>, <a href="#beans">bean classes</a>, <a 525b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#annotations">annotations</a>, and <a href="#resourcefiles">resource 526b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratofiles</a>. 527b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 528b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="applets">All possible applets in the input jars</a></h3> 529b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 530b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate all public applets in 531b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>in.jar</code>: 532b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 533b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 534b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 535b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 536b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printseeds 537b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 538b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class * extends java.applet.Applet 539b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 540b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 541b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're simply keeping all classes that extend the <code>Applet</code> class. 542b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 543b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoAgain, the <a href="usage.html#printseeds"><code>-printseeds</code></a> option 544b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoprints out which applets exactly will be preserved. 545b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 546b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf applicable, you should add options for processing <a href="#native">native 547b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a>, <a href="#callback">callback methods</a>, <a 548b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#enumerations">enumerations</a>, <a href="#serializable">serializable 549b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses</a>, <a href="#beans">bean classes</a>, <a 550b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#annotations">annotations</a>, and <a href="#resourcefiles">resource 551b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratofiles</a>. 552b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 553b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="midlets">All possible midlets in the input jars</a></h3> 554b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 555b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, obfuscate, and preverify all public midlets in 556b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>in.jar</code>: 557b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 558b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 559b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 560b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/wtk2.5.2/lib/midpapi20.jar 561b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/wtk2.5.2/lib/cldcapi11.jar 562b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-overloadaggressively 563b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 564b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 565b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-microedition 566b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printseeds 567b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 568b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class * extends javax.microedition.midlet.MIDlet 569b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 570b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 571b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're simply keeping all classes that extend the <code>MIDlet</code> class. 572b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 573b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#microedition"><code>-microedition</code></a> option 574b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomakes sure the class files are preverified for Java Micro Edition, producing 575b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocompact <code>StackMap</code> attributes. It is no longer necessary to run an 576b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoexternal preverifier. 577b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 578b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoBe careful if you do use the external <code>preverify</code> tool on a platform 579b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratowith a case-insensitive filing system, such as Windows. Because this tool 580b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratounpacks your processed jars, you should then use ProGuard's <a 581b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#dontusemixedcaseclassnames"><code>-dontusemixedcaseclassnames</code></a> 582b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooption. 583b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 584b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 585b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoout which midlets exactly will be preserved. 586b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 587b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf applicable, you should add options for processing <a href="#native">native 588b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a> and <a href="#resourcefiles">resource files</a>. 589b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 590b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote that you will still have to adapt the midlet jar size in the 591b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocorresponding jad file; ProGuard doesn't do that for you. 592b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 593b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="jcapplets">All possible Java Card applets in the input jars</a></h3> 594b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 595b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate all public Java Card applets in 596b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>in.jar</code>: 597b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 598b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 599b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 600b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/javacard2.2.2/lib/api.jar 601b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontwarn java.lang.Class 602b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-overloadaggressively 603b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 604b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 605b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printseeds 606b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 607b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class * implements javacard.framework.Applet 608b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 609b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 610b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're simply keeping all classes that implement the <code>Applet</code> 611b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratointerface. 612b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 613b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 614b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoout which applets exactly will be preserved. 615b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 616b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="xlets">All possible xlets in the input jars</a></h3> 617b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 618b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate all public xlets in 619b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>in.jar</code>: 620b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 621b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 622b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 623b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/jtv1.1/javatv.jar 624b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/cdc1.1/lib/cdc.jar 625b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/cdc1.1/lib/btclasses.zip 626b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-overloadaggressively 627b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 628b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 629b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printseeds 630b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 631b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class * implements javax.tv.xlet.Xlet 632b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 633b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 634b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're simply keeping all classes that implement the <code>Xlet</code> interface. 635b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 636b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 637b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoout which xlets exactly will be preserved. 638b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 639b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="servlets">All possible servlets in the input jars</a></h3> 6409f606f95f03a75961498803e24bee6799a7c0885Ying Wang 641b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options shrink, optimize, and obfuscate all public servlets in 642b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>in.jar</code>: 643b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 644b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 645b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 646b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 647b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars /usr/local/java/servlet/servlet.jar 648b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printseeds 649b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 650b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class * implements javax.servlet.Servlet 651b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 652b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 653b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoKeeping all servlets is very similar to keeping all applets. The servlet API 654b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratois not part of the standard run-time jar, so we're specifying it as a library. 655b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoDon't forget to use the right path name. 656b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 657b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're then keeping all classes that implement the <code>Servlet</code> 658b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratointerface. We're using the <code>implements</code> keyword because it looks 659b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomore familiar in this context, but it is equivalent to <code>extends</code>, 660b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoas far as ProGuard is concerned. 661b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 662b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#printseeds"><code>-printseeds</code></a> option prints 663b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoout which servlets exactly will be preserved. 664b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 665b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf applicable, you should add options for processing <a href="#native">native 666b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a>, <a href="#callback">callback methods</a>, <a 667b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#enumerations">enumerations</a>, <a href="#serializable">serializable 668b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses</a>, <a href="#beans">bean classes</a>, <a 669b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#annotations">annotations</a>, and <a href="#resourcefiles">resource 670b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratofiles</a>. 671b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 672b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="scala">Scala applications with the Scala runtime</a></h3> 673b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 674b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThese options shrink, optimize, and obfuscate all public Scala applications in 675b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<code>in.jar</code>: 676b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 677b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars in.jar 678b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars /usr/local/java/scala-2.9.1/lib/scala-library.jar 679b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-outjars out.jar 680b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars <java.home>/lib/rt.jar 681b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 682b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-dontwarn scala.** 683b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 684b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclasseswithmembers public class * { 685b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static void main(java.lang.String[]); 686b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 687b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 688b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keep class * implements org.xml.sax.EntityResolver 689b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 690b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembers class * { 691b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang ** MODULE$; 692b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 693b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 694b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinPool { 695b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang long eventCount; 696b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int workerCounts; 697b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int runControl; 698b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang scala.concurrent.forkjoin.ForkJoinPool$WaitQueueNode syncStack; 699b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang scala.concurrent.forkjoin.ForkJoinPool$WaitQueueNode spareStack; 700b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 701b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 702b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinWorkerThread { 703b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int base; 704b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int sp; 705b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int runState; 706b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 707b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 708b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembernames class scala.concurrent.forkjoin.ForkJoinTask { 709b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int status; 710b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 711b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 712b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembernames class scala.concurrent.forkjoin.LinkedTransferQueue { 713b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference head; 714b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference tail; 715b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang scala.concurrent.forkjoin.LinkedTransferQueue$PaddedAtomicReference cleanMe; 716b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 717b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 718b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 719b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe configuration is essentially the same as 720b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfor <a href="#applications">processing applications</a>, because Scala is 721b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangcompiled to ordinary Java bytecode. However, the example processes the Scala 722b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangruntime library as well. The processed jar can be an order of magnitude 723b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangsmaller and a few times faster than the original code (for the Scala code 724b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangexamples, for instance). 725b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 726b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe <a href="usage.html#dontwarn"><code>-dontwarn</code></a> option tells 727b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangProGuard not to complain about some artefacts in the Scala runtime, the way it 728b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangis compiled by the <code>scalac</code> compiler (at least in Scala 2.9.1 and 729b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangolder). Note that this option should always be used with care. 730b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 731b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe additional <a href="usage.html#keepoverview"><code>-keep</code></a> 732b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangoptions make sure that some classes and some fields that are accessed by means 733b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangof introspection are not removed or renamed. 734b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 735b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf applicable, you should add options for processing <a href="#native">native 736b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangmethods</a>, <a href="#callback">callback methods</a>, <a 737b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wanghref="#enumerations">enumerations</a>, <a href="#serializable">serializable 738b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangclasses</a>, <a href="#beans">bean classes</a>, <a 739b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wanghref="#annotations">annotations</a>, and <a href="#resourcefiles">resource 740b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfiles</a>. 741b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="native">Processing native methods</a></h3> 742b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 743b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf your application, applet, servlet, library, etc., contains native methods, 744b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoyou'll want to preserve their names and their classes' names, so they can 745b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratostill be linked to the native library. The following additional option will 746b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoensure that: 747b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 748b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclasseswithmembernames class * { 749b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato native <methods>; 750b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 751b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 752b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 753b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote the use of <a 754b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#keepclasseswithmembernames"><code>-keepclasseswithmembernames</code></a>. 755b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe don't want to preserve all classes or all native methods; we just want to 756b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratokeep the relevant names from being obfuscated. 757b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 758b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoProGuard doesn't look at your native code, so it won't automatically preserve 759b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothe classes or class members that are invoked by the native code. These are 760b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoentry points, which you'll have to specify explicitly. <a 761b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="callback">Callback methods</a> are discussed below as a typical example. 762b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 763b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="callback">Processing callback methods</a></h3> 764b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 765b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf your application, applet, servlet, library, etc., contains callback 766b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods, which are called from external code (native code, scripts,...), 767b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoyou'll want to preserve them, and probably their classes too. They are just 768b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoentry points to your code, much like, say, the main method of an application. 769b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf they aren't preserved by other <code>-keep</code> options, something like 770b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothe following option will keep the callback class and method: 771b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 772b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep class mypackage.MyCallbackClass { 773b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato void myCallbackMethod(java.lang.String); 774b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 775b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 776b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 777b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis will preserve the given class and method from being removed or renamed. 778b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 779b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="enumerations">Processing enumeration classes</a></h3> 780b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 781b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf your application, applet, servlet, library, etc., contains enumeration 782b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses, you'll have to preserve some special methods. Enumerations were 783b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratointroduced in Java 5. The java compiler translates enumerations into classes 784b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratowith a special structure. Notably, the classes contain implementations of some 785b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratostatic methods that the run-time environment accesses by introspection (Isn't 786b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothat just grand? Introspection is the self-modifying code of a new 787b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratogeneration). You have to specify these explicitly, to make sure they aren't 788b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoremoved or obfuscated: 789b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 790b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembers enum * { 791b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static **[] values(); 792b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static ** valueOf(java.lang.String); 793b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 794b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 795b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 796b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="serializable">Processing serializable classes</a></h3> 797b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 798b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoMore complex applications, applets, servlets, libraries, etc., may contain 799b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclasses that are serialized. Depending on the way in which they are used, they 800b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomay require special attention: 801b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<ul> 802b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 803b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<li>Often, serialization is simply a means of transporting data, without 804b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato long-term storage. Classes that are shrunk and obfuscated should then 805b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato continue to function fine with the following additional options: 806b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 807b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 808b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembers class * implements java.io.Serializable { 809b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private static final java.io.ObjectStreamField[] serialPersistentFields; 810b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void writeObject(java.io.ObjectOutputStream); 811b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void readObject(java.io.ObjectInputStream); 812b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object writeReplace(); 813b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object readResolve(); 814b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 815b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 816b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 817b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 818b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato The <a 819b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato href="usage.html#keepclassmembers"><code>-keepclassmembers</code></a> 820b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato option makes sure that any serialization methods are kept. By using this 821b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato option instead of the basic <code>-keep</code> option, we're not 822b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato forcing preservation of <i>all</i> serializable classes, just preservation 823b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang of the listed members of classes that are actually used.</li> 824b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 825b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<li>Sometimes, the serialized data are stored, and read back later into newer 826b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato versions of the serializable classes. One then has to take care the classes 827b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato remain compatible with their unprocessed versions and with future 828b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato processed versions. In such cases, the relevant classes will most likely 829b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato have <code>serialVersionUID</code> fields. The following options should 830b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato then be sufficient to ensure compatibility over time: 831b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 832b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 833b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepnames class * implements java.io.Serializable 834b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 835b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembers class * implements java.io.Serializable { 836b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato static final long serialVersionUID; 837b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private static final java.io.ObjectStreamField[] serialPersistentFields; 838b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato !static !transient <fields>; 839b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void writeObject(java.io.ObjectOutputStream); 840b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void readObject(java.io.ObjectInputStream); 841b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object writeReplace(); 842b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object readResolve(); 843b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 844b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 845b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 846b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 847b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato The <code>serialVersionUID</code> and <code>serialPersistentFields</code> 848b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato lines makes sure those fields are preserved, if they are present. 849b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato The <code><fields></code> line preserves all non-static, 850b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato non-transient fields, with their original names. The introspection of the 851b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato serialization process and the de-serialization process will then find 852b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang consistent names.</li> 853b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 854b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<li>Occasionally, the serialized data have to remain compatible, but the 855b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato classes involved lack <code>serialVersionUID</code> fields. I imagine the 856b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato original code will then be hard to maintain, since the serial version UID 857b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato is then computed from a list of features the serializable class. Changing 858b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato the class ever so slightly may change the computed serial version UID. The 859b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato list of features is specified in the section on <a 860b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato href="http://java.sun.com/javase/6/docs/platform/serialization/spec/class.html#4100">Stream 861b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato Unique Identifiers</a> of Sun's <a 862b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato href="http://java.sun.com/javase/6/docs/platform/serialization/spec/serialTOC.html">Java 863b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato Object Serialization Specification</a>. The following directives should at 864b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato least partially ensure compatibility with the original classes: 865b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 866b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 867b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepnames class * implements java.io.Serializable 868b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 869b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembers class * implements java.io.Serializable { 870b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato static final long serialVersionUID; 871b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private static final java.io.ObjectStreamField[] serialPersistentFields; 872b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato !static !transient <fields>; 873b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato !private <fields>; 874b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato !private <methods>; 875b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void writeObject(java.io.ObjectOutputStream); 876b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private void readObject(java.io.ObjectInputStream); 877b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object writeReplace(); 878b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato java.lang.Object readResolve(); 879b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 880b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 881b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 882b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 883b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato The new options force preservation of the elements involved in the UID 884b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato computation. In addition, the user will have to manually specify all 885b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato interfaces of the serializable classes (using something like "<code>-keep 886b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato interface MyInterface</code>"), since these names are also used when 887b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato computing the UID. A fast but sub-optimal alternative would be simply 888b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang keeping all interfaces with "<code>-keep interface *</code>".</li> 889b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 890b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</ul> 891b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 892b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 893b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote that the above options may preserve more classes and class members 894b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothan strictly necessary. For instance, a large number of classes may implement 895b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothe <code>Serialization</code> interface, yet only a small number may actually 896b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoever be serialized. Knowing your application and tuning the configuration 897b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooften produces more compact results. 898b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 899b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="beans">Processing bean classes</a></h3> 900b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 901b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf your application, applet, servlet, library, etc., makes extensive use of 902b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratointrospection on bean classes to find bean editor classes, or getter and 903b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratosetter methods, then configuration may become painful. There's not much else 904b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoyou can do than making sure the bean class names, or the getter and setter 905b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratonames don't change. For instance: 906b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 907b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyBean { 908b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public void setMyProperty(int); 909b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int getMyProperty(); 910b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 911b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 912b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyBeanEditor 913b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 914b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 915b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf there are too many elements to list explicitly, wildcards in class names 916b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangand method signatures might be helpful. This example preserves all possible 917b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangsetters and getters in classes in the package <code>mybeans</code>: 918b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 919b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep class mybeans.** { 920b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato void set*(***); 921b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato void set*(int, ***); 922b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 923b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato boolean is*(); 924b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato boolean is*(int); 925b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 926b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *** get*(); 927b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato *** get*(int); 928b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 929b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 930b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 931b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe '<code>***</code>' wildcard matches any type (primitive or non-primitive, 932b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoarray or non-array). The methods with the '<code>int</code>' arguments matches 933b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoproperties that are lists. 934b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 935b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="annotations">Processing annotations</a></h3> 936b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 937b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf your application, applet, servlet, library, etc., uses annotations, you may 938b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratowant to preserve them in the processed output. Annotations are represented by 939b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoattributes that have no direct effect on the execution of the code. However, 940b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratotheir values can be retrieved through introspection, allowing developers to 941b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoadapt the execution behavior accordingly. By default, ProGuard treats 942b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoannotation attributes as optional, and removes them in the obfuscation step. 943b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf they are required, you'll have to specify this explicitly: 944b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 945b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepattributes *Annotation* 946b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 947b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 948b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoFor brevity, we're specifying a wildcarded attribute name, which will match 949b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>RuntimeVisibleAnnotations</code>, 950b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>RuntimeInvisibleAnnotations</code>, 951b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>RuntimeVisibleParameterAnnotations</code>, 952b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>RuntimeInvisibleParameterAnnotations</code>, and 953b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>AnnotationDefault</code>. Depending on the purpose of the processed 954b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocode, you could refine this selection, for instance not keeping the run-time 955b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoinvisible annotations (which are only used at compile-time). 956b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 957b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoSome code may make further use of introspection to figure out the enclosing 958b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods of anonymous inner classes. In that case, the corresponding attribute 959b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohas to be preserved as well: 960b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 961b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepattributes EnclosingMethod 962b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 963b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 964b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="database">Processing database drivers</a></h3> 965b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 966b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoDatabase drivers are implementations of the <code>Driver</code> interface. 967b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoSince they are often created dynamically, you may want to preserve any 968b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimplementations that you are processing as entry points: 969b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 970b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep class * implements java.sql.Driver 971b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 972b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 973b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis option also gets rid of the note that ProGuard prints out about 974b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>(java.sql.Driver)Class.forName</code> constructs, if you are 975b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoinstantiating a driver in your code (without necessarily implementing any 976b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratodrivers yourself). 977b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 978b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="componentui">Processing ComponentUI classes</a></h3> 979b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 980b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoSwing UI look and feels are implemented as extensions of the 981b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>ComponentUI</code> class. For some reason, these have to contain a 982b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratostatic method <code>createUI</code>, which the Swing API invokes using 983b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratointrospection. You should therefore always preserve the method as an entry 984b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopoint, for instance like this: 985b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 986b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep class * extends javax.swing.plaf.ComponentUI { 987b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent); 988b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 989b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 990b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 991b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis option also keeps the classes themselves. 992b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 993b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="rmi">Processing RMI code</a></h3> 994b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 995b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoReportedly, the easiest way to handle RMI code is to process the code with 996b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoProGuard first and then invoke the <code>rmic</code> tool. If that is not 997b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopossible, you may want to try something like this: 998b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 999b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepattributes Exceptions 1000b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1001b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep interface * extends java.rmi.Remote { 1002b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato <methods>; 1003b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 1004b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1005b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep class * implements java.rmi.Remote { 1006b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato <init>(java.rmi.activation.ActivationID, java.rmi.MarshalledObject); 1007b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 1008b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1009b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1010b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe first <code>-keep</code> option keeps all your Remote interfaces and their 1011b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods. The second one keeps all the implementations, along with their 1012b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoparticular RMI constructors, if any. 1013b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1014b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <code>Exceptions</code> attribute has to be kept too, because the RMI 1015b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohandling code performs introspection to check whether the method signatures 1016b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoare compatible. 1017b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1018b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="injection">Processing resource injection</a></h3> 1019b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1020b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf your application is using JEE-style resource injection, the application 1021b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangcontainer will automatically assign instances of resource classes to fields and 1022b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangmethods that are annotated with <code>@Resource</code>. The container applies 1023b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangintrospection, even accessing private class members directly. It typically 1024b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangconstructs a resource name based on the type name and the class member name. 1025b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangWe then have to avoid that such class members are removed or renamed: 1026b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 1027b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembers class * { 1028b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang @javax.annotation.Resource *; 1029b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 1030b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 1031b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 1032b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe Spring framework has another similar annotation <code>@Autowired</code>: 1033b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 1034b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-keepclassmembers class * { 1035b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang @org.springframework.beans.factory.annotation.Autowired *; 1036b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 1037b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 1038b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1039b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="resourcefiles">Processing resource files</a></h3> 1040b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1041b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf your application, applet, servlet, library, etc., contains resource files, 1042b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoit may be necessary to adapt their names and/or their contents when the 1043b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoapplication is obfuscated. The following two options can achieve this 1044b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoautomatically: 1045b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1046b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-adaptresourcefilenames **.properties,**.gif,**.jpg 1047b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF 1048b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1049b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1050b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a href="usage.html#adaptresourcefilenames">-adaptresourcefilenames</a> 1051b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooption in this case renames properties files and image files in the processed 1052b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooutput, based on the obfuscated names of their corresponding class files (if 1053b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoany). The <a 1054b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#adaptresourcefilecontents">-adaptresourcefilecontents</a> 1055b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooption looks for class names in properties files and in the manifest file, and 1056b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoreplaces these names by the obfuscated names (if any). You'll probably want to 1057b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoadapt the filters to suit your application. 1058b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1059b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="manifestfiles">Processing manifest files</a></h3> 1060b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1061b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangAs illustrated in the previous section, manifest files can be treated like 1062b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangordinary resource files. ProGuard can adapt obfuscated class names in the 1063b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfiles, but it won't make any other changes. If you want anything else, you 1064b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangshould apply an external tool. For instance, if a manifest file contains 1065b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangsigning information, you should sign the jar again after it has been 1066b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangprocessed. 1067b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 1068b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf you're merging several input jars into a single output jar, you'll have to 1069b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangpick one, typically by specifying <a href="usage.html#filters">filters</a>: 1070b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 1071b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars in1.jar 1072b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars in2.jar(!META-INF/MANIFEST.MF) 1073b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-injars in3.jar(!META-INF/MANIFEST.MF) 1074b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-outjars out.jar 1075b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 1076b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 1077b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe filters will let ProGuard copy the manifest file from the first jar and 1078b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangignore any manifest files in the second and third input jars. Note that 1079b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangProGuard will leave the order of the files in the jars unchanged; manifest 1080b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfiles are not necessarily put first. 1081b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1082b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="stacktrace">Producing useful obfuscated stack traces</a></h3> 1083b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1084b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options let obfuscated applications or libraries produce stack traces 1085b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothat can still be deciphered later on: 1086b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1087b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printmapping out.map 1088b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1089b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-renamesourcefileattribute SourceFile 1090b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepattributes SourceFile,LineNumberTable 1091b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1092b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1093b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're keeping all source file attributes, but we're replacing their values by 1094b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothe string "SourceFile". We could use any string. This string is already 1095b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopresent in all class files, so it doesn't take up any extra space. If you're 1096b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoworking with J++, you'll want to keep the "SourceDir" attribute as well. 1097b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1098b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're also keeping the line number tables of all methods. 1099b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1100b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWhenever both of these attributes are present, the Java run-time environment 1101b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratowill include line number information when printing out exception stack traces. 1102b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1103b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe information will only be useful if we can map the obfuscated names back to 1104b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratotheir original names, so we're saving the mapping to a file 1105b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>out.map</code>. The information can then be used by the <a 1106b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="retrace/index.html">ReTrace</a> tool to restore the original stack trace. 1107b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1108b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="repackaging">Obfuscating package names</a></h3> 1109b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1110b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoPackage names can be obfuscated in various ways, with increasing levels of 1111b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoobfuscation and compactness. For example, consider the following classes: 1112b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1113b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.MyMain 1114b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.Foo 1115b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.Bar 1116b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.extra.FirstExtra 1117b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.extra.SecondExtra 1118b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.util.FirstUtil 1119b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.util.SecondUtil 1120b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1121b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1122b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoLet's assume the class name <code>mycompany.myapplication.MyMain</code> is the 1123b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomain application class that is kept by the configuration. All other class names 1124b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocan be obfuscated. 1125b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1126b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoBy default, packages that contain classes that can't be renamed aren't renamed 1127b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoeither, and the package hierarchy is preserved. This results in obfuscated 1128b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclass names like these: 1129b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1130b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.MyMain 1131b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.a 1132b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.b 1133b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.a.a 1134b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.a.b 1135b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.a.a 1136b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.a.b 1137b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1138b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1139b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe <a 1140b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#flattenpackagehierarchy"><code>-flattenpackagehierarchy</code></a> 1141b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooption obfuscates the package names further, by flattening the package 1142b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohierarchy of obfuscated packages: 1143b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1144b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-flattenpackagehierarchy 'myobfuscated' 1145b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1146b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1147b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe obfuscated class names then look as follows: 1148b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1149b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.MyMain 1150b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.a 1151b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.b 1152b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.a.a 1153b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.a.b 1154b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.b.a 1155b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.b.b 1156b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1157b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1158b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoAlternatively, the <a 1159b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#repackageclasses"><code>-repackageclasses</code></a> option 1160b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoobfuscates the entire packaging, by combining obfuscated classes into a single 1161b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopackage: 1162b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1163b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses 'myobfuscated' 1164b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1165b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe obfuscated class names then look as follows: 1166b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1167b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.MyMain 1168b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.a 1169b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.b 1170b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.a 1171b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.b 1172b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.c 1173b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.d 1174b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1175b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1176b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoAdditionally specifying the <a 1177b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#allowaccessmodification"><code>-allowaccessmodification</code></a> 1178b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooption allows access permissions of classes and class members to 1179b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratobe broadened, opening up the opportunity to repackage all obfuscated classes: 1180b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1181b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses 'myobfuscated' 1182b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 1183b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1184b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe obfuscated class names then look as follows: 1185b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1186b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.MyMain 1187b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.a 1188b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.b 1189b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.c 1190b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.d 1191b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.e 1192b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomyobfuscated.f 1193b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1194b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1195b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe specified target package can always be the root package. For instance: 1196b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1197b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-repackageclasses '' 1198b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-allowaccessmodification 1199b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1200b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe obfuscated class names are then the shortest possible names: 1201b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1202b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomycompany.myapplication.MyMain 1203b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoa 1204b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratob 1205b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoc 1206b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratod 1207b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoe 1208b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratof 1209b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1210b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1211b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote that not all levels of obfuscation of package names may be acceptable for 1212b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoall code. Notably, you may have to take into account that your application may 1213b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocontain <a href="#resourcefiles">resource files</a> that have to be adapted. 1214b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1215b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="logging">Removing logging code</a></h3> 1216b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1217b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangYou can let ProGuard remove logging code. The trick is to specify that the 1218b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wanglogging methods don't have side-effects — even though they actually do, 1219b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangsince they write to the console or to a log file. ProGuard will take your word 1220b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfor it and remove the invocations (in the optimization step) and if possible 1221b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangthe logging classes and methods themselves (in the shrinking step). 1222b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 1223b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangFor example, this configuration removes invocations of the Android logging 1224b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangmethods: 1225b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<pre> 1226b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-assumenosideeffects class android.util.Log { 1227b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static boolean isLoggable(java.lang.String, int); 1228b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static int v(...); 1229b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static int i(...); 1230b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static int w(...); 1231b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static int d(...); 1232b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public static int e(...); 1233b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 1234b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang</pre> 1235b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 1236b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangThe wildcards are a shortcut to match all versions of the methods. 1237b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<p> 1238b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangNote that you generally can't remove logging code that uses 1239b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<code>System.out.println</code>, since you would be removing all invocations 1240b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangof <code>java.io.PrintStream#println</code>, which could break your 1241b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangapplication. You can work around it by creating your own logging methods and 1242b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wanglet ProGuard remove those. 1243b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1244b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="restructuring">Restructuring the output archives</a></h3> 1245b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1246b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIn simple applications, all output classes and resources files are merged into 1247b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoa single jar. For example: 1248b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1249b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars classes 1250b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in1.jar 1251b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in2.jar 1252b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in3.jar 1253b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1254b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1255b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1256b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis configuration merges the processed versions of the files in the 1257b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>classes</code> directory and the three jars into a single output jar 1258b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>out.jar</code>. 1259b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1260b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf you want to preserve the structure of your input jars (and/or wars, ears, 1261b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratozips, or directories), you can specify an output directory (or a war, an ear, 1262b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoor a zip). For example: 1263b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1264b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in1.jar 1265b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in2.jar 1266b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in3.jar 1267b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out 1268b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1269b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1270b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe input jars will then be reconstructed in the directory <code>out</code>, 1271b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratowith their original names. 1272b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1273b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoYou can also combine archives into higher level archives. For example: 1274b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1275b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in1.jar 1276b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in2.jar 1277b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in3.jar 1278b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.war 1279b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1280b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1281b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe other way around, you can flatten the archives inside higher level 1282b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoarchives into simple archives: 1283b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1284b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.war 1285b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1286b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1287b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1288b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis configuration puts the processed contents of all jars inside 1289b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>in.war</code> (plus any other contents of <code>in.war</code>) into 1290b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>out.jar</code>. 1291b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1292b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIf you want to combine input jars (and/or wars, ears, zips, or directories) 1293b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratointo output jars (and/or wars, ears, zips, or directories), you can group the 1294b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<a href="usage.html#injars"><code>-injars</code></a> and <a 1295b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#outjars"><code>-outjars</code></a> options. For example: 1296b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1297b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars base_in1.jar 1298b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars base_in2.jar 1299b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars base_in3.jar 1300b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars base_out.jar 1301b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1302b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars extra_in.jar 1303b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars extra_out.jar 1304b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1305b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1306b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis configuration puts the processed results of all <code>base_in*.jar</code> 1307b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratojars into <code>base_out.jar</code>, and the processed results of the 1308b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>extra_in.jar</code> into <code>extra_out.jar</code>. Note that only the 1309b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoorder of the options matters; the additional whitespace is just for clarity. 1310b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1311b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis grouping, archiving, and flattening can be arbitrarily complex. ProGuard 1312b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoalways tries to package output archives in a sensible way, reconstructing the 1313b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoinput entries as much as required. 1314b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1315b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="filtering">Filtering the input and the output</a></h3> 1316b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1317b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangIf you want even greater control, you can add 1318b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<a href="usage.html#filters">filters</a> to the input and the output, 1319b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangfiltering out zips, ears, wars, jars, and/or ordinary files. For example, if 1320b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangyou want to disregard certain files from an input jar: 1321b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1322b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar(!images/**) 1323b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1324b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1325b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1326b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis configuration removes any files in the <code>images</code> directory and 1327b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoits subdirectories. 1328b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1329b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoSuch filters can be convenient for avoiding warnings about duplicate files in 1330b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothe output. For example, only keeping the manifest file from a first input jar: 1331b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1332b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in1.jar 1333b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in2.jar(!META-INF/MANIFEST.MF) 1334b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in3.jar(!META-INF/MANIFEST.MF) 1335b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1336b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1337b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1338b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoAnother useful application is speeding up the processing by ProGuard, by 1339b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratodisregarding a large number of irrelevant classes in the runtime library jar: 1340b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1341b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar(java/**,javax/**) 1342b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1343b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1344b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe filter makes ProGuard disregard <code>com.sun.**</code> classes, for 1345b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoinstance , which don't affect the processing of ordinary applications. 1346b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1347b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoIt is also possible to filter the jars (and/or wars, ears, zips) themselves, 1348b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratobased on their names. For example: 1349b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1350b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in(**/acme_*.jar;) 1351b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1352b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1353b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1354b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote the semi-colon in the filter; the filter in front of it applies to jar 1355b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratonames. In this case, only <code>acme_*.jar</code> jars are read from the 1356b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratodirectory <code>in</code> and its subdirectories. Filters for war names, ear 1357b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratonames, and zip names can be prefixed with additional semi-colons. All types of 1358b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratofilters can be combined. They are orthogonal. 1359b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1360b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoOn the other hand, you can also filter the output, in order to control what 1361b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocontent goes where. For example: 1362b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1363b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 1364b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars code_out.jar(**.class) 1365b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars resources_out.jar 1366b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1367b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1368b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThis configuration splits the processed output, sending <code>**.class</code> 1369b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratofiles to <code>code_out.jar</code>, and all remaining files to 1370b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>resources_out.jar</code>. 1371b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1372b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoAgain, the filtering can be arbitrarily complex, especially when combined with 1373b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wanggrouping input and output. 1374b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1375b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="multiple">Processing multiple applications at once</a></h3> 1376b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1377b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoYou can process several dependent or independent applications (or applets, 1378b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomidlets,...) in one go, in order to save time and effort. ProGuard's input and 1379b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooutput handling offers various ways to keep the output nicely structured. 1380b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1381b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe easiest way is to specify your input jars (and/or wars, ears, zips, and 1382b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratodirectories) and a single output directory. ProGuard will then reconstruct the 1383b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoinput in this directory, using the original jar names. For example, showing 1384b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratojust the input and output options: 1385b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1386b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars application1.jar 1387b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars application2.jar 1388b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars application3.jar 1389b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars processed_applications 1390b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1391b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1392b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoAfter processing, the directory <code>processed_applications</code> will 1393b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangcontain processed versions of application jars, with their original names. 1394b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1395b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="incremental">Incremental obfuscation</a></h3> 1396b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1397b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoAfter having <a href="#application">processed an application</a>, e.g. 1398b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoProGuard itself, you can still incrementally add other pieces of code that 1399b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratodepend on it, e.g. the ProGuard GUI: 1400b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1401b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars proguardgui.jar 1402b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars proguardgui_out.jar 1403b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars proguard.jar 1404b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars proguard_out.jar 1405b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 1406b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-applymapping proguard.map 1407b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1408b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class proguard.gui.ProGuardGUI { 1409b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static void main(java.lang.String[]); 1410b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 1411b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1412b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1413b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're reading both unprocessed jars as input. Their processed contents will go 1414b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoto the respective output jars. The <a 1415b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#applymapping"><code>-applymapping</code></a> option then 1416b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomakes sure the ProGuard part of the code gets the previously produced 1417b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoobfuscation mapping. The final application will consist of the obfuscated 1418b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoProGuard jar and the additional obfuscated GUI jar. 1419b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1420b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe added code in this example is straightforward; it doesn't affect the 1421b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooriginal code. The <code>proguard_out.jar</code> will be identical to the one 1422b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoproduced in the initial processing step. If you foresee adding more complex 1423b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoextensions to your code, you should specify the options <a 1424b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#useuniqueclassmembernames"><code>-useuniqueclassmembernames</code></a>, 1425b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<a href="usage.html#dontshrink"><code>-dontshrink</code></a>, and <a 1426b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#dontoptimize"><code>-dontoptimize</code></a> <i>in the 1427b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratooriginal processing step</i>. These options ensure that the obfuscated base 1428b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratojar will always remain usable without changes. You can then specify the base 1429b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratojar as a library jar: 1430b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1431b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars proguardgui.jar 1432b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars proguardgui_out.jar 1433b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars proguard.jar 1434b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 1435b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-applymapping proguard.map 1436b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1437b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class proguard.gui.ProGuardGUI { 1438b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static void main(java.lang.String[]); 1439b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 1440b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1441b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1442b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="microedition">Preverifying class files for Java Micro Edition</a></h3> 1443b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1444b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoEven if you're not interested in shrinking, optimizing, and obfuscating your 1445b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomidlets, as shown in the <a href="#midlets">midlets example</a>, you can still 1446b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratouse ProGuard to preverify the class files for Java Micro Edition. ProGuard 1447b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangproduces slightly more compact results than the traditional external 1448b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopreverifier. 1449b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1450b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 1451b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1452b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/wtk2.5.2/lib/midpapi20.jar 1453b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang-libraryjars /usr/local/java/wtk2.5.2/lib/cldcapi11.jar 1454b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1455b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontshrink 1456b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontoptimize 1457b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontobfuscate 1458b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1459b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-microedition 1460b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1461b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1462b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're not processing the input, just making sure the class files are 1463b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopreverified by targeting them at Java Micro Edition with the <a 1464b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#microedition"><code>-microedition</code></a> option. Note 1465b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothat we don't need any <code>-keep</code> options to specify entry points; all 1466b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoclass files are simply preverified. 1467b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1468b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="upgrade">Upgrading class files to Java 6</a></h3> 1469b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1470b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe following options upgrade class files to Java 6, by updating their 1471b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratointernal version numbers and preverifying them. The class files can then be 1472b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoloaded more efficiently by the Java 6 Virtual Machine. 1473b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1474b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 1475b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1476b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 1477b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1478b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontshrink 1479b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontoptimize 1480b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontobfuscate 1481b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1482b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-target 1.6 1483b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1484b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1485b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're not processing the input, just retargeting the class files with the <a 1486b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#target"><code>-target</code></a> option. They will 1487b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoautomatically be preverified for Java 6 as a result. Note that we don't need 1488b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoany <code>-keep</code> options to specify entry points; all class files are 1489b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratosimply updated and preverified. 1490b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1491b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="deadcode">Finding dead code</a></h3> 1492b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1493b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options list unused classes, fields, and methods in the application 1494b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>mypackage.MyApplication</code>: 1495b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1496b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 1497b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 1498b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1499b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontoptimize 1500b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontobfuscate 1501b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontpreverify 1502b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-printusage 1503b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1504b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keep public class mypackage.MyApplication { 1505b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static void main(java.lang.String[]); 1506b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 1507b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1508b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1509b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoWe're not specifying an output jar, just printing out some results. We're 1510b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratosaving some processing time by skipping the other processing steps. 1511b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1512b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe java compiler inlines primitive constants and String constants 1513b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato(<code>static final</code> fields). ProGuard would therefore list such fields 1514b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoas not being used in the class files that it analyzes, even if they <i>are</i> 1515b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoused in the source files. We can add a <a 1516b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="usage.html#keepclassmembers"><code>-keepclassmembers</code></a> option 1517b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratothat keeps those fields a priori, in order to avoid having them listed: 1518b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1519b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-keepclassmembers class * { 1520b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato static final % *; 1521b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato static final java.lang.String *; 1522b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 1523b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1524b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1525b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="structure">Printing out the internal structure of class files</a></h3> 1526b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 1527b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThese options print out the internal structure of all class files in the input 1528b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratojar: 1529b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1530b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 1531b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1532b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontshrink 1533b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontoptimize 1534b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontobfuscate 1535b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dontpreverify 1536b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1537b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-dump 1538b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1539b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1540b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoNote how we don't need to specify the Java run-time jar, because we're not 1541b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoprocessing the input jar at all. 1542b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1543b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<h3><a name="annotated">Using annotations to configure ProGuard</a></h3> 1544b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1545b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe traditional ProGuard configuration allows to keep a clean separation 1546b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratobetween the code and the configuration for shrinking, optimization, and 1547b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoobfuscation. However, it is also possible to define specific annotations, 1548b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoand then annotate the code to configure the processing. 1549b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1550b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoYou can find a set of such predefined annotations in the directory 1551b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>examples/annotations/lib</code> in the ProGuard distribution. 1552b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe annotation classes are defined in <code>annotations.jar</code>. The 1553b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratocorresponding ProGuard configuration (or meta-configuration, if you prefer) 1554b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratois specified in <code>annotations.pro</code>. With these files, you can start 1555b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoannotating your code. For instance, a java source file 1556b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>Application.java</code> can be annotated as follows: 1557b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1558b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato@KeepApplication 1559b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopublic class Application { 1560b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato .... 1561b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 1562b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1563b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1564b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe ProGuard configuration file for the application can then be simplified by 1565b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoleveraging off these annotations: 1566b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<pre> 1567b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-injars in.jar 1568b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-outjars out.jar 1569b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-libraryjars <java.home>/lib/rt.jar 1570b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1571b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato-include lib/annotations.pro 1572b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</pre> 1573b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1574b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe annotations are effectively replacing the application-dependent 1575b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>-keep</code> options. You may still wish to add traditional 1576b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<code>-keep</code> options for processing <a href="#native">native 1577b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratomethods</a>, <a href="#enumerations">enumerations</a>, <a 1578b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#serializable">serializable classes</a>, and <a 1579b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratohref="#annotations">annotations</a>. 1580b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<p> 1581b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe OnoratoThe directory <code>examples/annotations</code> contains more examples that 1582b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoillustrate some of the possibilities. 1583b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 1584b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<hr /> 1585b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<noscript><div><a target="_top" href="/index.html" class="button">Show menu</a></div></noscript> 1586b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato<address> 1587b9cc48a43ed984587c939d02fba5316bf5c0df6eYing WangCopyright © 2002-2013 1588b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang<a target="other" href="http://www.lafortune.eu/">Eric Lafortune</a>. 1589b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</address> 1590b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</body> 1591b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato</html> 1592