Cordova Build - ignore files

一个人想着一个人 提交于 2019-12-03 06:16:24

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="" />

Hidden (.*) folder & files will be ignored by default

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.

To Rename a folder with .(dot) at start you may need CLI

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:

  • creates cordova/phonegap project
  • adds plugins,platforms
  • builds native applicaiton
  • launches native application on emulator

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.

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>

This is what I'm doing. I've moved the src files for the app that was in www folder to another folder created in root - web-app. Next, the following script was added in package.json :

This surely needs to be refined, but am working with it as makeshift arrangement.

Good Luck...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!