Skip to content

Instantly share code, notes, and snippets.

@raphendyr
Last active Jun 4, 2022
Embed
What would you like to do?
Google Play Services installation to Sailfish X

Google Play Services for Alien Dalvik in Sailfish OS

Devices I have tested the guide:

  • Xperia 10 II
  • Currently not working: Xperia XA2

Requirements

You need unzip, wget and squashfs-tools.

If you have Debian/Ubuntu/etc. run the following:

sudo apt install unzip wget squashfs-tools

Instructions

In the host Linux machine

  • retrieve OGApps ARM / 10.0 / pico from: https://opengapps.org/

    • Xperia 10 II: ARM64 / Android 10.0
    • Xperia XA 2: ARM / Android 10.0 (interestingly, the hardware supports 64bit..)

    Sailfish 3+ use Android 8.1, Sailfish 4.0 use Android 9.0, and sailfish 4.1+ use Android 10.0

  • download also md5 checksum

  • copy /opt/alien/system.img to a Linux, e.g.:

    scp defaultuser@PHONE_IP:/opt/alien/system.img system-original.img

    The username is nemo for old installations.

  • extract required apps and support files, i.e, run the following in bash/zsh/ksh:

zip=$(ls open_gapps-arm*-*-pico-*.zip | sort -rn -k3,5 -t- | head -n1)
echo "USING PACKAGE $zip, CHECK THAT IT HAS CORRECT ANDROID VERSION\!"
md5sum -c "$zip.md5"
mkdir -p to-system/
for f in \
    Core/defaultetc-common.tar.lz \
    Core/defaultframework-common.tar.lz \
    'Core/gmscore-*.tar.lz' \
    Core/gmssetup-all.tar.lz \
    Core/googlebackuptransport-all.tar.lz \
    Core/googleonetimeinitializer-all.tar.lz \
    Core/googlepartnersetup-all.tar.lz \
    Core/gsfcore-all.tar.lz \
    'Core/setupwizarddefault-*.tar.lz' \
    'Core/vending-*.tar.lz' \
    ; do
  echo ".. $f:"
  unzip -p "$zip" "$f" | tar -vx --lzip --strip-components 2 -C to-system/
done
# remove execute from data files
find to-system/ -type f -print0 | xargs -r0 chmod -x
# extract shared libs
if [ "$zip" = "${zip#*-arm64-}" ]; then native=armeabi-v7a; else native=arm64-v8a; fi
for apk in to-system/priv-app/*/*.apk; do
  pushd "${apk%/*}"
  rm -rf lib/*/
  unzip -x "${apk##*/}" "lib/$native/*"
  [ -e lib/armeabi-v7a ] && mv lib/armeabi-v7a lib/arm
  popd
done
  • optionally, you can include Aurora Store as system app at this point (fork of YalpStore)

    Google Play store works with Xperia 10 II, so if you prefer that, no need to install this.

    mkdir -p to-system/priv-app/AuroraStore
    wget 'https://files.auroraoss.com/AuroraStore/Stable/AuroraStore_4.1.1.apk' -O to-system/priv-app/AuroraStore/AuroraStore.apk
    echo "0c4a74b84c94deec64f68d75fd18e73fbaa8393fb324945e6c25cd8943418507 to-system/priv-app/AuroraStore/AuroraStore.apk" | sha256sum -c

    If the last line, doesn't say OK, then there was a problem with the download, do not use the image! .

  • open squashfs image, fix, copy apps and repackage (requries squashfs-tools)

    NOTE: If you find a better method to keep file owners and permissions than sudo, let me know!

    sudo bash -c "
      # unpack
      root=/dev/shm/sailfish-android
      unsquashfs -d \$root system-original.img
      # fix broken files
      chmod +r \$root/system/etc/fs_config_dirs \$root/system/etc/fs_config_files
      # copy
      cp -vr to-system/* \$root/system/
      # create missing path after Sailfish 4.1
      #mkdir -p \$root/system/vendor/lib64/hw
      # repackage
      mksquashfs \$root/ system.img -comp lz4 -Xhc -noappend -no-exports -no-duplicates -no-fragments
      # clean
      chown $USER.$(id -ng) system.img
      rm -rf \$root
    "
  • upload image scp system.img nemo@PHONE_IP:/home/nemo/

  • cleaup rm -rf to-system system.img (note: let's keep original-system.img as a backup)

In your phone, e.g. ssh nemo@PHONE_IP. Remember to be a root devel-su.

  • Install the new image:

    # stop alien
    systemctl stop aliendalvik
    # backup system.img
    cp /opt/alien/system.img /home/alien-system.img
    # replace it
    cp /home/nemo/system.img /opt/alien/system.img
    # clear system app cache
    rm -vrf /home/.android/data/system/package_cache/*/Settings-*
    # remove updated google apps
    rm -vrf /home/.android/data/app/com.android.vending-*
    rm -vrf /home/.android/data/app/com.google.android.gms-*
    # fix android bootup with Sailfish 4.1
    rm -vrf /home/.android/data/misc/audioserver/
    # you can start alien now
    systemctl start aliendalvik
  • 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.

    lxc-attach -n aliendalvik -- /system/bin/logcat

When you install google play services for the first time:

  • 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)
  • Xperia XA2:
    • Google Play Store can't install applications. Seems android biometric interface is not implemented (at least up to SFOS 4.1, works in Xperia 10 II SFOS 4.2)

Troubleshooting:

  • 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 aliendalvik is running, you can stream android logs with

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

    lxc-attach -n aliendalvik -- /system/bin/sh # enter Android shell
    bmgr transport com.google.android.backup/.BackupTransportService # in Android system
@lotheac
Copy link

lotheac commented May 18, 2022

copying gservices.db off device is unnecessary, you can do this instead:

# 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])'

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