简体   繁体   中英

Phonegap build cordova.js

I am developing Phonegap Build application. 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. How can I remove the two redundant js file in order to optimize my application?

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):

Enhancement: PhoneGap 2.8 introduce cordova.js without version number. Build could now exclude redundant .js files.


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 . 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 :

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

2 . Remove the phonegap.js and cordova-xxxjs files (these are the unused ones in > 2.8.0).

3 . Repackage the APK, again using 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.

4 . Re-sign the APK file using your android cert so it's valid:

Sign the apk using the jarsigner tool that's part of the Java JDK. 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.

5 . The last step is to zipalign the apk file:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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