[Galaxy Y GT-S5360 General] powerpenguin:
System apps during ROM building

Hi,

If anyone is interested, I'm using a little script to extract libs from apks in the following workflow to update my ROMs:

(script only tested on linux)

pull apks from phone

run script on apks

copy the dirs generated to /system/lib/ (either on your phone or in your kitchen ROM tree) for all system apps where applicable

if baking ROM in kitchen, copy the lines from generated update-add.txt in the updater-script (if directly on phone, symlink the actual .so files to /system/lib)

The reason for the subdirs and symlinking is maintainability. This way, if you want to update or remove a system apps, you can simply remove the associated lib dir (which has the app name) under /system/lib

apklibupdater.apk:

#! /usr/bin/perl -w

# apklibupdate2.pl 2011-09-11 by ppenguin
# Evaluates apk files in argument and extracts relevant dynamic libraries.
# These libraries are extracted and should be put under system/lib/<package>/<orig-lib-path>/
# The script outputs a list of commands to be copied in the updater-script of the ROM, which
# symlinks the libraries as needed in /system/lib/.
# This improves ROM maintenance, because it keeps /system/lib/ uncluttered and easy to maintain.

use Cwd;
use IPC::System::Simple qw(capture EXIT_ANY);
use File::Path qw(remove_tree);
use File::Basename;

my(@APKs) = @ARGV;
my($aapt) = "aapt d badging";
my($pn, $vn, $lb, @ai, $fn, $fs);
my (@res, $ret, @lfs);

my $cs = ",";

open (UPDADD, '>>update-add.txt');

foreach (@APKs) {
# print "about to exec " . $aapt . " " . $_ . "\n";
@ai = qx($aapt $_);
$fn = $_;
# $fs = -s $fn;
# $fs = fs2hr($fs);

foreach (@ai) {
if ($_ =~ /.*package: name=\'(.*?)\'.*versionName=\'(.*?)\'.*$/) {
$pn = $1;
$vn = $2;
}
if ($_ =~ /.*application: label=\'(.*?)\'.*/) {
$lb = $1;
}
}
mkdir $pn;
my $pwd = getcwd;
chdir $pn;
@res = qx(unzip $pwd/$fn lib/armeabi/*);
# print "Unzip returned: @res\n";
chdir $pwd;
@lfs = qx(ls $pn/lib/armeabi/*);
# print "pwd=".getcwd." ls $pn/lib/armeabi*\n";
# print "LSLSLSLS:". @lfs . "\n";
if (@lfs > 0) {
foreach (@lfs) {
my $lffname = $_;
my $lfname = basename($lffname);
chomp $lfname;
chomp $lffname;
if (length $lfname > 0) {
print UPDADD "symlink(\"/system/lib/$lffname\", \"/system/lib/$lfname\");\n";
}
}
} else {
print "No library in apk!\n";
remove_tree($pn);
}
}

close UPDADD;

# this function from
# http://www.use-strict.de/articles/Perl__Filesize_in_a_human_readable_format.html
sub fs2hr {
my ($size) = @_;
if ($size > 1099511627776) {
return sprintf("%.2fT", $size / 1099511627776); # TiB: 1024 GiB
} elsif ($size > 1073741824) {
return sprintf("%.2fG", $size / 1073741824);	# GiB: 1024 MiB
} elsif ($size > 1048576) {
return sprintf("%.2fM", $size / 1048576);	# MiB: 1024 KiB
} elsif ($size > 1024) {
return sprintf("%.2fK", $size / 1024);	# KiB: 1024 B
} else {
return sprintf("%.2fB", $size);	# bytes
}
}

The script should be run like this:

$ cd mytemplibdir
$ apklibupdater.pl <kitchen_working_dir>/system/app/*.apk

If you are not baking a ROM but changing the phone directly, you can push the relevant apks to /system/app and all generated libdirs to /system/lib and do the symlinks. It is nearly trivial to modify the perl script such that update-add.txt will contain shell commands to automatically make the symlinks, which you could then run in an adb shell on the phone.