作者:手机用户2602907455 | 来源:互联网 | 2022-01-14 16:19
编译Android系统APK
1、设置环境
1 2 3 | export ANDROID_HOME= /home/administrator/soft/android
export PATH=$PATH:$ANDROID_HOME /out/host/linux-x86/bin
export ANDROID_PRODUCT_OUT=$ANDROID_HOME /out/target/product/generic
|
2、创建项目
1 2 3 4 5 6 7 8 9 | android create project -t 1 -k com.lhw.led -a MainActivity -p . /led
Avd id : 1,It's get by command "android list"
Project Name: led
Package: com.lhw.led
Main Activity:MainActivity
Project Path: ./
|
接下来就是自己编写Android程序了。
3、编写Android.mk
Android.mk需要放在项目根路径下,即led下,内容:
1 2 3 4 5 6 7 8 9 10 | LOCAL_PATH := $(call my- dir )
include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := led
LOCAL_JAVA_LIBRARIES :=
LOCAL_STATIC_JAVA_LIBRARIES :=
include $(BUILD_PACKAGE)
|
4、编译
在Android源码目录下执行:
1 2 | . /build/envsetup .sh
mmm /home/administrator/workspace/android_test/led/
|
执行结果:
Install: out/target/product/generic/system/app/led.apk
编译Android系统可执行命令
Android系统允许开发者,自己编写"ls"这样的命令放到Android系统中。
1、编写C文件:mycmd.c
1 2 3 4 5 6 7 8 9 | #include <stdio.h>
int main( int argc, char **argv)
{
printf ( "This is my command!\n" );
return 0;
}
</stdio.h>
|
2、编写Android.mk文件
1 2 3 4 5 6 7 8 9 | LOCAL_PATH := $(call my- dir )
LOCAL_SRC_FILES := mycmd.c
LOCAL_MODULE := mycmd
LOCAL_MODULE_TAGS := mycmd
LOCAL_SHARED_LIBRARIES := libc
LOCAL_STATIC_LIBRARIES :=
include $(BUILD_EXECUTABLE)
|
3、编译
1 | mmm /home/administrator/workspace/android_test/mycmd/
|
编译完成后信息:
1 | Install: out /target/product/generic/system/bin/mycmd
|