Skip to content

Instantly share code, notes, and snippets.

@raphendyr
Last active February 2, 2025 22:40
Show Gist options
  • Save raphendyr/fc0e00a17a69c9054037b478fa4425c1 to your computer and use it in GitHub Desktop.
Save raphendyr/fc0e00a17a69c9054037b478fa4425c1 to your computer and use it in GitHub Desktop.
Google Play Services installation to Sailfish X

Google Play Services for AppSupport in Sailfish OS

I recommend to consider microG instead. It's officially promoted in the changelog forum post. Additionally, it doesn't bundle Google products and should provide better secrecy. However, it might not include all features. Check out the guide from the official forum.

In contrast, this guide is based on MindTheGapps, as mentioned in LineageOS wiki. Before, we used OpenGApps, but that is not maintained anymore.

This guide is currently updated to Sailfish 5.0 and the Google Apps package is changed. Please, check the document history for support of older versions.

Devices I have tested the guide:

  • Xperia 10 II (AppSupport 11)

Prepare

Using the Phone:

  1. Download MindTheGapps package from https://mindthegapps.com/, see version below.
  • Xperia 10 II: Android 11 and ARM64
  • Xperia XA 2: Android 11 and ARM (add a comment if this is wrong)
  1. Save the zip to Downloads folder

  2. Open the zip using file browser

  3. Extract all files using the archive app

There is no upstream sha1 sum for chekcking. Here are outputs for me:

52bbb853cc03c92755ea1c5c5f1ffa9a67d39e7b  /home/defaultuser/Downloads/MindTheGapps-11.0.0-arm64-20230922_081122.zip

Install

  • Setup "gapps-support", i.e., MindTheGapps as mounts to the Appsupport LXC container. This uses /product and /system_ext Android mounts, which were not used by Sailfish at the time.

    mkdir -p /opt/gapps-support
    # install system packages
    dir=$(find /home/defaultuser/Downloads -type d -iname 'MindTheGapps*' | sort -rn -k2,4 -t- | head -n1)
    dir=${dir:-/mindthegapps-not-found}
    (cd "$dir/system/product" && rm -rf app/GoogleTTS app/MarkupGoogle app/talkback priv-app/AndroidMigratePrebuilt priv-app/SetupWizardPrebuilt priv-app/Velvet)
    rm -rf /opt/gapps-support/product /opt/gapps-support/system_ext
    cp -a "$dir/system/product" /opt/gapps-support/product
    cp -a "$dir/system/system_ext" /opt/gapps-support/system_ext
    chown -R appsupport-root:appsupport-root /opt/gapps-support/product /opt/gapps-support/system_ext
    # make mount script
    echo '#!/bin/sh' > /opt/gapps-support/prepare-hook.sh
    echo 'echo "lxc.mount.entry = /opt/gapps-support/product product none rbind,nodev,nosuid,ro,create=dir 0 0" >> $CONTAINER_CONFIG_PATH/41-gapps_config' >> /opt/gapps-support/prepare-hook.sh
    echo 'echo "lxc.mount.entry = /opt/gapps-support/system_ext system/system_ext none rbind,nodev,nosuid,ro,create=dir 0 0" >> $CONTAINER_CONFIG_PATH/41-gapps_config' >> /opt/gapps-support/prepare-hook.sh
    chmod +x /opt/gapps-support/prepare-hook.sh
    # enable script
    mkdir -p /etc/appsupport.conf.d/init/prepare-hook.d
    ln -s /opt/gapps-support/prepare-hook.sh /etc/appsupport.conf.d/init/prepare-hook.d/61-gapps-support.sh
  • Note that startup after the installation will take a long time as the Android is caching and compiling files. You can follow the progress with the following command. However, it will show a lot of errors and warnings, so it might be alarming, even though everything is ok.

    appsupport-attach /system/bin/logcat

Uninstall

# system link, this can be removed to just disable GApps:
rm -rf /etc/appsupport.conf.d/init/prepare-hook.d/61-gapps-support.sh
# remove all data
rm -rf /opt/gapps-support

When you install google play services for the first time:

THIS STEP HAS NOT BEEN CHECKED AFTER Sailfish 5.0 and MindTheGApps

  • open google play and sign in

  • retrieve GSF ID:

    Sadly, neither Sailfish 4 or Android contains sqlite3 anymore, so you need to do some manual work. Either copy the database to your computer or install sqlite3 to your phone.

    Copy:

    # on sailfish after devel-su
    cp /home/.android/data/data/com.google.android.gsf/databases/gservices.db /tmp/
    chmod a+r /tmp/gservices.db
    # on your computer
    scp defaultuser@PHONE_IP:/tmp/gservices.db
    sqlite gservices.db 'select * from main where name = "android_id";'
    # copy the id from the output
    rm gservices.db
    # on sailfish after devel-su
    rm /tmp/gservices.db

    Or Install:

    # on sailfish after devel-su
    pkcon install python3-sqlite
    python3 -c 'import sqlite3;
    c = sqlite3.connect("/home/.android/data/data/com.google.android.gsf/databases/gservices.db").cursor();
    c.execute("select value from main where name=\"android_id\";");
    print(c.fetchone()[0])'
  • Register your device: https://www.google.com/android/uncertified/

