I would like to pack my firefox extension as xpi file. I tried by adding it to archive and name it as filename.xpi
But when i try to install it on firefox am getting "package corrupted" message. Is there any way i can create a valid xpi file ?
I have installed cygwin and tried to execute zip command to create xpi file. But got zip is not a command error.
Can somebody guide me to get it done ?
Also, here's how I pack an extension for Firefox with command line 7z:
(where 'a' stands for "add/create" and "-r" for recursive)
Or to update the extension with the file(s) we just edited:
("u" for update the archive's content)
Do as per the following while using 7z Select only the inner contents and not the outer folder. Enter the filename as filename.xpi and choose archive format as zip in the prompt that appears while zipping. You will find a valid xpi file created. Use the created xpi for installing your extension on firefox. It works!
If you are on windows (to install cygwin it looks like you do), you can use the windows built in tool:
Then just replace the .zip for .xpi in the filename
Looks like your problem is on completing the point 1. correctly. Select only the contents of the extension. Not the folder that contains it.
So basically your zip file should have following structure:
and NOT this structure:
Two methods, using the GUI 7zFM.exe, or a command line or batch file.
1.0) GUI method. Assuming 7-Zip is installed with shell integration so you see 7-Zip show up in the context-menu (right-click of selected files) of Windows Explorer.
1.a) Go into the folder of your add-on.
1.b) Select all the files and folders you want to include in the .xpi. Assuming you don't have any files you want to ignore down in any sub-folders. If you do, you might want to use the command line option.
1.c) Right-click on the list of selected files, find the
7z
icon, choose theAdd to archive...
option.1.d) A dialog pops up. Edit the location and name of the zip file, change to .zip to .xpi, etc.
1.e) Note if you create the .xpi in the same folder, don't re-archive it in the future, as your add-on will fail horribly. You never want an .xpi ending up inside your .xpi by accident. I usually just create it in the parent folder, by adding
..\
to the beginning of the file name, e.g...\addon-1.2.3-fx.xpi
1.f) 7-Zip has a lot of powerful compression options, not all of which Firefox can handle. Choose settings which Firefox is able to process. Refer to image.
2.0) Command Line method. Assuming you're in Windows, and know how to open a command prompt, change drives and directories (a.k.a. folders).
2.a)
CD
to your add-on directory.2.b) Use the most basic 7-Zip command line.
"C:\Program Files\7-Zip\7z.exe" a -tzip addon-1.2.3-fx.xpi *
2.c) You can get a smaller file by finding the exact command line options which correspond to the above GUI, namely:
"C:\Program Files\7-Zip\7z.exe" a -tzip -mx=9 -mm=Deflate -mfb=258 -mmt=8 "addon-1.2.3-fx.xpi" *
Note that there is no Dictionary size = 32kb option when using Deflate Compression method. Otherwise, the options are in order and correspond to the GUI.
Notes:
i) The multi-thread option (-mmt=8) is specific to my system which has 8 cores. You will need to lower this to 6 or 4 or 2 or 1 (i.e. remove option) if you have fewer cores, etc, or increase if you have more. Won't make much difference either way for a small extension.
ii) The option to recurse into folder may or may not be the default, so specifying this option should ensure proper recursion.
iii) The option to
preserve windows timestamps
(creation, access, modification) should default toon
anyways, so may not be needed.iv) The
ignore files in list
option is any file which has a list of files and wildcards of files you wish to exclude.2.d) Advanced topic #1: ignore file list (examples)
"C:\Program Files\7-Zip\7z.exe" a -tzip -mx9 -mm=Deflate -mfb=258 -mmt=8 -mpass=15 -mtc=on "addon-1.2.3-fx.xpi" * -x@ignore.txt
2.e) Advanced topic #2: Batch file (Windows CMD.EXE), assuming fairly recent windows, i.e. from the 21st century. This can be as simple and rigid, or complex and flexible as you care to make it. A general balance is to assume you will be in the
Command Prompt
, in the top level directory of the add-on you are working on, and that you have intelligently named that directory to have the same basename of the .xpi file e.g.D:\dev\addon-1.2.3-fx
directory for theaddon-1.2.3-fx.xpi
add-on xpi. This batch file makes this assumption, and dynamically figures out the correct basename to use for the .xpi.Just zip all the files and folders inside my_extension folder and change the resulting zipped file's extension to my_extension.xpi
Installation of xpi file created from zipped file of my_extension folder will result error as
"This add-on could not be installed because it appears to be corrupt." error
I experienced the same problems today and found the error to be that the add-on was obviously not signed by Mozilla, causing Firefox to refuse the installation. Up until recently, it was possible to by-pass this security check by setting
xpinstall.signatures.required
to false inabout:config
. However, as of Firefox 46, signing is mandatory and no by-pass is provided any longer, see https://blog.mozilla.org/addons/2016/01/22/add-on-signing-update/ This means that one has to either downgrade to a previous version or use a non release channel version to test one's addons :(