以hello 為例,文件如下:
./hello/Android.mk
./hello/hello.cpp
./hello/MODULE_LICENSE_APACHE2
./hello/NOTICE
Android.mk 的內容:
# Copyright 2018 The Android Open Source Project
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= hello.cpp
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_MODULE:= hello
include $(BUILD_EXECUTABLE)
hello.cpp 的內容:
int main(int argc, char **argv)
{
printf("hello world!\n");
return 0;
}
將文件夾hello 放到 system/core 目錄下。
./cd 到 system/core/hello$
$mm
編譯成功如下顯示:
然後將可執行文件push到手機/system/bin目錄下:
adb root
adb disable-verity
adb reboot
adb root
adb remount
adb push hello /system/bin/
adb shell
cd /system/bin/
Chmod 777 hello
./hello
其中adb disable-verity 不執行的話會報只读文件系统Read-only file system問題。
結束