Known issues:

  • Android/apps believe the device is rooted (well, it is, but they shouldn't know that).
  • Fast location doesn't work with wi-fi polling
  • Google Backup Transport doesn't seem to work (requires investication)

Troubleshooting:

  • To check logs of appsupport service, run as root: journalctl -u appsupport@defaultuser -e

  • For location service, disable google wi-fi checking, it doesn't work. This means that accurate location will take some time, of course (e.g. Jodel will take few minutes to login).

  • When appsupport is running, you can stream android logs with

    appsupport-attach /system/bin/logcat
  • If google backup is disabled, you can re-enable it:

    # enter Android shell
    appsupport-attach /system/bin/sh
    
    # in Android system
    bmgr transport com.google.android.backup/.BackupTransportService
@raphendyr
Copy link
Author

Hmm.. I didn't check the first time case. I would love to have another device for that (I could reset the Android). However, I did check that the db file is there in my phone, but it's hard to say if that is in use or left from before. So, if you get the Store working, but you won't find the file, then I or you need to do some debugging.

Any how, the Play Store icon should be visible as long as the correct image is in use. Every (or most) OS updates do reset the /opt/alien/system.img to the original version from Jolla, so the above steps need to be done after every update (well, not the first time part, but creating the image part).

A script would be nice, but making it work for everyone is bit too much work. In addition, I prefer not to install too many packages in the phone. However, there exists some in forums (seems to attempt to work for everyone quite well), which you can check out. It seems to do mostly the same things. Didn't have # force rerunning permission and storage migrations step at the moment.

Any how, my guess is that you don't have the correct image in use. Thus repeat from the start and try to keep track of files. Make extra copies or write notes where needed.

@CosmicDuck
Copy link

Hmm, I reinstalled complete aliendavik and appsupport-system-unprivileged to recreate the /opt/alien/system.img.
Then restarted from scratch the steps above. By the way I also restarting the phone after that my old installed apps like whatsapp are running, but no google play store available. Is it possible I must install it first but where it is? Maybe can I simply use install the apk from the pico image but whats the name of the apk?
I tried also to reinit my android storage by moving /home/.android to another place. But then no play icon appears on sfos app screen. But installing aptoide and fdroid app from sf store is working well.
I think there is a mistake in my brain, hopefully you can find my fault.

@CosmicDuck
Copy link

Now I used a modified script from here so it can be used for aarch64/arm64 Xperia10III now.
All Gapps like Google, Chrome also GPlayStore are now installed after reboot an waiting some minutes so also my older instaled apps could now been updated with the Google Play Store App.
I thing it is a good idea to find the differences between your and my modified installations.

@raphendyr
Copy link
Author

The Google Play Store etc. go into the priv-app inside the squasfs image, hence it requires modification of that rootfs. I think there is some mistake in my guid or it's bit vague of something.

It's also possible that some parts of the code don't work with some terminal (e.g. fish or even bash). I have been using zsh, so I only have verified it with that. And this is actually really good reason to use a script, as that would define the shell.

If I find motivation, I could look how complicated it would be to create a Sailfish app out of this process. Or like a button to settings or such.

I have spend little bit going through how AppSupport starts the Android container, but there doesn't seem to be nice way to integrate Google Play services without modifying the squashfs. Well, we would beed to extract those few paths out of the image and mount them with lxc (latter is doable, former is error prone). I wish lxc had overlayfs or such.

@tardypad
Copy link

I just tried it with SailfishOS 4.6 and it still works fine.
The only required change in the above scripts is using /opt/appsupport/ instead of /opt/alien/.

Couple of others comments:

  • systemctl ... aliendalvik could be replaced by systemctl ... appsupport (but former still works via a symlink)
  • for the python3-sqlite part, please remove the indentation at the beginning of lines, otherwise a simple copy paste of the whole code doesn't work
  • I had to restart the Google Play app a couple of times before it worked for good (the first times it opened and closed immediately)
    I also rebooted in between but not sure if it was necessary. I don't remember if it was like this before in previous versions.

@raphendyr
Copy link
Author

Thanks @tardypad! I had forgotten to update the guide. I removed references to aliendalvik and fixed that stupid indentation bug.

Another thing that I had locally, was adding the trichromelibrary. It contains some Chrome components and is required by Chrome at least. However, I did the engineering last year and I'm unable to confirm anymore, if it's still needed as part of opengapps installation or not. For some reason, Google Play store didn't seem to download that as a dependency, but it should update if it's installed or such. Anyhow, it's now in the guide (with some extra details in the raw markdown file).

@nreal2
Copy link

nreal2 commented Jan 5, 2025

Thank you very much for this, worked like it should with 10 III with latest updates installed (4.6.0.15).

@nreal2
Copy link

nreal2 commented Jan 31, 2025

Upgrading from 4.6.0.15 to 5.0.0.55 did not go well, had to delete everything to get android support running again, paths may have changed?

@raphendyr
Copy link
Author

I looked into how Sailfish manges the appsupport in 4.6 and 5.0. It starts to be really nice, specially how 5.0 uses user systemd to manage the appsupport. I guess that enables appsupport for multiple users (now or in future).

Anyhow, hooked into the appsupport system and used some existing Android mounts. This should setup that works over smaller Sailfish updates. In addition, it would allow making a installable package of this setup.

This new stuff has been tested in my phone for about 10 minutes, so I have no idea if it would really work. Play Store seems to be there and working (can install packages, thus it has permissions). If people dare, you can test the updated guide. I tried to make it safe enough, so people don't accidentally brick the system. If the AppSupport doesn't start, remove the files as noted in "Uninstall" section.

@raphendyr
Copy link
Author

raphendyr commented Feb 2, 2025

Also, note that the Sailfish changelog mentions this microG guide, which allows installation from the phone without console - https://forum.sailfishos.org/t/installing-microg-on-sailfish-os/14375

The microG and official Google apps are different, but the former likely suites for most use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment