[How-to] Install MicroG on XA2 (Android 8.1)
asked 2019-02-24 20:34:12 +0200
This post is a wiki. Anyone with karma >75 is welcome to improve it.
update 2017-07-21 : This is for Sailfish OS up to 3.0.3 Hossa. Starting from 3.1.0 Seitseminen, the Signature Spoofing is built-in, there's no need for patching, only to activate it in Settings, and grant the Signature Spoofing capability in Android Settings. Modifying system.img is still required for mapsv1 API, but it's a bit simpler.
Edit: Check the answer by yeoldegrove for an automated script, thank you to yeoldegrove!
Hopefully this is not a duplicate.
I just managed to get the signature spoofing and MicroG working on XA2 (3.0.1.14) with the new Android support so I thought to write a small how-to if others are interested.
Note that you should do this before installing Android apps. Many apps will crash if you install MicroG after them, but you can reinstall the apps and they should start working. Also you probably need to do this everytime there is an update for the Android Support and the system.img is changed.
What's needed:
-squashfs-tools (available for both Windows and Linux, I used the Linux version)
-vdexExtractor (https://github.com/anestisb/vdexExtractor AFAIK only works on Linux)
-SmaliPatcher (https://forum.xda-developers.com/apps/magisk/module-smali-patcher-0-7-t3680053 AFAIK only works on Windows)
Steps:
Get the file /opt/alien/system.img from your phone and copy it to your PC (make a backup too)
Use squashfs-tools to unpack the .img file
unsquashfs /path/to/image/system.img
Get the following files and copy them to another folder
unpacked_image_path/system/framework/oat/arm/services.vdex
unpacked_image_path/system/framework/services.jar
Deodex the services.vdex with vdexExtractor
/path/to/vdexExtractor/bin/vdexExtractor -i path/to/services.vdex --ignore-crc-error
Now you should have a file called services_classes.dex, you need to rename it to classes.dex and pack it into the services.jar file
zip -j path/to/services.jar classes*.dex
Now you need to use SmaliPatcher to inject the signature spoof patch to the services.jar (which now includes the classes.dex file). So switch to Windows (unless you can find a Linux version of smalipatcher) and use the graphical UI to patch services.jar. I chose the default settings which includes mock location patch and the signature spoof patch. You probably only need the signature spoof patch.
SmaliPatcher creates a .zip file which includes a /system folder. Copy this system folder over your unpacked_image_path/system to replace the original files with the patched files.
Now use squashfs-tools again to pack the files to system.img
mksquashfs unpacked_image_path/ system.img -comp lz4 -Xhc -noappend -no-exports -no-duplicates -no-fragments
Copy the new system.img to your phone. Make sure Android Support is not running.
As devel-su: cp /path/to/image/system.img /opt/alien/system.img
Press y to confirm overwrite (make sure you have backup of the original system.img)
(Not sure if necessary but I set the permissions of system.img to match the original by:)
As devel-su: chmod u=rw,g=r,o=rw /opt/alien/system.img
Start the Android Support. Install MicroG from F-droid repo. You should see signature spoofing enabled and MicroG working.
Thanks to people on thread https://together.jolla.com/question/198500/xperia-xa2-sailfish-x-dont-have-systempriv-app-directory/ for getting the squashfs parameters right, thanks to authors of vdexExtractor, SmaliPatcher and of course the MicroG team. Also thanks to the author(s) of NanoDroid for creating a tutorial for deodexing.
Hopefully I got everything right. Please share any improvements you might have in mind for this tutorial. Happy patching =)
Wouldn't the video by leszek be easier? I'm asking because I cannot try since I don't have an XA2.
Giacomo Di Giacomo ( 2019-02-24 20:40:24 +0200 )editI think that video tutorial is missing the signature spoof patch which is the hardest part of the process. I'm not exactly sure if MicroG works 100% without the patch, would be nice if someone can test if it is necessary or not.
synthent ( 2019-02-24 20:45:30 +0200 )editThe Video is without Singature Spoofing, which is really the hardest thing here. Some thinks work without it, but the most need Spoofing ;) So thank you for this tutorial!! I'll try it ;)
jayki ( 2019-02-24 21:00:01 +0200 )editThis is a PITA. I guess the system.img file is the same for all phones. There should not be copyright issues if some kind soul made available the patched file for other users to download, since it's all freely available stuff.
Giacomo Di Giacomo ( 2019-02-24 21:12:43 +0200 )editGive a man a patched image and he will enjoy MicroG until the next Alien Dalvik update. Teach a man to patch the image himself and he will enjoy MicroG until it goes unmaintained :)
synthent ( 2019-02-24 21:24:09 +0200 )edit