Installing microG on LineageOS 11 for Raspberry Pi

You do not need to do this if you use OmniRom, as it has microG pre-installed

Android users can install Google's play store, which slows the system and requires frequent communication with Google's servers or they can install microG, an open-source alternative that gives most apps what they need without constant battery draining, system slowing communication with Google's servers.

Have a question? Want to contribute? Try the "Other Projects" section of the Raspberry Pi forum. Start your title with "WBC".

There are several different ways to get microG on Android.

  1. Lineage4microG requires that the device be supported by the LineageOS team, or at least that docker-lineage-cicd can assemble the ROM. This is the preferred method, as it enables "restricted" installation of microG (only selected apps can act as part of play services). For those working on devices other than the Pi, note that docker-lineage-cicd can often assemble ROMs for devices that have lost Lineage support.
  2. NanoDroid can install microG, however it uses the NanoDroid author's fork instead of the original microG.
  3. One can apply a signature spoofing patch to the Android OS. Options include needle and haystack.
  4. Magisk can install microG.

This method is based on the kingslayer method. Before trying it, you should back up your Pi completely and be aware of the security implications. It assumes that you have access to a computer that runs Linux.

This method was tested using LinageOS for Raspberry Pi. It will probably work with other non-oxeded ROMs.

Requirements

Linux computer with a microSD card reader

DexPatcher - this process was tested using release 1.8.0 beta 1.

Haystack 11 attempt file with relevant hooks.
spoof_AVD file

Checksums of the above files are available in the checksum database

Instructions

Mount the SD card on your computer and copy /system/framework/services.jar from the Android system partition (partition #2) to a temporary working directory. We're going to assume that you decided to name your working directory /workingdir and partition 2 of the SD card is mounted on /SD_Partition_2

cp /SD_Partition_2/system/framework/services.jar /workingdir
Copy 11-hook-services.jar.dex and 11core-services.jar.dex from haystack-11-attempt.zip to your /workingdir

cd /tmp; unzip haystack-11-attempt.zip; cp haystack-11-attempt/*.dex /workingdir
Take apart your services.jar and integrate the patch into the pieces.

java -jar dexpatcher-1.8.0-beta1.jar -a 11 -M -v -d -o ./ services.jar 11-hook-services.jar.dex 11core-services.jar.dex
There should now be four .dex files in /workingdir named classes*.dex
Make a directory with the name repack by running

mkdir repack
Reassemble the classes into a new services.jar

zip -j repack/services.jar classes*.dex
Become root using su. Use cat instead of cp to copy the new services.jar to your SD card.

cat /workingdir/repack/services.jar > /SD_Partition_2/system/framework/services.jar
Transfer the SD card to the Pi and boot from it. The LineageOS boot animation should appear. Go through the first-boot device setup and get ready to start installing apps.
Install the f-droid app. It is the key to installing the rest of the needed software.
Add the microG f-droid repository and confirm its signing key.
Install the following apps from f-droid.
  1. microG services core
  2. Fakestore
  3. FakeGapps
Turn off Google device registration
Extract org.spoofing.apk from /system/framework within spoof_AVD_api30.zip. Install the apk.
Reboot the device
Open microG settings and do the self-check. Click "system grants signature spoofing permission" and a popup should appear that asks for permission.
Click "Play Store (Phonesky) has correct signature. Another permission dialog should appear to ask whether you want to allow FakeStore to spoof.
Use settings->apps->permission manager->additional permissions to allow FakeStore and microG services core to spoof if not already set.
Install local gsm location from fdroid
Install wifi location service from fdroid. Be sure to choose the one that mentions "a local RF-based back end"
Grant microG permission to access location and anything else that you want. The menu sequence will take you to settings so that you can let microG access location in the background.
You may wish to let microG ignore battery optimizations
You may wish to give microG some of the other permissions that it asks for.
You may wish to install microG services framework proxy from f-droid.