Android: Include su binary executable in AOSP buil

2019-03-16 16:50发布

I have been trying to get the su binary included in the /out/.../system/xbin/su after building Android from source. I have the su binary (from Chainfire) as an executable file but I can't seem to get it included in the AOSP build.

All the examples or solutions I've came across discussed about the following in the Android_Source_Root:

  1. Removing the su directory from system/extras/ and include the su-binary directory (taken from ChainsDD) in external/.
  2. Modify the file system/extras/su/Android.mk with "LOCAL_MODULE_TAGS := optional" and the file build/target/product/core.mk to include su in the PRODUCT_PACKAGES.

All of those have the su.c, su.h and other files in the su directory that are used to build the su package.

What I would like to know is how to include su in the AOSP build when I have the "su binary executable file" only without the need to include the su.c or any of those files? Where should I put the su directory and what is the content of the Android.mk file?

Please advice and thank you for your time.

1条回答
forever°为你锁心
2楼-- · 2019-03-16 17:10

I managed to resolve the issue that I mentioned. The following are the 2 ways I solved the issue but I faced another issue explained in the "Issue Faced" heading.

*Note: I put the su binary file in prebuilts/su

Solution 1

I modified the device.mk file in the device/ directory. I added the following to the file.

PRODUCT_COPY_FILES += \
    prebuilts/su/su:system/xbin

Solution 2

I modified the device.mk file in the device/ directory. I added the following to the file.

PRODUCT_PACKAGES += \
    su

I then added and insert the following to the Android.mk file in prebuilts/su/su.

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := su
LOCAL_SRC_FILES := $(LOCAL_MODULE)
LOCAL_MODULE_CLASS := EXECUTABLES

LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
LOCAL_UNSTRIPPED_PATH := $(LOCAL_MODULE_PATH)

include $(BUILD_PREBUILT)

Issue faced

I am unable to chmod the su binary file after it has been copied to the system/xbin directory. I have tried a few ways as follows but yielded no result.

  1. I added the following right after the lines in Solution 1 and it keeps giving me the error of chmod ... file cannot be found.

        $(shell chmod 6755 out/<product>/system/xbin/su)
    
  2. I added the following in Solution 2 Android.mk file before the include $(BUILD_PREBUILT) line but none changes the permission of the file.

    #Trial 1.
    SU_BINARY := $(LOCAL_MODULE_PATH)/su
    $(SU_BINARY)-post: su
        $(shell chmod 6755 $(LOCAL_MODULE_PATH)/su)
    
    #Trial 2 without "-post".
    SU_BINARY := $(LOCAL_MODULE_PATH)/su
    $(SU_BINARY): su
        $(shell chmod 6755 $(LOCAL_MODULE_PATH)/su)
    
    #Trial 3.
    SU_BINARY := $(LOCAL_MODULE_PATH)/su
    $(SU_BINARY): su
        chmod 6755 $(LOCAL_MODULE_PATH)/su
    

Could someone please advice on how to chmod the file? Thank you for your time.

Issues Resolved

Solution 1 (for Issue 1)

Change the permission of the file first chmod 6755 prebuilts/su/su. Include the following in the device.mk file in the device/ directory.

PRODUCT_COPY_FILES += \
    prebuilts/su/su:system/xbin

Solution 2 (for Issue 2)

Just add the following to the Android.mk file before include $(BUILD_PREBUILT)

LOCAL_POST_INSTALL_CMD := chmod 6755 $(LOCAL_MODULE_PATH)/$(LOCAL_MODULE)
查看更多
登录 后发表回答