Phonegap合并目录-资产未合并 [英] Phonegap merge directories - assets not being merged

查看:77
本文介绍了Phonegap合并目录-资产未合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在PhoneGap上总计为n00b(版本:3.4).目前,我的项目结构如下:

I'm a total n00b at PhoneGap (version: 3.4). Currently I have a project structure like:

.cordova
+---config.json
hooks
+---README.md
merges
+---android
    +---js
        +---index.js
platforms
+---.gitkeep
plugins
+---org.apache.cordova.device (content: the plugin sources, doc, and data)
+---android.json (content: plugins config for android)
www
+---css (content: many assets here)
+---img (content: many assets here)
+---js (content: many assets here, siblings of index.js)
    +---index.js (a default file intended to be overriden by the merged index.js file)
+---res (content: resources for splashscreen and stuff configured in config.xml)
+---index.html
+---config.xml
+---icon.png

我的意图是让许多文件被平台特定文件(在本例中为android)覆盖,因此我为自定义android资产创建了merges/android目录.

My intention is to have many files being overriden by platform specific files (in this case, android), so I created a merges/android directory for my custom android assets.

index.js的内容(基本):

Contents of index.js (base):

var app = {
    selectDevice: function() {
        window.alert('using default');
    },
    initialize: function() {
        document.addEventListener("deviceready", this.selectDevice, false);
    }
};

index.js的内容(合并):

Contents of index.js (to-merge):

var app = {
    selectDevice: function() {
        window.alert('using android');
    },
    initialize: function() {
        document.addEventListener("deviceready", this.selectDevice, false);
    }
};

index.html的内容(每个平台的唯一html文件):

Contents of index.html (the only-and-common html file for every platform):

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <script type="text/javascript" src="phonegap.js"></script>
        <title>1001Carros</title>
    </head>
    <body>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
            window.alert('initializing...');
            app.initialize();
            window.alert('initialization was run.');
        </script>
        <div id="log">
            <button id="clickme" value="Click Me"></button>
            pantalla principal
        </div>
    </body>
</html>

我在这里详细介绍的文件系统结构是我当前存储库的状态(注意:空文件夹具有虚拟.gitkeep文件,因此它们存在于存储库中-对于平台目录(当前为空)尤其如此).

The filesystem structure I detailed here is the state of my current repository (notes: empty folders have dummy .gitkeep files so they exist in the repository - this is specially true for the platforms directory, which is currently empty).

但是,当我将内容推送到仓库中并在 http://build.phonegap.com中进行拖放重建时,我有两种情况:

However, when I push my contents to my repo and pull-and-rebuild in http://build.phonegap.com, I had two scenarios:

  1. 在第一次尝试中,我没有在基本的www目录中创建一个index.js文件,而是在merges/android目录中创建了一个文件.结果:文件丢失(即它的内容,这是在deviceReady事件中显示的警报-告诉当前平台是android-,从未执行过,随后的代码也未执行-message:初始化运行了,这就是结果)尝试调用app.initialize()ReferenceError的内容).
  2. 在第二次尝试中,当没有文件合并时,我将index.js创建为www/js下的默认值.结果:打印的消息是使用默认值".
  1. In the first try, I did not create an index.js file in the base www directory, but just in the merges/android directory. Result: the file was missing (i.e. it's content, which was an alert being shown inside the deviceReady event -telling that the current platform is android- was never executed, and subsequent code neither -message: initialization was run-, which is the result of a ReferenceError when trying to call app.initialize()).
  2. In the second try, I create the index.js to be the default under www/js when no file was merged. Result: the message printed was 'using default'.

我的结论是:文件从未合并.

My conclusion: the file was never merged.

我的问题:为什么?我是否应该创建一个显式的platform/android目录(好:platform)以便合并我的文件?还是当我告诉我重建Android应用程序时,build.phonegap.com应该自动执行该操作吗?

My question: Why? Should I create an explicit platforms/android directory (well: platform) in order to get my files merged? or should build.phonegap.com do it automatically when I tell to rebuild the android application?

我在这里想念什么?

推荐答案

merges文件夹用于图像或css之类的资源,在我看来,这对于整个JS而言意义不大.相反,我建议您添加设备插件,并针对"android"在这些平台上针对其他行为对device.platform进行测试.

The merges folder is meant for ressources like images or css, not that much for entire JS in my opinion. Instead, I advise you to add the Device plugin and test device.platform against "android" for a different behaviour on those platforms.

http://docs.phonegap.com/zh/3.0.0/cordova_device_device.md.html#device.platform

您询问是否应创建platform/android目录.这是一个奇怪的问题,因为如果您这样做正确,则应使用build命令,并且该目录应由其自己创建!然后在platform/android/assets/www中,您应该找到已合并的文件,而没有其他地方.

You asked if you should create a platform/android directory. This is a weird question because if you are doing this right, you should be using the build command and that directory should be created by itself! Then in the platform/android/assets/www you should find your files merged, nowhere else.

这篇关于Phonegap合并目录-资产未合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