[HowTo] Install Google Play Services to XA2Ultra SailfishOS 4.6.0.11 Android 11 (Tested working)

Hi

After many studies and attempts I was able to literally install and activate Google Play Services within SailfishOS 4.6.0.11 running Android 11 for the XA2 Ultra 64 bits.

Below is the tutorial:

  1. Copy the Script below and rename it to install_gapps.sh

set -e

WORKDIR=/home/.aliendalvik_systemimg_patch

TMPWORKDIR="$WORKDIR/tmp"

SQUASHFS_ROOT="$TMPWORKDIR/squashfs-root"

MOUNT_ROOT="$TMPWORKDIR/systemimg_mount"

SYSTEM_IMG=/opt/appsupport/system.img

ORIG_IMG_FILE=orig_img_path.txt

FEDORA22_REPO=https://archives.fedoraproject.org/pub/archive/fedora/linux/releases/30/Everything/aarch64/os/Packages

OPENGAPPS_ARCH=arm64

OPENGAPPS_API=11.0

OPENGAPPS_VARIANT=pico

GOOGLE_APPS_REMOVE=‘carriersetup-all extservicesgoogle-all extsharedgoogle-all googlebackuptransport-all googlecontactssync-all googlefeedback-all googlepartnersetup-all setupwizarddefault-arm64 setupwizardtablet-arm64 vending-common’

log() {

printf '%s\n' "$1" > /dev/stderr

}

install_fedora22_rpm() {

pkgname="$1"

pkgversion="$2"

if ! rpm -q "$pkgname" > /dev/null; then

    pkgfile="$pkgname-$pkgversion.fc30.armv7hl.rpm"

    firstletter="$(printf '%s' "$pkgfile" | cut -c 1)"

    mkdir "$TMPWORKDIR/rpms"

    curl "$FEDORA22_REPO/$firstletter/$pkgfile" > "$TMPWORKDIR/rpms/$pkgfile"

    pkcon -y install-local "$TMPWORKDIR/rpms/$pkgfile"

    rm "$TMPWORKDIR/rpms/$pkgfile"

    rmdir "$TMPWORKDIR/rpms"

fi

}

install_deps() {

if ! rpm -q squashfs-tools > /dev/null; then

    log "squashfs-tools package not found. Installing..."

    pkcon -y install squashfs-tools

fi



if ! rpm -q rsync > /dev/null; then

    log "rsync package not found. Installing..."

    pkcon -y install rsync

fi

if ! rpm -q lzip > /dev/null; then

    log "lzip package not found. Installing..."

    install_fedora22_rpm lzip 1.20-4

fi

}

extract_image() {

mkdir "$MOUNT_ROOT"

mount -o loop,ro "$SYSTEM_IMG" "$MOUNT_ROOT"

if [ -f "$MOUNT_ROOT/$ORIG_IMG_FILE" ]; then

    orig_image="$(cat "$MOUNT_ROOT/$ORIG_IMG_FILE")"

    log "$SYSTEM_IMG already patched, using original from $orig_image"

else

    orig_image="$WORKDIR/system.img.orig.$(date +%Y%m%dT%H%M%S)"

    cp "$SYSTEM_IMG" "$orig_image"

    log "Copying original image $SYSTEM_IMG to $orig_image"

fi

umount "$MOUNT_ROOT"

if [ ! -f "$orig_image" ]; then

    log "$orig_image not found"

    return 1

fi

mount -o loop,ro "$orig_image" "$MOUNT_ROOT"

if [ -f "$MOUNT_ROOT/$ORIG_IMG_FILE" ]; then

    umount "$MOUNT_ROOT"

    rmdir "$MOUNT_ROOT"

    log "$orig_image already patched, please restore original image to $SYSTEM_IMG"

    return 1

fi

mkdir "$SQUASHFS_ROOT"

# rsync needs to be run twice to copy all xattrs. Probably a bug in rsync.

rsync -aSHAX "$MOUNT_ROOT/" "$SQUASHFS_ROOT/"

rsync -aSHAX "$MOUNT_ROOT/" "$SQUASHFS_ROOT/"

umount "$MOUNT_ROOT"

rmdir "$MOUNT_ROOT"

printf '%s' "$orig_image" > "$SQUASHFS_ROOT/$ORIG_IMG_FILE"

}

build_image() {

cp "$SYSTEM_IMG" "$TMPWORKDIR/system.img.backup"

mksquashfs "$SQUASHFS_ROOT" "$SYSTEM_IMG" -noappend -no-exports -no-duplicates -no-fragments

rm "$TMPWORKDIR/system.img.backup"

rm -r "$SQUASHFS_ROOT"

}

_find_opengapps() {

downloads=/home/defaultuser/Downloads/

name_pattern="open_gapps-$OPENGAPPS_ARCH-$OPENGAPPS_API-$OPENGAPPS_VARIANT-*.zip"

if [ "$1" != quiet ]; then

    log "Searching for Open GApps zip at $downloads/$name_pattern"

fi

find "$downloads" -maxdepth 1 -name "$name_pattern" | sort | tail -n 1

}

get_opengapps_zip() {

opengapps_zip="$(_find_opengapps)"

if [ -z "$opengapps_zip" ]; then

    # Show the Open GApps download page to the user instead of automating

    # the download of the latest version.

    # The no-mirror policy

    log "Opening Open GApps download page"

    runuser -l defaultuser – /usr/bin/xdg-open "The Open GApps Project"

    log "Waiting for download to start"

    while [ -z "$opengapps_zip" ]; do

        sleep 1

        opengapps_zip="$(_find_opengapps quiet)"

    done

    log "Detected new download at $opengapps_zip"

    log "Waiting for download to finish"

    while [ -f "$opengapps_zip" ] && [ -f "$opengapps_zip.part" ]; do

        sleep 1

    done

    sleep 1

    if [ ! -f "$opengapps_zip" ]; then

        log "Download failed"

        return 1

    fi

else

    log "Found Open GApps zip $opengapps_zip"

fi

printf '%s' "$opengapps_zip"

}

install_opengapps() {

log "Unzip open gapps archive"

unzip "$(get_opengapps_zip)" -d "$TMPWORKDIR/opengapps/"

log "Remove some google apps"

for p in $GOOGLE_APPS_REMOVE; do

    log "Removing $p"

    rm "$TMPWORKDIR/opengapps/Core/$p.tar.lz"

done

if [ -f "$TMPWORKDIR/opengapps/Core/extservicesgoogle-all.tar.lz" ]; then

    rm -r "$SQUASHFS_ROOT/system/priv-app/ExtServices"

fi

if [ -f "$TMPWORKDIR/opengapps/Core/extsharedgoogle-all.tar.lz" ]; then

    rm -r "$SQUASHFS_ROOT/system/app/ExtShared"

fi

mkdir "$TMPWORKDIR/opengapps_unarchived"

for f in "$TMPWORKDIR"/opengapps/Core/*.tar.lz; do

    lzip -c -d "$f" | tar -x -C "$TMPWORKDIR/opengapps_unarchived"

done

rm -r "$TMPWORKDIR/opengapps/"



ls -al "$TMPWORKDIR"/opengapps_unarchived

ls -al "$SQUASHFS_ROOT/system/"

ls -al "$SQUASHFS_ROOT/system/product"

cp -r "$TMPWORKDIR"/opengapps_unarchived/*/*/* "$SQUASHFS_ROOT/system/"

rm -r "$TMPWORKDIR/opengapps_unarchived/"

}

set_traps() {

# shellcheck disable=SC2064

trap "$*" EXIT HUP INT QUIT PIPE TERM

}

cleanup() {

if [ ! -f "$SYSTEM_IMG" ] && [ -f "$TMPWORKDIR/system.img.backup" ]; then

    mv "$TMPWORKDIR/system.img.backup" "$SYSTEM_IMG" || :

fi

umount "$MOUNT_ROOT" || :

rm -r "$TMPWORKDIR" || :

set_traps -

exit 1

}

set_traps cleanup

systemctl stop aliendalvik

mkdir -p “$WORKDIR”

mkdir -p “$TMPWORKDIR”

install_deps

log “extract image”

extract_image

log “image was extracted”

log “install open gapps”

install_opengapps

log “open gapps were installed”

log “build image”

build_image

log “image was built”

rmdir “$TMPWORKDIR”

set_traps -

exit 0

NOTE: Download Visual Studio Code and paste the text. After that, change the file from CRLT to LT (Windows recognizes the different format and with the change it changes it to Linux)

  1. After saving, place the file in the Download folder on device

  2. After finishing the script, open the website https://opengapps.org/ download the file
    AMR64 - Android 11 - PEAK.

  3. For some unknown reason, a file is not in the GAPP folder called /opegapp…/Core/extservicesgoogle-all.tar.lz
    Download and use WINRAR to place this file in the CORE folder.
    https://mega.nz/file/20M3HIJJ#tam9A-NzN_pURHMQy5pbC8-ElpRQfvpbhAakvxthw8E

  4. After completing the copy of the extservicesgoogle-all.tar.lz file into the CORE folder, copy and paste Gapp to the Download folder on your device.

  5. Open the terminal or use PUTTY to use the commands below:

devel-su
password
cd /home/defaultuser/Download
Assign usage permission to the install_gapp.sh file with the chmod +x install_gapps.sh command
Install 2 packages: rsync and unzip
pkcon install unzip
pkcon install rsync

  1. Enter the command: ./install_gapps.sh

Wait for the data to load, extract and copy the new files.
After completing, restart your device and configure your play store

Thanks to the user @nemishkor. I made some changes to make it work on the XA2Ultra.




1 Like

You should’ve put that in code tags. Or preferably host it on a VCS like github.

2 Likes

Iwonder what you exactly mean by XA2Ultra 64 bit. For this device, sailfish is still 32 bit. Does that mean you run 64 bit Android on top of 32 bit sailfish?

1 Like

As far as I know the XA2 Ultra is 64Bits. I used the files for 64Bits and it worked perfectly. I’m waiting for an Xperai 10 to update and see if it will work with the same code

1 Like