我是 PhoneGap 的老手(版本:3.4)。目前我的项目结构如下:
.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)覆盖,所以我创建了一个merges/android
我的自定义 Android 资产的目录。
index.js 的内容(基础):
var app = {
selectDevice: function() {
window.alert('using default');
},
initialize: function() {
document.addEventListener("deviceready", this.selectDevice, false);
}
};
index.js 的内容(要合并):
var app = {
selectDevice: function() {
window.alert('using android');
},
initialize: function() {
document.addEventListener("deviceready", this.selectDevice, false);
}
};
index.html 的内容(每个平台唯一且通用的 html 文件):
<!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 文件,因此它们存在于存储库中 - 对于当前为空的平台目录尤其如此)。
但是,当我将内容推送到我的存储库并拉取并重建时http://build.phonegap.com http://build.phonegap.com,我有两种情况:
- 在第一次尝试中,我没有创建
index.js
文件位于基本 www 目录中,但仅位于 merges/android 目录中。结果:文件丢失(即它的内容,这是在 deviceReady 事件中显示的警报 - 告诉当前平台是 android - 从未执行,后续代码也没有执行 - 消息:初始化已运行 - 这是结果的一个ReferenceError
当试图打电话时app.initialize()
).
- 在第二次尝试中,我创建了
index.js
为默认值www/js
当没有文件被合并时。结果:打印的消息是“使用默认值”。
我的结论:该文件从未合并。
我的问题: 为什么?我是否应该创建一个显式的platforms/android目录(好吧:platform)以便合并我的文件?或者当我告诉重建 Android 应用程序时,build.phonegap.com 应该自动执行此操作吗?
我在这里缺少什么?