When compiling a cordova application every single file in my /www
folder gets copied to the assets/www
folder(android) but I'd like to customize what files are copied. I use several pseudo languages like CoffeeScript, Jade or Stylus which are auto-compiled by my IDE and they shouldn't be shipped into the final application.
With the help of this article, I found that you can create/edit the platform/android/ant.properties
, and add the following line to it:
aapt.ignore.assets=!*.map:!thumbs.db:!.git:.*:*~
With this line, any file or directory that matches one of these patterns will not be included in the .apk file:
*.map
thumbs.db
.git
.*
*~
I found that editing the platforms/android/build.xml
won't work because it's overwritten each time the build is invoked; also, creating a build.xml
file in the root of the project didn't work.
The rules for this property are the following, taken from $ANDROID_HOME/tools/ant/build.xml
:
<!-- '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.
-->
<property name="aapt.ignore.assets" value="" />
I highly recommend cordova-plugin-exclude-files. You simply specify files to exclude as pattern
attributes of exclude-files
tags in your config.xml
file.
For example, to exclude all .scss
files:
<exclude-files pattern="**/*.scss" />
And to exclude all files with the string "ios-only" on the Android platform only:
<platform name="android"> <exclude-files pattern="ios-only" /> </platform>
All hidden files and folders will be ignored while build for example .git/
& .gitignore
To hide : Rename the folder by a .
(dot) prepended to the folder/file name.
Use Terminal in Linux/Mac to rename the folder.
mv dev .dev
Use cmd in Windows
ren dev .dev
I do not know any way how to filter files for cordova, but I can describe you approach that we use in our projects.
We are using gruntjs with phonegap plugin. We configure it to use prebuilt folder (which contains only necessary files and folders) and it:
Main thing in this approach is that cordova/phonegap project (directory with .cordova, platforms and www folders) is just a build artefact.
Here is relevant part of our Gruntfile.js as an example:
phonegap : {
config : {
root : './out/dist',
config : {
template : './config.tpl.xml',
data: {
id: pkg.id,
version: pkg.version,
name: pkg.name,
author : pkg.author
}
},
path : 'out/phonegap',
plugins : [
// PHONEGAP OFFICIAL PLUGINS
'org.apache.cordova.globalization',
'org.apache.cordova.network-information',
'org.apache.cordova.splashscreen',
//THIRD-PARTY PLUGINS
'de.appplant.cordova.plugin.local-notification'
],
platforms : [
'android'
],
maxBuffer : 200, // You may need to raise this for iOS.
verbose : false,
releases : 'out/releases',
releaseName : function() {
return pkg.name + '-v' + pkg.version;
},
// Android-only integer version to increase with each release.
// See http://developer.android.com/tools/publishing/versioning.html
versionCode : function() {
return 1;
}
}
}
Note, out/dist is generated by previous build step and contains concatenated and minified version of code.
I've created a custom script to ignore files/folders which works not just for android:
Add this to your config.xml:
<ignore entries="lang,foo/bar,ignore/asdf.html" />
And you need two more files located in hooks/before_build and hooks/after_build folders.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With