[Sony Ericsson XPERIA X10 Mini] Emperor.dk:
Easy but advanced apk-modding

Cyanogen has made this cool app called CMWallpapers.apk.

You will find the app in a lot of custom ROMs all over XDA, some modded and some not.

In this school we will modify the package id to avoid colission with any preinstalled version and change the content of the app.

See previous schools for how to open an APK and edit content.

Today we are building an Xperia S wallpaper app-pack.

Changing icon and app name

Opening the apk in APK Edit first shows the app icons and name.

To change the icons simply click them and select the one you want from the popup filemanager. I found the original stock icon from WallpaperPicker.apk in the Xperia S stock ROM. It's fine to use the 48x48 for both LDPI and MDPI.

The app and label name is changed to "Xperia S wallpapers".

Notice: This is only the english name. In order to change the name for other languages, we need to change a lot of XML-files. This is done easily using the "replace in all open documents" function in Notepad++.

Navigate to res/ and simply drag and drop all the "value-??" folders into Notepad++, press CTRL+H and replace "CyanogenMod" with "Xperia S" in all open documents (There is one big button to do it in all with one click), and then press CTRL+SHIFT+S to save all documents.

After that click the Apply button in APK Edit.

Changing the package-id

The package id is defined in AndroidManifest.xml

<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="10" android:versionName="2.3.7" [COLOR="Red"]package="com.cyanogenmod.CMWallpapers"[/COLOR]
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application android:label="@string/app_name" android:icon="@drawable/cyanogenmod_icon">
<activity android:label="@string/app_label" android:icon="@drawable/cyanogenmod_icon" android:name="wallpaper" android:screenOrientation="nosensor" android:finishOnCloseSystemDialogs="true">
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:label="@string/no_wallpaper" android:name="NoWallpaper">
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>

Here we can change "com.cyanogenmod.CMWallpapers" to "com.xperias.wallpapers"

IMPORTANT: When you change the package-id you will have to change alle references in all SMALI-files, and all folder-paths inside the apk, or the app will not work.

Inside the APK exists a folder-path to the SMALI-files:

smali\com\cyanogenmod\CMWallpapers

We must rename the foldes "cyanogenmod" and "CMWallpapers" to match our package-id.

In APK Edit we just navigate to "smali\com\" and rename the folder "cyanogenmod" to "xperias", and then navigate into "xperias" and rename "CMWallpapers" to "wallpapers".

The new folder-path to the SMALI-files will now be:

smali\com\xperias\wallpapers

Next we will open all SMALI-files and change any references to match the new package-id. There are a lot, so again you might use the replace in all open documents function in Notepad++

Save all documents and click the Apply button in APK Edit.

Making wallpaper files

One wallpaperfile consists of two files, the wallpaper itself, and a thumbnail, in the format:

wallpaper.jpg

wallpaper_small.jpg

For this app to work properly, the LDPI resolution should be 427x320, and the thumbnail should be 107x80.

The MDPI resolution should be 640x480, and the thumbnail should be 107x80.

I have prepared all the wallpaperfiles from the stock Xperia S ROM, i had to resize and crop some parts off.

The wallpapers in the stock Xperia S ROM is found in "system\etc\customization\content\com\sonyericsson\wallpaperpicker\wallpapers"

The wallpaper-files has to be placed in "res\drawable-ldpi" and "res\drawable-mdpi"

Place wallpaperfiles inside the APK

First we open the "res\drawable-ldpi" folder, and delete the existing wallpaper files.

Notice: Don't delete the icon-file!

Then we copy the resized/cropped Xperia S wallpaperfiles into the folder and click Apply.

Next we do the same for "res\drawable-mdpi" folder.

Edit arrays.xml

Inside "res\values" folder we got an XML-file with references to all the wallpaper-files. This has to be edited to match our new wallpaper-files.

At the upper part of the XML we got file-reference, this must match the filename without the ".jpg", and at the lower part of the list we got wallpaper discription/name.

Be very carefull when editing XMLs in Windows. You will very easily break the text encode if you copy from 3rd party text-editor into Notepad++. It's better just to type in everything manualy.

Result

After install of the modded app, we get an Xperia S wallpaper choise when pressing the Menu-button and tapping wallpaper.

We also get an option to select no wallpaper. If we want to get rid of this, we need to edit AndroidManifest.xml and remove the red part:

<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="10" android:versionName="2.3.7" package="com.xperias.wallpapers"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application android:label="@string/app_name" android:icon="@drawable/cyanogenmod_icon">
<activity android:label="@string/app_label" android:icon="@drawable/cyanogenmod_icon" android:name="wallpaper" android:screenOrientation="nosensor" android:finishOnCloseSystemDialogs="true">
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
[COLOR="red"] <activity android:label="@string/no_wallpaper" android:name="NoWallpaper">
<intent-filter>
<action android:name="android.intent.action.SET_WALLPAPER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
[/COLOR] </application>
</manifest>

And now, let me see some weekend mod-projects from all you newbies. I can't wait to se all your cool idears for app modding. I would realy like to see the Sony Ericsson Notes app with Google Tasks sync :)

Download the finished app here: http://www.mediafire.com/?i5tw3zpbcl86byg

New version here, cleaned up all MDPI, only 537 KB: http://www.mediafire.com/download.php?srhfp05qma86ctb