简体   繁体   English

Phonegap构建cordova.js

[英]Phonegap build cordova.js

I am developing Phonegap Build application. 我正在开发Phonegap Build应用程序。 For the android file,when I try to compile the zip file, the APK file always contain 3 javascript file:phonegap.js cordova.js ... Yet the three files are of exactly the same content. 对于android文件,当我尝试编译zip文件时,APK文件始终包含3个javascript文件:phonegap.js cordova.js ...但是这三个文件的内容完全相同。 How can I remove the two redundant js file in order to optimize my application? 我如何删除两个冗余js文件以优化我的应用程序?

FYI the reason the redundant files are present is to avoid user confusion according to the devs : 仅供参考, 根据开发人员的说法,存在冗余文件的原因是为了避免用户混淆:

Many users were including the wrong file. 许多用户包括错误的文件。 Allowing inclusion of any of the above avoided a lot of confusion -- enough to outweigh the footprint of two extra files, in our opinion. 允许包含上述任何内容避免了很多混乱-我们认为这足以超过两个额外文件的占用空间。

Now that PhoneGap 2.8 introduced cordova.js without the version number in the filename, there is a low-priority issue being tracked to remove the redundant files (so if you just wait, it might be fixed soon on its own): 现在,PhoneGap 2.8引入了cordova.js ,但文件名中没有版本号,因此跟踪了一个低优先级问题,以删除冗余文件(因此,如果您只是等待,它可能很快会自行修复):

Enhancement: PhoneGap 2.8 introduce cordova.js without version number. 增强功能:PhoneGap 2.8引入了不带版本号的cordova.js。 Build could now exclude redundant .js files. 现在,构建可以排除冗余的.js文件。


But , if you aren't willing to wait for them to upgrade the build process, you can remove the files yourself following these instructions: 但是 ,如果您不想等待他们升级构建过程,则可以按照以下说明自行删除文件:

1 . 1 Unpack the APK files into a local directory structure using apktool (you'll need the Android and Java SDKs installed on your machine) - instructions here on how to unpack and remove files : 使用apktool将APK文件解压缩到本地目录结构中(您需要在计算机上安装Android和Java SDK)- 有关如何解压缩和删除文件的说明

$ \path\to\AndroidSDK\platform-tools\apktool d myApp.apk

2 . 2 Remove the phonegap.js and cordova-xxxjs files (these are the unused ones in > 2.8.0). 删除phonegap.jscordova-xxxjs文件(> 2.8.0中未使用的文件)。

3 . 3 Repackage the APK, again using apktool : 重新apktool APK,再次使用apktool

$ \path\to\AndroidSDK\platform-tools\apktool b myApp myAppUnsigned.apk
  • note at this point that the APK isn't signed, and therefore can't be deployed to the Play Store or any devices which doesn't allow apps from unsigned sources. 请注意,此时APK尚未签名,因此无法部署到Play商店或任何不允许来自未签名来源的应用的设备。

4 . 4 Re-sign the APK file using your android cert so it's valid: 使用您的Android证书重新签署APK文件,以便它是有效的:

Sign the apk using the jarsigner tool that's part of the Java JDK. 使用Java JDK中的jarsigner工具对apk进行签名。 You'll also need your keystore and key alias that you used to sign the app, as well as the password. 您还需要用于签名应用程序的密钥库和密钥别名以及密码。

jarsigner -verbose -keystore ~/MySigningKey.keystore ~/Desktop/myAppUnsigned.apk myKeyAlias

Enter Passphrase for keystore:

After you enter your passphrase, you'll see a whole bunch of 'signing:' messages zoom by; 输入密码后,您会看到一堆“签名:”消息放大; once it's all done, you have a signed apk file. 完成后,您将拥有一个已签名的apk文件。

5 . 5 The last step is to zipalign the apk file: 最后一步是zip对齐apk文件:

zipalign -v 4 myAppUnsigned.apk myApp.apk

And you should be done. 并且应该完成。 You could automate all these steps into a batch/shell script for ease of use when building files. 您可以将所有这些步骤自动化到批处理/ shell脚本中,以便在构建文件时易于使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM