• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

[HOW-TO]Make your own flashable zip (KitKat edition)

Status
Not open for further replies.
Welcome, this thread was created to help new-ish (or even seasoned) developers make their own flashable zips. One thing to note about this tutorial is that the zips you create can only be flashed using a custom recovery, so bear that in mind. And, without further ado

Setup
Mac, Unix, and Linux
Lucky for you guys, your system comes with everything you need.

Windows
While ROM Developing is something you normally associate with Linux or Mac, a great majority of it can be done on Windows, with the help of a couple of programs.
  • Notepad++ is a very versitile text editor. It has support for syntax highlighting in many different programming languages. More importantly though, it has support for Lunux/Unix line endings (even on Windows). That being said, anything related to your zip [B}MUST[/B] be done using Notepad++ (or any other text editor that supports Linux/Unix line endings)
  • 7-Zip is one of the most powerful archive managers I have ever used. While this is not a requirement if you are on Windows, it will make your life so much easier. One thing I do suggest doing once you install 7-Zip is to go to Tools > Options > Editor and set your default editor as Notepad++, so that when you want to edit a file, you can just right-click it and hit edit or just hit F4 on your keyboard.

So, now that we got the Windows users up to pace with everyone else. You may be asking yourself, where on Earth do I even start with all this stuff? Well, thankfully I have created a skeleton that you can use to get started.


Download
The skeleton.zip can be downloaded from my Google Drive.
Link: http://goo.gl/iDlGWP
QR Code:
chart



Language
Just for reference, in case you want to look up some more tutorials on this stuff, the scripting language used in Android Update Scripts is called Edify. Now, there are a few guidelines with Edify
  • You cannot have empty lines in your script, this will cause the script to terminate early
  • Your script must end with an empty line, this is how Edify knows that it has reached the end of the script.
  • You can only insert a tab at the beginning of a line if that line is a continuation of a command from the previous line
  • You can only continue a command line on the next line if you have reached an argument seperator (a comma).
  • Every command must end with a semicolon.
  • Every argument with select exceptions (will be mentioned below) must be enclosed in double quotes (")

I know this sounds really difficult, but it is really easy once you get started.


Scripting Commands
Just like every programming/scripting language, Edify has a set of built-in commands for you to use.

The mount command
The mount command is used to mount partitions, so you can write information to them. The syntax for this command is:
mount("fs_type", "partition_type", "device", "mount_point");
The arguments for this command are:
  • fs_type: Is the filesystem for the partition, such as ext4 or vfat
  • partition_type is the type of partition, this will almost always be MTD or EMMC. One trick to know which it is, is to look at the partition. If it begins with/dev/block, then it is most likely EMMC, otherwise, it is probably MTD
  • device refers to the partition itself, such as /dev/block/mmcblk0p19
  • mount_poiint is where you want to mount the partition, such as /system

The unmount command
The unmount command is very important, either once you finish writing a partition; or when you finish your script, you should unmount the partitions you used, so the user doesn't get errors from their recovery. Syntax is:
unmount("mount_point");


The format command
Writing data doesn't do much good if you are just adding to the data that's already there right? Well the format command can help with that. This command will delete all of the data on a partition. You must always format a partition while it is not mounted. If you try to format a partition while it is mounted, you will generate an error. The syntax for the format command is:
format("fs_type", "partition_type". "device", "size", "mount_point");
The only new parameter here is size, and size has many options:
  • If size is 0, then the entire partition will be used
  • If you set size to be a POSITIVE number, then the filesystem will be the size you specify, assuming it does not go past the bounds of the partition
  • If you set size to be a NEGATIVE number, then that many bytes will be left at the end of the partition and the rest will be used.

The is mounted function
Sometimes, things get complicated, and you need to unmount a partition in the middle of a script, but you need to make for SURE that it is unmounted, this command will help you do that. The is mounted function will return true if a partition is mounted, and false if it isn't. The syntax is:
is_mounted("mount_point");
One thing I should mention, Edify doesn't have if statements. There is a way to do logic, but I will cover that later.


The rename function
The rename function allows you to rename a file or directory. The syntax is:
rename("old_name". "new_name");
So, if I wanted to rename /system/app to /system/apps, I would do
rename("/system/app", "/system/apps");


The delete function
The delete function is used to delete files or directories, delete is kinda strange though, because it has two syntaxes. First:
delete("path");
will delete the file or directory specified (if it is a directory, it can only be deleted if empty). Second:
delete_recursive("path");
will delete a directory and everything contained in that directory.


The show progress function
Show progress is used to update the progress bar found on the recovery screen. This function will add the value you tell it to to the progress bar in the amount of time specified. This does NOT affect how fast your script will execute. The syntax is (note the arguments for this function are NOT in quotes):
show_progress(frac, time);
An example of this is:
show_progress(0.1, 5)l
The function shown here will ADD 10% to the progress bar and the bar will grow for 5 seconds.


The set progress function
The set progress function works a little differently than the show progress function. As you can imagine, this will not add to the progress, but it will set the progress. Syntax is (again arguments are not in quotes):
set_progress(frac);
An example:
set_progress(1.0);
will set the progress to 100% instantly.


MORE COMING SOON....
 
Status
Not open for further replies.

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones