This is for people who build AOSP or any roms from source for general public or for personal use. Koushik Dutta has given quite a good explanation here but some more things are needed to get it fully working. You should know what you are doing before you read ahead. I am not responsible if you mess up your device or any of your personal belongings
This guide will focus on Nexus 5 but the same procedure should work on Nexus 4, Nexus 7 (2012 & 2013) or any other device with little or no modifications.
- Knowledge about building roms from source
- knowledge about cherry-picking commits and resolving the conflicts
- basic knowledge about device trees
- A logical and working brain
You need to add the Superuser related repos from cyanogenmod into your rom source. This can be done using a local manifest. Make a local manifest by any name say su.xml and place it in .repo/local_manifests/su.xml. If the "local_manifests" folder doesn't exists in .repo then make one. Copy paste the following lines in su.xml
There are many commits to refer. I would link some to you. You can cherry-pick, for example,this or this. You can refer any of such commits. Cherry-pick is to be done in packages/apps/Settings. There might be conflicts in Android.mk & proguard.flags. Just compare the files from the ones in the above linked commits and fix them.
Step 3 : Add some required flags to device make file
To make Superuser to go under Settings, the most important flag needed is this :
SUPERUSER_EMBEDDED := true
# SU Support SUPERUSER_EMBEDDED := true PRODUCT_PACKAGES += \ Superuser \ su PRODUCT_PROPERTY_OVERRIDES += \ persist.sys.root_access=3 # Enable ADB authentication PRODUCT_PROPERTY_OVERRIDES += \ ro.adb.secure=1
Step 4[MOST IMPORTANT] : Import init.superuser.rc in init.rc or similar file.
People do everything properly upto step 3 but they never get superuser to work properly. When you try opening any root app, ADB gives the following error :
D/su ( 2529): su invoked. D/su ( 2529): starting daemon client 10019 10019 E/su ( 2529): connect failed with 2: No such file or directory
import init.hammerhead.usb.rc import init.superuser.rc on early-init mount debugfs debugfs /sys/kernel/debug chown system system /sys/kernel/debug/kgsl/proc