ogxpdg
Last Updated: February 25, 2016
·
8.235K
· gavd
1f38abf717939e78cb7d64c8d3dd19a2

Exclude files from Cordova/Phonegap build (Android)

I have some Cordova projects that I include libraries in as Git submodules. This means a lot of cruft (example files, etc) comes along with my build!

Thankfully, I can edit the ant build.xml in the root of my project. Let's prove the concept and break our app!

<?xml version="1.0" encoding="UTF-8"?>
<project name="fhsurveyor" default="help">

    <!-- The local.properties file is created and updated by the 'android' tool. 
         It contains the path to the SDK. It should *NOT* be checked into
         Version Control Systems. -->
    <property file="local.properties" />
        <property name="aapt.ignore.assets" value="&lt;dir&gt;jQ.Mobi/examples:!.svn:!.git:.*:&lt;dir&gt;_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" />
....

This means any file called index.html won't be loaded onto the device. So more usefully, here's what I used to omit my /lib/ directory (which gets compiled into a single JavaScript) from my app:

....
   <property name="aapt.ignore.assets" value="&lt;dir&gt;lib:!.svn:!.git:.*:&lt;dir&gt;_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" />
....

If you look in {Android home}/tools/ant/build.xml, you can see the full documentation for this:

'aapt.ignore.assets' is the list of file patterns to ignore under /res and /assets.
     Default is "!.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~"

     Overall patterns syntax is:
       [!][<dir>|<file>][*suffix-match|prefix-match*|full-match]:more:patterns...

     - The first character flag ! avoids printing a warning.
     - Pattern can have the flag "<dir>" to match only directories
       or "<file>" to match only files. Default is to match both.
     - Match is not case-sensitive.
Say Thanks
Respond

1 Response
Add your response

4550
0b3a0d3d88f3505a7bc1aa52e9cad99f

Thanks.

After a few attempts with the search keywords on Google, I found this as the #1 result (http://www.google.com/search?q=phonegap+android+assets+exclude) and this is exactly what I wanted!

Phonegap for android and iOS with git submodules and requirejs optimization!

over 1 year ago ·