WebView Obfuscation Magic

Posted: June 29, 2009 in AndCooper, Android, Mobile
Tags: , ,

This is what the obfuscation prepaation ANT script code looks like:

<property name="assets-css-obfuscated" value="${assets-folder}/css-obfuscated"></property>
<property name="assets-js-obfuscated" value="${assets-folder}/js-obfuscated"></property>
<property name="assets-js-libs-compressed" value="${assets-folder}/js-libs-compressed"></property>
<property name="project-assets-css-libs" value="${basedir}/project-assets/css-libs"></property>
<property name="project-assets-js-libs-compressed" value="${basedir}/project-assets/js-libs-compressed"></property>
<property name="project-assets-temp-concat" value="${basedir}/project-assets/temp-concat"></property>
 <!--  The assumption is that during testing/dev we want the non obfuscated js/css files to 
 be real but the obfuscated oen sot be empty and reverse that for the 
 production/release. Thus prep step prepares an obfuscated empty file
 concat of the js-libs and the css files.  we assume
 that we plaqce js-libs-compressed libs in the folder
 <!-- Concat js-libs-compressed into one js-libs-3rdparty file-->
 <concat destfile="${project-assets-temp-concat}/js-compressed-3rdparty.js" force="no">
 <fileset dir="${project-assets-js-libs-compressed}" includes="**/*.js"></fileset>
 <!-- Move js lib file to assets -->
 <copy file="${project-assets-temp-concat}/js-compressed-3rdparty.js" todir="${assets-js-libs-compressed}"></copy>
 <!-- Produce an empty css-obfuscated file and a js-obfuscated file only empty for testing/dev -->
<property name="css-obfuscated-file-name" value="css-obfuscated-file-name.css"></property>
<property name="js-obfuscated-file-name" value="js-obfuscated-file-name.js"></property>
 <concat destfile="${project-assets-temp-concat}/${css-obfuscated-file-name}" force="no">
 <fileset dir="${project-assets-temp-concat}" includes="${css-obfuscated-file-name}"></fileset>
 <copy file="${project-assets-temp-concat}/${css-obfuscated-file-name}" todir="${assets-css-obfuscated}"></copy>
 <concat destfile="${project-assets-temp-concat}/${js-obfuscated-file-name}" force="no">
 <fileset dir="${project-assets-temp-concat}" includes="${js-obfuscated-file-name}"></fileset>
 <copy file="${project-assets-temp-concat}/${js-obfuscated-file-name}" todir="${assets-js-obfuscated}"></copy>
 <delete includeemptydirs="true">
 <fileset dir="${project-assets-temp-concat}"></fileset>

Than during the release.produciton target before the apkbuilder task you make empty css-not-obfuscated.css and js-not-obfuscate.js files and thus your import wil always be:

import css-non-obfuscated.css

import css-bofuscated.css

import js-non-obfuscate.js

import js-0obfuscated.js

import js-compressed-3rdparty.js

Notice that you will always have the import js 3rdparty compressed lib.  Because if you import an empty css or js file nothing happens it will always work right for both testing and production release because of the switching of which one is the empty file. Is not that a cool trick? And you never have to go through the html and change the damn imports every time.  Sure I could have threw together an ANT build script like everyone else but I thought it might be valuable to actually have an Android Build script that supports WebVuiew application development.

Is this trick used in the PhoneGap or QuickConnect or Rhomobile build scripts? Suprisingly, no in fact. This is the quality that needs  to go into a WebView application development book. However, I can not develop the book unless I have side Android App Development contracts. Now, some more details to finish than AndCooper Build Tool 0.1 release.

Reblog this post [with Zemanta]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s