[Miscellaneous Android Development] MrRusch:
OK, so I'm just gonna throw this one out there as a feeler..

When porting packages from other devices, I've found myself modifying Smali reference IDs for ages. The goal being to get the references in a foreign package to reference the correct resource in e.g. the BASE framework-res.apk.

Finally, I got really fed up, and automated the process. The result is this very alpha SmaliRefSwapper JAR. Instead of spending endless hours of cutting and pasting references until your eyes bleed, this code does most of the process for you in a matter of seconds.

Now I'm trying to figure out if this is something which would be of interest to developers. If not I probably won't put much more work into this. So let me know what you think - yey or nay!

Definitions

BASE framework = framework-res.apk in the ROM you are trying to port the foreign package

to

.

BASE package = the APK in the ROM you are trying to port the foreign package code

to

.

PORT framework = framework-res.apk in the ROM you are trying to port the foreign package

from

.

PORT package = the APK in the ROM you are trying to port the foreign package

from

.

Preparations

You can place the files wherever you want, but for simplicity, I have provided a folder structure and instructions relative to this.

1. Place the Smali files (package.apk/smali/*) from the PORT package into SmaliRefSwapper/smali

2. Place the XML files (package.apk/res/values/*) from the BASE package into SmaliRefSwapper/xml/base/package_values

3. Place the XML files (framework-res.apk/res/values/*) from the BASE framework into SmaliRefSwapper/xml/base/framework-res_values

4. Place the XML files (package.apk/res/values/*) from the PORT package into SmaliRefSwapper/xml/port/package_values

5. Place the XML files (framework-res.apk/res/values/*) from the PORT framework into SmaliRefSwapper/xml/port/framework-res_values

If there is no XML in the BASE or PORT package, place a dummy public.xml file in these folders.

Usage Instructions

Run the JAR (through terminal to obtain some logs) and select the appropriate folders.

The output will be two folders:

SmaliRefSwapper/smali_new

SmaliRefSwapper/xml_new

smali_new content goes into the PORT package before recompilation. In it, all Smali references have been replaced with the correct reference from the BASE framework/package.

xml_new contains two folders:

SmaliRefSwapper/xml_new/framework-res

SmaliRefSwapper/xml_new/package

framework-res files contain references which should be added to the respective XMLs in the BASE framework before recompilation (e.g. public.xml content should be added to framework-res.apk/res/values/public.xml). In certain cases, for example when drawable references have been added, it is necessary to manually fix the dependencies they may infer (e.g. adding a PNG file from the PORT framework-res/package).

xml_new may also contain a UNHANDLED.xml, which lists references that could not be found in either PORT framework-res or package. In most cases these are hardcoded hexadecimal values, such as colors or numbers.

After recompiling the BASE framework with the new XML, and the PORT package with the new Smali and XML, it should be safe to include the PORT package in the BASE ROM.

Download

SmaliRefSwapper Alpha

Please

do not

mirror my work!