Cordova Build - 忽略文件

ola*_*nod 10 android cordova cordova-3

编译cordova应用程序时,我/www文件夹中的每个文件都被复制到assets/www文件夹(android),但我想自定义要复制的文件.我使用了几种伪语言,如CoffeeScript,Jade或Stylus,它们由我的IDE自动编译,不应该发送到最终的应用程序中.

gus*_*nke 7

本文的帮助下,我发现您可以创建/编辑platform/android/ant.properties,并向其添加以下行:

aapt.ignore.assets=!*.map:!thumbs.db:!.git:.*:*~
Run Code Online (Sandbox Code Playgroud)

使用此行,匹配其中一个模式的任何文件目录都不会包含在.apk文件中:

  • *.map
  • thumbs.db
  • .git
  • .*
  • *~

我发现编辑platforms/android/build.xml 将不起作用,因为每次调用构建时它都会被覆盖; 此外,build.xml在项目的根目录中创建文件不起作用.

该属性的规则如下,取自$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="" />
Run Code Online (Sandbox Code Playgroud)


And*_*iov 2

我不知道如何过滤科尔多瓦文件,但我可以描述我们在项目中使用的方法。

我们使用gruntjsphonegap插件。我们将其配置为使用预构建的文件夹(仅包含必要的文件和文件夹),并且它:

  • 创建 cordova/phonegap 项目
  • 添加插件、平台
  • 构建本机应用程序
  • 在模拟器上启动本机应用程序

这种方法的主要内容是 cordova/phonegap 项目(包含 .cordova、platforms 和 www 文件夹的目录)只是一个构建工件。

以下是我们的Gruntfile.js的相关部分作为示例:

  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;
        }
     }
  }
Run Code Online (Sandbox Code Playgroud)

请注意,out/dist 是由之前的构建步骤生成的,包含代码的串联和缩小版本。