Sample app and runtime resource overlay for android 31

Use case

Install standard app (without elevated system permissions) and change it resources using separate RRO APK (with elevated root permission).
Install and activate RRO in Android OS runtime, without messing with build time RROs. There is no need to change anything in Android OS, you can do it with standard system image (without Google play) on emulator

How to

Prepare emulator

  • Create AVD virtual device with Android 31 target image. Choose a version without Google Play, otherwise you will not be able to grant root permissions
  • Run emulator from command line: emulator -avd {EMU_NAME} -writable-system, for example emulator -avd Pixel_5_API_31 -writable-system

Install Target App

  • Build android app found in MyTarget directory
  • Install it on your device, the same way you always do

Build overlay

  • Open MyOverlay directory
  • Let’s build an overlay APK

aapt2 compile -v --dir res/ -o Overlay.flata

aapt2 link -v --no-resource-removal \
-I ~/AppData/Local/Android/Sdk/platforms/android-31/android.jar \
--manifest AndroidManifest.xml \
-o myoverlays.apk.u Overlay.flata
  • We have unaligned apk file myoverlays.apk.u, let’s align it using
zipalign 4 myoverlays.apk.u myoverlays.apk
  • Finally, we need to sign our APK, I use standard debug certificate
printf 'android' | jarsigner -keystore ~/.android/debug.keystore  myoverlays.apk androiddebugkey 

Install overlay

  • Overlays are placed in system directories, and we need root permission to di it
  • We will be placing our overlay to /product/overlay folder
  • Prepare target file system, run

adb root
adb remount
adb shell remount
  • Copy overlay using
adb push myoverlays.apk product/overlay

Note: use script to automate steps from Build and install overlay section

Enable overlay

  • After overlay install/reinstall you need to reboot your device
adb reboot
  • Verify your overlay is installed, you should see mappings defined by overlay and it’s status. Run

adb root
adb shell cmd overlay dump com.example.myoverlay
  • Overlay is not enabled by default, enable it using

adb shell cmd overlay enable --user current com.example.myoverlay

  • You should see changes in your application

Note: use script to automate steps from enable overlay section


View Github