Skip to content

Instantly share code, notes, and snippets.

@draekko
Forked from dic1911/#build_rom_with_microG.md
Created October 19, 2021 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save draekko/7c9645a1350195054c4fdc48a149377d to your computer and use it in GitHub Desktop.
Save draekko/7c9645a1350195054c4fdc48a149377d to your computer and use it in GitHub Desktop.

Building ROMs with microG integrated


Intro

I never thought I'd do this instead of just build normal ROMs and install microG manually just like people flashes opengapps or some other stuff, but then I found out that "LineageOS for microG" exists, stable custom ROM plus microG instead of bs out of box, nice idea isn't it?

Oh btw, if you know docker and doesn't want to customize your build, "LineageOS for microG" got you covered already, just check out their repository.

Requirement

As I'm not gonna cover the part about how you normally make a working ROM for your device, just make sure you can get a booting and working build before you try.

Syncing needed stuff

  1. So, you probably already know how to make use of "local_manifests", now add this prebuilt repo for microG to the xml file. For example:
    <project name="lineageos4microg/android_prebuilts_prebuiltapks" path="prebuilts/prebuiltapks" remote="github" revision="master" />

Update: vachounet@Telegram from OmniROM group mentioned that there's another repo with more useful changes, check here, you can include microg.mk and skip step one from next section if you want all stuff included in your build.

  1. Sync ROM source like you usually do

Prepare your tree

  1. Let's start with the easy one, simply add the following to your device tree .mk file where you normally add PRODUCT_PACKAGES to:
    # microG
    PRODUCT_PACKAGES += \
        GmsCore \
        GsfProxy \
        MozillaNlpBackend \
        OpenWeatherMapWeatherProvider \
        FDroid \
        FakeStore \
        com.google.android.maps.jar \
        com.google.android.maps.xml \
        org.microg.xml

  1. Now, as you may heard, microG requires signature spoofing patch for frameworks_base to let apps recognize microG as GMS so that you can receive push notifications, grab patch from here, just the one that matches the Android version that you're about to build, use patch for P if you're building Q for now.
    $ cd frameworks/base

    ## Special thanks vachounet@Telegram for mentioning these 2
    ## Only run merge 2 commits if you're building Android Q
    $ git fetch "https://gerrit.omnirom.org/android_frameworks_base" refs/changes/29/36729/4 && git cherry-pick FETCH_HEAD
    $ pushd ../../packages/apps/PermissionController # for LineageOS, location may vary for different ROMs
    $ git fetch "https://gerrit.omnirom.org/android_packages_apps_PackageInstaller" refs/changes/30/36730/3 && git cherry-pick FETCH_HEAD

    ## Now grab basic patch for microG
    $ wget https://github.com/microg/android_packages_apps_GmsCore/raw/master/patches/android_frameworks_base-P.patch

    $ patch -p1 < android_frameworks_base-P.patch
    ## maybe some hunk succeed and some may fail here, resolve it manually if failed

    $ git status
    ## You'll probably see some .orig and .rej files generated when patching, remove it manually
  1. To make network location working, we need to set 2 boolean values in Android framework xml file that controls network location provider behavior,

    • Add the content below to your overlay xml(recommended - if you don't know anything about overlay, read the next paragraph), or use your favorite text editor to open (ROM dir.)/frameworks/base/core/res/res/values/config.xml then set respective boolean to true
    <!-- From https://github.com/lineageos4microg/docker-lineage-cicd/blob/master/src/signature_spoofing_patches/frameworks_base_config.xml#L21 -->
    <!-- Force-enable the location overlays -->
    <bool name="config_enableNetworkLocationOverlay" translatable="false">true</bool>
    <bool name="config_enableFusedLocationOverlay" translatable="false">true</bool>
  • As this is just a quick guide to adding needed overlay to your device tree here, try DuckDuckGo if you want to learn more
  • Let's start with checking if you already have overlay in device tree and add it if you don't.
    ## Go to your device tree dictionary
    $ cd device/(vendor)/(codename)

    ## Check if there's a dictionary named "overlay" there,
    ## if it exists skip the following in this code block
    $ ls overlay

    ## Open one of the already included Makefile, like the one where you do step 1 of this section
    $ vim device.mk
    ## Add next line to the Makefile(without "##", and change "(vendor)"
    ## and "(codename)" to match your device tree path)
    ## DEVICE\_PACKAGE\_OVERLAYS += device/(vendor)/(codename)/overlay

    ## Create dictionary to "overlay" the Android framework
    $ mkdir -p overlay/frameworks/base/res/res/values
  • Now we're nearly finished, just have to add the boolean values to the overlay
    ## Open the file to set the 2 boolean values
    $ vim overlay/frameworks/base/res/res/values/config.xml

    ## Now there're two cases, there's already a "config.xml" and there's not,
    ## if you already have other values set in that "config.xml", just add the
    ## content above to the inside of "<resources>" tag, and you'll be good to go
    ## If you don't have existing "config.xml", grab it from the link below
  1. (optional - not supported on Android 10 at the time of writing) You can also grab Bromite WebView package from the release page, and replace the one in (ROM dir.)/external/chromium-webview/prebuilt/(target device cpu arch.)/webview.apk

[Optional] Google Play Store

Sometimes it's tricky to install Play Store manually, as recent Android version need a permission whitelist xml for Play Store, for FakeStore, it's easy since it only needs android.permission.FAKE_PACKAGE_SIGNATURE (source)

For the Play Store apk, you may obtain it from various sources, like APKMirror(original) , shadow53(patched) and Lucky P-something. In my experience, different apk source may have different permissions (as the version varies?), there won't be too much differences, but in case you missed any one of the permissions, you'll experience bootloop, check logcat and you'll see what's missing. (Tip: Grab the whitelist xml from shadow53's package as a quick start)

  • First one is to simply replace the apk and xml file in FakeStore directory
  • Another one is cleaner, here we go:
 ## Assume you're in $TOP dictionary of ROM source
 $ cd prebuilts; mkdir Phonesky && cd Phonesky
 ## I have written the Android.mk for you, grab it with the command below
 $ wget https://gist.github.com/dic1911/407184ee427c50ad0066af643a20254f/raw/b413f433cf122635ac7226ef1abe69ef92f0b6d9/Android.mk

Put Play Store apk in current dictionary and rename to "com.android.vending.apk", then replace the FakeStore include to Phonesky in your makefile.

Happy building!

Just run your favorite build command now! Easy, right?

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := privapp-permissions-com.android.vending.xml
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := ETC
LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)/permissions
LOCAL_SRC_FILES := $(LOCAL_MODULE)
include $(BUILD_PREBUILT)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := Phonesky
LOCAL_SRC_FILES := com.android.vending.apk
LOCAL_MODULE_CLASS := APPS
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
LOCAL_CERTIFICATE := PRESIGNED
LOCAL_REQUIRED_MODULES := privapp-permissions-com.android.vending.xml
include $(BUILD_PREBUILT)
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- From https://github.com/lineageos4microg/docker-lineage-cicd/blob/master/src/signature_spoofing_patches/frameworks_base_config.xml#L21 -->
<!-- Force-enable the location overlays -->
<bool name="config_enableNetworkLocationOverlay" translatable="false">true</bool>
<bool name="config_enableFusedLocationOverlay" translatable="false">true</bool>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment