Does anyone know how to include super-user privileges when building android from source (AOSP)?
Asked
Active
Viewed 1.8k times
14
-
Do you mean superuser privilege in the shell or in android apps? – m-ric Sep 27 '12 at 14:26
-
@m-ricwhat if i want to compile Android with super user previliges for my android apps? is it possible? Basically i want an application to read or write into /system directory. Is it possible? I know it needs rooting. But to avoid the issues i thought it is better to build the android itself. Since its a reference board and we are testing something on it – Arjun Oct 05 '16 at 11:30
1 Answers
12
To get a root(ed) shell, edit system/core/rootdir
or the init.rc associated to your device (e.g. device/ti/panda/init.rc
for pandaboard) in android sources, and change those lines:
service console /system/bin/sh
class core
console
disabled
user shell
group log
into:
service console /system/bin/sh
class core
console
disabled
user root
group root
To embed Superuser.apk in AOSP, you have to fetch and build:
- su-binary (e.g. in
external/
) and stub/removesystem/extras/su
package. - Superuser (e.g. in
packages/app/
)
You may also have to set the sticky bit of /system/xbin/su
in su-binary/Android.mk. For instance, I used following makefile:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := su
LOCAL_SRC_FILES := su.c db.c activity.cpp
SU_SHARED_LIBRARIES := liblog libsqlite
ifeq ($(PLATFORM_SDK_VERSION),4)
LOCAL_CFLAGS += -DSU_LEGACY_BUILD
SU_SHARED_LIBRARIES += libandroid_runtime
else
SU_SHARED_LIBRARIES += libcutils libbinder libutils
LOCAL_MODULE_TAGS := eng
endif
LOCAL_C_INCLUDES += external/sqlite/dist
LOCAL_SHARED_LIBRARIES := $(SU_SHARED_LIBRARIES)
LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
SU_INSTALL_DIR := $(TARGET_OUT)/xbin
SU_BINARY := $(SU_INSTALL_DIR)/su
# taken from busybox-android
$(SU_BINARY)-post: su
@echo "Setting SUID/GUID to su-binary..."
chmod ug+s $(TARGET_OUT_OPTIONAL_EXECUTABLES)/su
SU_CMD := su
SYMLINKS := $(addprefix $(TARGET_OUT_EXECUTABLES)/,$(SU_CMD))
$(SYMLINKS): $(LOCAL_INSTALLED_MODULE) $(SU_BINARY)-post $(LOCAL_PATH)/Android.mk
@echo "Symlink: $@ -> /system/xbin/$(SU_CMD)"
@mkdir -p $(dir $@)
@rm -rf $@
@ln -sf /system/xbin/$(SU_CMD) $@
ALL_DEFAULT_INSTALLED_MODULES += $(SU_BINARY)-post $(SYMLINKS)
include $(BUILD_EXECUTABLE)

m-ric
- 5,621
- 7
- 38
- 51
-
Is that possible to just embed Superuser.apk in AOSP? I want to add root permission to a APK (prebuilt / preinstalled). – Dr.jacky May 15 '16 at 07:08
-
1Superuser.apk and SuperSU.apk require the su binary to be changed (contained in the zip file): http://superuserdownload.com/. Just embedding the apk won't be enough. To be specific to just one app, read this: http://su.chainfire.eu/#how – m-ric May 16 '16 at 00:27
-
-
1@Mr.Hyde try the version closest to JellyBean, I expect it to work just fine. – m-ric May 19 '16 at 13:59
-
1The attached mk of `su-binary` doesn't build. It says that there's a missing separator in `$(SU_BINARY)-post:` – shlatchz Sep 26 '16 at 20:55
-
Also how do I create a key `build/target/product/security/superuser.pk8` for the superuser app? – shlatchz Sep 26 '16 at 22:16
-
1What do you mean with "stub/remove system/extras/su package" in 1.? Replace the directory-content with the sources from the link? And why did you say "may also have to set the sticky bit"? Is it required or not? – MUmla May 17 '17 at 13:20
-
Is this answer still valid for AOSP 7 ? I can not find the specified phrase! @shlatchz – Saleh Jul 21 '18 at 12:02
-
-
If you want to build AOSP with root access, (i.e. to be able to run adb root) just set target as userdebug. (in lunch command) @Bayou – Saleh Sep 17 '19 at 11:35
-
Anyhow I am not sure but think the answer is valid still, if you need your apps to be able to run root commands – Saleh Sep 17 '19 at 11:35
-