/2012/07/07/How-to-obfuscate-and-package-a-libgdx-app-for-distribution/

{"item":{"status":"visible","url":"\/2012\/07\/07\/How-to-obfuscate-and-package-a-libgdx-app-for-distribution\/","trash":"","name":"How-to-obfuscate-and-package-a-libgdx-app-for-distribution","parent":"","title":"How to obfuscate and package a libgdx app for distribution","date":"2012-07-07 22:05:59","filepath":"posts\/20120707_How-to-obfuscate-and-package-a-libgdx-app-for-distribution.xml.json","type":"post","content":"<p><strong><img style=\"float: left; margin-left: 10px; margin-right: 10px;\" src=\"http:\/\/www.8bitrobot.com\/media\/uploads\/2012\/01\/gear.png\" alt=\"\" width=\"60\" height=\"64\" \/>First off:<\/strong> This is an <a href=\"http:\/\/www.8bitrobot.com\/tag\/impatient%20guide\/\">Impatient Guide<\/a> and it will be short on explanation and possibly accuracy<\/p>\n<p><strong>Second off:<\/strong> This method is a first attempt and is probably fraught with errors and inefficiencies, but it worked for me.<\/p>\n<p><em>Let's get started!<\/em><\/p>\n<p>Say you have a <a href=\"http:\/\/libgdx.badlogicgames.com\/\">LibGDX<\/a> project and you want to package it up for redistribution, but you don't want to give out a jar and would like it to be wrapped in a nice executable (.exe) just like any ordinary Windows binary. &nbsp;In addition, obfuscating the code to make reverse engineering more difficult might be something you want too.<\/p>\n<p>Here's how I did it manually with <a href=\"http:\/\/www.eclipse.org\/\">Eclipse<\/a>, <a href=\"http:\/\/proguard.sourceforge.net\/\">ProGuard<\/a>, <a href=\"http:\/\/launch4j.sourceforge.net\/\">Launch4j<\/a>, and <a href=\"http:\/\/www.7-zip.org\/\">7-zip<\/a>.<\/p>\n<h2>Creating the JAR files:<\/h2>\n<ol>\n<li>Export a jar file with the <a href=\"http:\/\/www.eclipse.org\/\">Eclipse<\/a> Export Wizard. &nbsp;I did this for my desktop version, by right clicking on the project \"myapp-desktop\" -&gt; Export -&gt; Java -&gt; Runnable Jar File.<\/li>\n<li>Plug in the usual stuff into the wizard, but choose \"Copy required libraries into a sub-folder next to the generated JAR.\" &nbsp;Otherwise, ProGuard will make your life a nightmare when you try to obfuscate (e.g. \"Warning: org.lwjgl.input.Controllers: can't find referenced class net.java.games.input.ControllerEnvironment\").<\/li>\n<li>Hit \"finish\" and the wizard will generate your shiny new .jar file.<\/li>\n<li>Do 1 through 3 again, but in step 2 choose \"Package required libraries into generated JAR.\" &nbsp;The jarinjarloader files and the MANIFEST.MF from this second generated JAR will be used later on.<\/li>\n<\/ol>\n<h2>Obfuscate your jar with ProGuard:<\/h2>\n<ol>\n<li>Run the GUI version of <a href=\"http:\/\/proguard.sourceforge.net\/\">ProGuard<\/a>:&nbsp;<em>java -jar proguardgui.jar<\/em><\/li>\n<li>In the Input\/Output tab, click \"Add input...\" and enter the first generated JAR path.<\/li>\n<li>Click \"Add output...\" and enter your output JAR... say (e.g. <em>output.jar<\/em>).<\/li>\n<li>Click \"Add...\" in the Add libraries section and add the library export directory generated with the first JAR. &nbsp;If your export JAR name was&nbsp;<em>foo.jar<\/em>, the export dependencies should be in <em>foo_lib.<\/em><\/li>\n<li>In the Obfuscation tab uncheck \"<em>Use mixed-case class names.<\/em>\"<\/li>\n<li>Keep the default settings for now (you can tweak them later once you have this working).<\/li>\n<li>Start processing the JAR. &nbsp;In the&nbsp;<em>Process<\/em> tab click&nbsp;<em>Process!<\/em><\/li>\n<li>If ProGuard finishes it will produce a nice obfuscated\/shrunk JAR, <em>output.jar<\/em>.<\/li>\n<\/ol>\n<h2>Combine library dependencies into obfuscated JAR<\/h2>\n<ol>\n<li>The&nbsp;<em>output.jar<\/em> is not runnable as is. &nbsp;It needs to know how to find the library dependencies. &nbsp;You can pack the dependencies into the JAR with <a href=\"http:\/\/www.7-zip.org\/\">7-zip<\/a>. &nbsp;So, open <em>output.jar<\/em> in 7-zip.<\/li>\n<li>Add\/drag the contents of&nbsp;<em>foo_lib<\/em> (from step 2 in the first section) into the root level of the JAR (e.g. they should be in the same directory <em>META-INF<\/em> is in).<\/li>\n<li>Extract the other JAR from the first section (see step 4) into a temp directory (e.g. <em>temp<\/em>).<\/li>\n<li>In <em>output.jar<\/em>, clobber the file \"<em>META-INF\/MANIFEST.MF\"&nbsp;<\/em>with the file from <em>\"temp\/META-INF\/MANIFEST.MF\"<\/em>.<\/li>\n<li>In&nbsp;<em>output.jar<\/em>, add the directory <em>\"org\/eclipse\"<\/em> from&nbsp;<em>\"temp\/org\/eclipse\"<\/em>.<\/li>\n<li>Confirm the JAR is runnable: <em>java -jar output.jar<\/em><\/li>\n<\/ol>\n<h2>Wrap your JAR in a Windows executable<\/h2>\n<ol>\n<li>Use <a href=\"http:\/\/launch4j.sourceforge.net\/\">Launch4j<\/a> to wrap your JAR. &nbsp;Open the Launch4j GUI.<\/li>\n<li>Add your output file: <em>out.exe<\/em><\/li>\n<li>Add your input JAR file: <em>output.jar<\/em><\/li>\n<li>In the <em>JRE<\/em> tab, set the <em>Min JRE version<\/em> (e.g. 1.6.0)<\/li>\n<li>Click the gear icon to build the wrapper.<\/li>\n<li>Confirm the binary works. &nbsp;<strong><em>High Fives all Around!<\/em><\/strong><\/li>\n<\/ol>\n<div>&nbsp;<\/div>"}}
comments powered by Disqus
 

Lorem Ipsum

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Lorem

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

 
This page is best viewed with Firefox 3.5+, Chrome 5+, Safari 5+, Opera 10.6+, IE 9+
Copyright © 2014 8bitrobot.com