<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Proguard &#8211; Wiebe Elsinga</title>
	<atom:link href="http://wiebe-elsinga.com/blog/tag/proguard/feed/" rel="self" type="application/rss+xml" />
	<link>http://wiebe-elsinga.com/blog</link>
	<description>Blog</description>
	<lastBuildDate>Fri, 20 Mar 2015 20:42:38 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.1</generator>
	<item>
		<title>Archive addition Android artifacts with Gradle.</title>
		<link>http://wiebe-elsinga.com/blog/archive-addition-android-artifacts-with-gradle/</link>
		
		<dc:creator><![CDATA[W.Elsinga]]></dc:creator>
		<pubDate>Fri, 20 Mar 2015 06:42:19 +0000</pubDate>
				<category><![CDATA[AndroidDev Tips]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[gradle]]></category>
		<category><![CDATA[javadoc]]></category>
		<category><![CDATA[Proguard]]></category>
		<guid isPermaLink="false">http://wiebe-elsinga.com/blog/?p=1651</guid>

					<description><![CDATA[When building Android applications or libraries common practice is to save your artifacts to a local file storage or repo. Beside your APK there are some additional artifacts you want/need to save, and you want gradle to do this. Most common ones are Javadoc, your source files and perhaps your proguard generated files like the mapping file. I naturally wanted a Gradle task to handle this. So lets have a look as some tasks you may want to use. Adding Javadoc archive tasks The following will add tasks to generate Javadocs for each build type and assemble it into a jar archive . 123456789101112131415161718192021222324252627282930313233343536android.applicationVariants.all &#123; variant -&#62; &#160; &#160; project.task&#40;&#34;${variant.name.capitalize()}Javadoc&#34;, type: Javadoc&#41; &#123; &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/javadoc/$variant.name&#34;&#41; &#160; &#160; &#160; &#160; source = variant.javaCompile.source &#160; &#160; &#160; &#160; ext.androidJar = &#34;${project.android.sdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar&#34; &#160; &#160; &#160; &#160; classpath = project.files&#40;variant.javaCompile.classpath.files&#41; + project.files&#40;ext.androidJar&#41; &#160; &#160; &#160; &#160; options &#123; &#160; &#160; &#160; &#160; &#160; &#160; linksOffline&#40;&#34;http://d.android.com/reference&#34;, &#34;${project.android.sdkDirectory}/docs/reference&#34;&#41; &#160; &#160; &#160; &#160; &#160; &#160; links&#40;&#34;http://docs.oracle.com/javase/7/docs/api/&#34;&#41;; &#160; &#160; &#160; &#160; &#160; &#160; setMemberLevel&#40;JavadocMemberLevel.PACKAGE&#41; &#160; &#160; &#160; &#160; &#160; &#160; docEncoding = 'UTF-8' &#160; &#160; &#160; &#160; &#160; &#160; encoding = 'UTF-8' &#160; &#160; &#160; &#160; &#160; &#160; charSet = 'UTF-8' &#160; &#160; &#160; &#160; &#125; &#160; &#160; &#160; &#160; exclude '**/BuildConfig.java' &#160; &#160; &#160; &#160; exclude '**/R.java' &#160; &#160; &#125; &#160; &#160; project.task&#40;&#34;generate${variant.name.capitalize()}JavadocJar&#34;, type: Jar, dependsOn: &#34;${variant.name.capitalize()}Javadoc&#34;&#41; &#123; &#160; &#160; &#160; &#160; classifier 'javadoc' &#160; &#160; &#160; &#160; description = 'Assembles a jar archive containing the generated Javadoc API documentation of $variant.name.' &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/libs/&#34;&#41; &#160; &#160; &#160; &#160; exclude '**/BuildConfig.class' &#160; &#160; &#160; &#160; exclude '**/R.class' &#160; &#160; &#160; &#160; from &#34;$project.buildDir/javadoc/$variant.name&#34; &#160; &#160; &#125; &#125; When added to your build.gradle file, generate your Javadoc jar archive from the command line with gradle generateReleaseJavadocJar. Adding Source archive tasks The following will add tasks to assemble a jar archive containing the Java sources. 123456789101112131415android.applicationVariants.all &#123; variant -&#62; &#160; &#160; project.task&#40;&#34;generate${variant.name.capitalize()}SourcesJar&#34;, type: Jar&#41; &#123; &#160; &#160; &#160; &#160; classifier = 'sources' &#160; &#160; &#160; &#160; description = 'Assembles a jar archive containing the main sources of $variant.name..' &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/libs/&#34;&#41; &#160; &#160; &#160; &#160; // exclude generated files &#160; &#160; &#160; &#160; exclude '**/BuildConfig.java' &#160; &#160; &#160; &#160; exclude '**/R.java' &#160; &#160; &#160; &#160; from variant.javaCompile.source &#160; &#160; &#125; &#125; When added to your build.gradle file, generate your Sources jar archive from the command line with gradle generateReleaseSourcesJar. Adding Proguard archive tasks The following will add tasks to assemble a zip archive containing the generated proguard files. 12345678910android.applicationVariants.all &#123; variant -&#62; &#160; &#160; project.task&#40;&#34;generate${variant.name.capitalize()}ProguardFilesJar&#34;, type: Zip&#41; &#123; &#160; &#160; &#160; &#160; classifier 'proguard' &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; description = 'Assembles a jar archive containing the Proguard files of $variant.name..' &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; destinationDir = new File&#40;&#34;$project.buildDir/libs/&#34;&#41; &#160; &#160; &#160; &#160; from &#34;$project.buildDir/outputs/mapping&#34; &#160; &#160; &#125; &#160; &#160; &#125; When added to your build.gradle file, generate your Proguard zip archive from the command line with gradle generateReleaseProguardFilesJar.]]></description>
										<content:encoded><![CDATA[<p>When building Android applications or libraries common practice is to save your artifacts to a local file storage or repo.</p>
<p>Beside your APK there are some additional artifacts you want/need to save, and you want gradle to do this. Most common ones are Javadoc, your source files and perhaps your <a href="http://proguard.sourceforge.net/">proguard</a> generated files like the mapping file.</p>
<p>I naturally wanted a Gradle task to handle this. So lets have a look as some tasks you may want to use.<br />
</p>
<h3>Adding Javadoc archive tasks</h3>
<p>The following will add tasks to generate Javadocs for each build type and assemble it into a jar archive .</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:100%;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">android.<span style="color: #006600;">applicationVariants</span>.<span style="color: #006600;">all</span> <span style="color: #66cc66;">&#123;</span> variant <span style="color: #66cc66;">-&gt;</span><br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;${variant.name.capitalize()}Javadoc&quot;</span>, type: Javadoc<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/javadoc/$variant.name&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; source <span style="color: #66cc66;">=</span> variant.<span style="color: #006600;">javaCompile</span>.<span style="color: #006600;">source</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; ext.<span style="color: #006600;">androidJar</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">&quot;${project.android.sdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classpath <span style="color: #66cc66;">=</span> project.<span style="color: #006600;">files</span><span style="color: #66cc66;">&#40;</span>variant.<span style="color: #006600;">javaCompile</span>.<span style="color: #006600;">classpath</span>.<span style="color: #006600;">files</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> project.<span style="color: #006600;">files</span><span style="color: #66cc66;">&#40;</span>ext.<span style="color: #006600;">androidJar</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; options <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; linksOffline<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://d.android.com/reference&quot;</span>, <span style="color: #ff0000;">&quot;${project.android.sdkDirectory}/docs/reference&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; links<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;http://docs.oracle.com/javase/7/docs/api/&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setMemberLevel<span style="color: #66cc66;">&#40;</span>JavadocMemberLevel.<a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20package"><span style="color: #000000; font-weight: bold;">PACKAGE</span></a><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; docEncoding <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'UTF-8'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encoding <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'UTF-8'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; charSet <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'UTF-8'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/BuildConfig.java'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/R.java'</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;generate${variant.name.capitalize()}JavadocJar&quot;</span>, type: Jar, dependsOn: <span style="color: #ff0000;">&quot;${variant.name.capitalize()}Javadoc&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classifier <span style="color: #ff0000;">'javadoc'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Assembles a jar archive containing the generated Javadoc API documentation of $variant.name.'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/libs/&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/BuildConfig.class'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/R.class'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color: #ff0000;">&quot;$project.buildDir/javadoc/$variant.name&quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>When added to your <code class="codecolorer bash blackboard"><span class="bash">build.gradle</span></code> file, generate your Javadoc jar archive from the command line with <code class="codecolorer bash blackboard"><span class="bash">gradle generateReleaseJavadocJar</span></code>.<br />
</p>
<h3>Adding Source archive tasks</h3>
<p>The following will add tasks to assemble a jar archive containing the Java sources.</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">android.<span style="color: #006600;">applicationVariants</span>.<span style="color: #006600;">all</span> <span style="color: #66cc66;">&#123;</span> variant <span style="color: #66cc66;">-&gt;</span><br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;generate${variant.name.capitalize()}SourcesJar&quot;</span>, type: Jar<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classifier <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'sources'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Assembles a jar archive containing the main sources of $variant.name..'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/libs/&quot;</span><span style="color: #66cc66;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// exclude generated files</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/BuildConfig.java'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; exclude <span style="color: #ff0000;">'**/R.java'</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; from variant.<span style="color: #006600;">javaCompile</span>.<span style="color: #006600;">source</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>When added to your <code class="codecolorer bash blackboard"><span class="bash">build.gradle</span></code> file, generate your Sources jar archive from the command line with <code class="codecolorer bash blackboard"><span class="bash">gradle generateReleaseSourcesJar</span></code>.<br />
</p>
<h3>Adding Proguard archive tasks</h3>
<p>The following will add tasks to assemble a zip archive containing the generated proguard files.</p>
<div class="codecolorer-container groovy blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="groovy codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">android.<span style="color: #006600;">applicationVariants</span>.<span style="color: #006600;">all</span> <span style="color: #66cc66;">&#123;</span> variant <span style="color: #66cc66;">-&gt;</span><br />
&nbsp; &nbsp; project.<span style="color: #006600;">task</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;generate${variant.name.capitalize()}ProguardFilesJar&quot;</span>, type: Zip<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; classifier <span style="color: #ff0000;">'proguard'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; description <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'Assembles a jar archive containing the Proguard files of $variant.name..'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; destinationDir <span style="color: #66cc66;">=</span> <a href="http://www.google.de/search?q=site%3Agroovy.codehaus.org/%20new"><span style="color: #000000; font-weight: bold;">new</span></a> <a href="http://www.google.de/search?as_q=File&amp;num=100&amp;hl=en&amp;as_occt=url&amp;as_sitesearch=java.sun.com%2Fj2se%2F1%2E5%2E0%2Fdocs%2Fapi%2F"><span style="color: #aaaadd; font-weight: bold;">File</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$project.buildDir/libs/&quot;</span><span style="color: #66cc66;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; from <span style="color: #ff0000;">&quot;$project.buildDir/outputs/mapping&quot;</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> &nbsp; &nbsp;<br />
<span style="color: #66cc66;">&#125;</span></div></td></tr></tbody></table></div>
<p>When added to your <code class="codecolorer bash blackboard"><span class="bash">build.gradle</span></code> file, generate your Proguard zip archive from the command line with <code class="codecolorer bash blackboard"><span class="bash">gradle generateReleaseProguardFilesJar</span></code>.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Obfuscating for Android with ProGuard</title>
		<link>http://wiebe-elsinga.com/blog/obfuscating-for-android-with-proguard/</link>
					<comments>http://wiebe-elsinga.com/blog/obfuscating-for-android-with-proguard/#comments</comments>
		
		<dc:creator><![CDATA[W.Elsinga]]></dc:creator>
		<pubDate>Fri, 14 Dec 2012 05:56:23 +0000</pubDate>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Proguard]]></category>
		<guid isPermaLink="false">http://wiebe-elsinga.com/blog/?p=1337</guid>

					<description><![CDATA[Obfu-what? Right, Obfuscation, in general, describes a practice that is used to intentionally make something more difficult to understand. The nature of Java (the programming language for Android apps) is that the code is not compiled down to machine code; it is compiled to an intermediate format that is ready to be run on a variety of hardware platforms. While this allows great portability, it also leaves the code for Android apps, as present in the APK (Application PacKage file), available for extraction. I&#8217;m going to describe a way for you to obfuscate your Android code to make it harder for others to reverse engineer. And also why not shrink the size of your Android applications and optimize them to make them run faster at the same time. Without a doubt, the simplest method to protect an app is to enable the obfuscation in ProGuard. This freely available tool is already built into the Android toolkit. Obfuscation By default, compiled bytecode still contains a lot of debugging information: source file names, line numbers, field names, method names, argument names, variable names, etc. This information makes it straightforward to decompile the bytecode and reverse-engineer entire apps. Sometimes, this is not desirable. Obfuscators, such as ProGuard, can remove the debugging information and replace all names by meaningless character sequences, making it much harder to reverse-engineer the code. It further compacts the code as a bonus. The app remains functionally equivalent, except for the class names, method names, and line numbers given in exception stack traces. Shrinking Java source code (.java files) is typically compiled to bytecode (.class files). Bytecode is more compact than Java source code, but it may still contain a lot of unused code, especially if it includes program libraries. Shrinking programs such as ProGuard can analyze bytecode and remove unused classes, fields, and methods. The app remains functionally equivalent, including the information given in exception stack traces. For a realistic example, take the following code: if&#40;Config.LOGD&#41;&#41; &#123; &#160;Log.d&#40;TAG, &#34;Some text&#34;&#41;; &#125; The code as shown above is a typical scenario during development. You create code like this to help debug and test your code. Before releasing the final product, though, you set Config.LOGD to false, so it doesn&#8217;t execute. The problem is, this code is still in your application. It makes it bigger, and may cause potential security issues by including code which should never be seen by a snooping hacker. Shrinking the code solves this problem beautifully. The code is completely removed from the final product, leaving the final package safer and smaller. Optimizing Apart from removing unused classes, fields, and methods in the shrinking step, ProGuard can also perform optimizations at the bytecode level, inside and across methods. Proguard So let&#8217;s have a look at the proguard.cfg file. I recommend you open up the sample code, as I will be highlighting the key parts on this page. Basic template -dontpreverify -repackageclasses '' -allowaccessmodification -optimizations !code/simplification/arithmetic -keepattributes *Annotation* -keep public class * extends android.app.Activity -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -keep public class * extends android.content.ContentProvider -keep public class * extends android.view.View { &#160; &#160; public &#60;init&#62;(android.content.Context); &#160; &#160; public &#60;init&#62;(android.content.Context, android.util.AttributeSet); &#160; &#160; public &#60;init&#62;(android.content.Context, android.util.AttributeSet, int); &#160; &#160; public void set*(...); } -keepclasseswithmembers class * { &#160; &#160; public &#60;init&#62;(android.content.Context, android.util.AttributeSet); } -keepclasseswithmembers class * { &#160; &#160; public &#60;init&#62;(android.content.Context, android.util.AttributeSet, int); } -keepclassmembers class * implements android.os.Parcelable { &#160; &#160; static android.os.Parcelable$Creator CREATOR; } -keepclassmembers class **.R$* { &#160; &#160; public static &#60;fields&#62;; } Fragments -keep public class * extends android.support.v4.app.Fragment -keep public class * extends android.app.Fragment Serializables -keepnames class * implements java.io.Serializable -keepclassmembers class * implements java.io.Serializable { &#160; &#160; static final long serialVersionUID; &#160; &#160; private static final java.io.ObjectStreamField[] serialPersistentFields; &#160; &#160; !static !transient &#60;fields&#62;; &#160; &#160; !private &#60;fields&#62;; &#160; &#160; !private &#60;methods&#62;; &#160; &#160; private void writeObject(java.io.ObjectOutputStream); &#160; &#160; private void readObject(java.io.ObjectInputStream); &#160; &#160; java.lang.Object writeReplace(); &#160; &#160; java.lang.Object readResolve(); } Removing Logging -assumenosideeffects class android.util.Log { &#160; &#160; public static *** e(...); &#160; &#160; public static *** w(...); &#160; &#160; public static *** wtf(...); &#160; &#160; public static *** d(...); &#160; &#160; public static *** v(...); } Methods -keepclasseswithmembernames class * { &#160; &#160; native &#60;methods&#62;; } -keepclassmembers class * { &#160; &#160; public void *ButtonClicked(android.view.View); } Now that we have added all our Proguard settings, we need to run Proguard during the build fase. I will use Maven to illustrate this. Within your pom.xml the android-maven-plugin should be defined. To this definition add the proguard setting like: &#160; &#160; &#160; &#60;plugin&#62; &#160; &#160; &#160; &#160; &#60;groupId&#62;com.jayway.maven.plugins.android.generation2&#60;/groupId&#62; &#160; &#160; &#160; &#160; &#60;artifactId&#62;android-maven-plugin&#60;/artifactId&#62; &#160; &#160; &#160; &#160; &#60;version&#62;3.0.0&#60;/version&#62; &#160; &#160; &#160; &#160; &#60;extensions&#62;true&#60;/extensions&#62; &#160; &#160; &#160; &#160; &#60;configuration&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;sdk&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;platform&#62;15&#60;/platform&#62; &#160; &#160; &#160; &#160; &#160; &#60;/sdk&#62; &#160; &#160; &#160; &#160; &#160; &#60;dex&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;jvmArguments&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#60;argument&#62;-Xms256m&#60;/argument&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#60;argument&#62;-Xmx512m&#60;/argument&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;/jvmArguments&#62; &#160; &#160; &#160; &#160; &#160; &#60;/dex&#62; &#160; &#160; &#160; &#160; &#160; &#60;run&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#60;debug&#62;true&#60;/debug&#62; &#160; &#160; &#160; &#160; &#160; &#60;/run&#62; &#160; &#160; &#160; &#160; &#160; &#60;proguard&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;skip&#62;false&#60;/skip&#62; &#160; &#160; &#160; &#160; &#160; &#160; &#60;config&#62;proguard.cfg&#60;/config&#62; &#160; &#160; &#160; &#160; &#160; &#60;/proguard&#62; &#160; &#160; &#160; &#160; &#60;/configuration&#62; &#160; &#160; &#160; &#60;/plugin&#62; All that is left is to run Maven with mvn clean install To check if the app has been obfuscated, install the apk on you Android device and when you run it, you shouldn&#8217;t see any logging in logcat.]]></description>
										<content:encoded><![CDATA[<p>Obfu-what? Right, Obfuscation, in general, describes a practice that is used to intentionally make something more difficult to understand.<br />
The nature of Java (the programming language for Android apps) is that the code is not compiled down to machine code; it is compiled to an intermediate format that is ready to be run on a variety of hardware platforms. While this allows great portability, it also leaves the code for Android apps, as present in the APK (Application PacKage file), available for extraction.<br />
I&#8217;m going to describe a way for you to obfuscate your Android code to make it harder for others to reverse engineer. And also why not shrink the size of your Android applications and optimize them to make them run faster at the same time.</p>
<p>Without a doubt, the simplest method to protect an app is to enable the obfuscation in <a href="http://proguard.sourceforge.net/" title="Proguard" target="_blank">ProGuard</a>. This freely available tool is already built into the Android toolkit.</p>
<h3>Obfuscation</h3>
<p>By default, compiled bytecode still contains a lot of debugging information: source file names, line numbers, field names, method names, argument names, variable names, etc. This information makes it straightforward to decompile the bytecode and reverse-engineer entire apps. Sometimes, this is not desirable. Obfuscators, such as ProGuard, can remove the debugging information and replace all names by meaningless character sequences, making it much harder to reverse-engineer the code. It further compacts the code as a bonus. The app remains functionally equivalent, except for the class names, method names, and line numbers given in exception stack traces.</p>
<h3>Shrinking</h3>
<p>Java source code (.java files) is typically compiled to bytecode (.class files). Bytecode is more compact than Java source code, but it may still contain a lot of unused code, especially if it includes program libraries. Shrinking programs such as ProGuard can analyze bytecode and remove unused classes, fields, and methods. The app remains functionally equivalent, including the information given in exception stack traces. </p>
<p>For a realistic example, take the following code:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;"><span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>Config.<span style="color: #006633;">LOGD</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp;Log.<span style="color: #006633;">d</span><span style="color: #009900;">&#40;</span>TAG, <span style="color: #0000ff;">&quot;Some text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>The code as shown above is a typical scenario during development. You create code like this to help debug and test your code. Before releasing the final product, though, you set Config.LOGD to false, so it doesn&#8217;t execute. The problem is, this code is still in your application. It makes it bigger, and may cause potential security issues by including code which should never be seen by a snooping hacker.</p>
<p>Shrinking the code solves this problem beautifully. The code is completely removed from the final product, leaving the final package safer and smaller.</p>
<h3>Optimizing</h3>
<p>Apart from removing unused classes, fields, and methods in the shrinking step, ProGuard can also perform optimizations at the bytecode level, inside and across methods.</p>
<h3>Proguard</h3>
<p>So let&#8217;s have a look at the <i>proguard.cfg</i> file. I recommend you open up the <a href="https://github.com/welsinga/sample_proguard" title="Sample code" target="_blank">sample code</a>, as I will be highlighting the key parts on this page.</p>
<h4>Basic template</h4>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:100%;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">-dontpreverify<br />
-repackageclasses ''<br />
-allowaccessmodification<br />
-optimizations !code/simplification/arithmetic<br />
-keepattributes *Annotation*<br />
<br />
-keep public class * extends android.app.Activity<br />
-keep public class * extends android.app.Application<br />
-keep public class * extends android.app.Service<br />
-keep public class * extends android.content.BroadcastReceiver<br />
-keep public class * extends android.content.ContentProvider<br />
<br />
-keep public class * extends android.view.View {<br />
&nbsp; &nbsp; public &lt;init&gt;(android.content.Context);<br />
&nbsp; &nbsp; public &lt;init&gt;(android.content.Context, android.util.AttributeSet);<br />
&nbsp; &nbsp; public &lt;init&gt;(android.content.Context, android.util.AttributeSet, int);<br />
&nbsp; &nbsp; public void set*(...);<br />
}<br />
<br />
-keepclasseswithmembers class * {<br />
&nbsp; &nbsp; public &lt;init&gt;(android.content.Context, android.util.AttributeSet);<br />
}<br />
<br />
-keepclasseswithmembers class * {<br />
&nbsp; &nbsp; public &lt;init&gt;(android.content.Context, android.util.AttributeSet, int);<br />
}<br />
<br />
-keepclassmembers class * implements android.os.Parcelable {<br />
&nbsp; &nbsp; static android.os.Parcelable$Creator CREATOR;<br />
}<br />
<br />
-keepclassmembers class **.R$* {<br />
&nbsp; &nbsp; public static &lt;fields&gt;;<br />
}</div></div>
<h4>Fragments</h4>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">-keep public class * extends android.support.v4.app.Fragment<br />
-keep public class * extends android.app.Fragment</div></div>
<h4>Serializables</h4>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">-keepnames class * implements java.io.Serializable<br />
<br />
-keepclassmembers class * implements java.io.Serializable {<br />
&nbsp; &nbsp; static final long serialVersionUID;<br />
&nbsp; &nbsp; private static final java.io.ObjectStreamField[] serialPersistentFields;<br />
&nbsp; &nbsp; !static !transient &lt;fields&gt;;<br />
&nbsp; &nbsp; !private &lt;fields&gt;;<br />
&nbsp; &nbsp; !private &lt;methods&gt;;<br />
&nbsp; &nbsp; private void writeObject(java.io.ObjectOutputStream);<br />
&nbsp; &nbsp; private void readObject(java.io.ObjectInputStream);<br />
&nbsp; &nbsp; java.lang.Object writeReplace();<br />
&nbsp; &nbsp; java.lang.Object readResolve();<br />
}</div></div>
<h4>Removing Logging</h4>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">-assumenosideeffects class android.util.Log {<br />
&nbsp; &nbsp; public static *** e(...);<br />
&nbsp; &nbsp; public static *** w(...);<br />
&nbsp; &nbsp; public static *** wtf(...);<br />
&nbsp; &nbsp; public static *** d(...);<br />
&nbsp; &nbsp; public static *** v(...);<br />
}</div></div>
<h4>Methods</h4>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">-keepclasseswithmembernames class * {<br />
&nbsp; &nbsp; native &lt;methods&gt;;<br />
}<br />
-keepclassmembers class * {<br />
&nbsp; &nbsp; public void *ButtonClicked(android.view.View);<br />
}</div></div>
<p>Now that we have added all our Proguard settings, we need to run Proguard during the build fase. I will use <i>Maven</i> to illustrate this.</p>
<p>Within your <i>pom.xml</i> the <i>android-maven-plugin</i> should be defined. To this definition add the <i>proguard</i> setting like:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:100%;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.jayway.maven.plugins.android.generation2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>android-maven-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>3.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extensions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extensions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdk<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;platform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>15<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/platform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdk<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dex<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jvmArguments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;argument<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-Xms256m<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/argument<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;argument<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-Xmx512m<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/argument<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jvmArguments<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dex<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;run<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;debug<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/debug<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/run<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;proguard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;skip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/skip<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>proguard.cfg<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/proguard<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div>
<p>All that is left is to run Maven with</p>
<div class="codecolorer-container dos default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap;">mvn clean install</div></div>
<p>To check if the app has been obfuscated, install the apk on you Android device and when you run it, you shouldn&#8217;t see any logging in logcat.</p>
]]></content:encoded>
					
					<wfw:commentRss>http://wiebe-elsinga.com/blog/obfuscating-for-android-with-proguard/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
