gpt4 book ai didi

cordova - Phonegap 合并目录 - Assets 未合并

转载 作者:行者123 更新时间:2023-12-02 00:15:19 24 4
gpt4 key购买 nike

我是 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)覆盖,因此我为自定义 Android Assets 创建了一个 merges/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 中进行拉取和重建时,我有两种情况:

  1. 在第一次尝试中,我没有在 www 基本目录中创建 index.js 文件,而是在 merges/android 目录中创建。结果:文件丢失(即它的内容,这是在 deviceReady 事件中显示的警报 - 告诉当前平台是 android - 从未执行,后续代码也没有执行 - 消息:初始化已运行 - 这是结果尝试调用 app.initialize() 时出现 ReferenceError)。
  2. 在第二次尝试中,当没有合并文件时,我将 index.js 创建为 www/js 下的默认值。结果:打印的消息是“使用默认值”。

我的结论:该文件从未合并。

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

我在这里缺少什么?

最佳答案

merges 文件夹适用于图像或 css 等资源,在我看来,不适用于整个 JS。相反,我建议您添加设备插件并针对“android”测试 device.platform 在这些平台上的不同行为。

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

您询问是否应该创建 platform/android 目录。这是一个奇怪的问题,因为如果你做得正确,你应该使用 build 命令,并且该目录应该由它自己创建!然后在 platform/android/assets/www 中,您应该会发现您的文件已合并,而不是其他地方。

关于cordova - Phonegap 合并目录 - Assets 未合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24540972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com