Not all apps can directly includable on AOSP.
And some apps requires reverse engineering…
And some extreme cases, you might even want to merge prebuilt apps with AOSP apps…
For example, if you want to merge prebuilt Settings with AOSP one,
apktool
apktool d -r SettingsOEM.apk
(Don’t decompile resources by adding -r option to prevent rebuild breakages)
Find and replace ALL hex ref of resouces to actual vars
inside of resource classes or xml (e.g. R$string
, public.xml
).
For example, from this
const v0, 0x7f040ad0
to this
sget v0, Lcom/android/settings/R$string;->ok_button:I
If you’re using VS Code
,
open all R$*.smali
files in the new window
and do ctrl+shift+f
for opened file wide search.
Or, create auto replace script.
apktool
apktool b SettingsOEM.apk
d2j-dex2jar
d2j-dex2jar.sh SettingsOEM.apk
unzip SettingsOEM-dex2jar.jar
Clean-up and import required classes and resources that you want.
Zip classes to SettingsOEM-lib.jar
Place resources to (e.g.) res dir.
You should check whether classes names are not duplicated.
Target apps’ resources will be overrided by your imported ones.
jadx
to get decompiled java files for better code editjadx SettingsOEM-lib.jar
Remove class inside SettingsOEM-lib.jar
and place java files
to corresponding dirs such as src/com/android/...
.
Android.bp
java_import {
name: "SettingsOEM-lib",
sdk_version: "current",
jars: ["libs/SettingsOEM-lib.jar"],
}
android_library {
name: "SettingsOEM-core",
platform_apis: true,
resource_dirs: [
"res",
],
static_libs: [
"SettingsOEM-lib",
],
manifest: "AndroidManifest.xml",
}
android_app {
name: "SettingsOEM",
static_libs: [
"SettingsOEM-core",
],
srcs: [
"src/**/*.java",
],
defaults: ["platform_app_defaults"],
platform_apis: true,
certificate: "platform",
system_ext_specific: true,
privileged: true,
overrides: [
"Settings",
],
}
Include that app as module when you build AOSP.
Still it will requires bunch of fixes…
ADB logcat will be your friend for debugging.
- Written by: someone5678
- Date: 2023-07-07
- Update: 2023-07-09