用Eclipse编译工程,若工程下有libs目录,会自动将里面的*.so库编译到apk包中。我现在需要用到*.so库和Android.mk文件编译工程,但用Eclipse编译时,Android.mk不起作用。 Android.mk好像只有在通过源代码编译工程时才起作用(我目前只发现这个办法),即在Linux环境下的Android源代码目录中,通过make或mmm命令编译。但通过mmm编译的工程,不会把工程下libs目前中的*.so库添加进apk包里,是不是要在Android.mk文件中添加一些申明什么的? 还有,想知道Android源代码中,重启手机的相关代码在哪个部分。 有了解的朋友请支个招啊!谢谢!
2、如果你想在Android source里面添加你自己的library,你只需要在你本地模块Android.mk中指定LOCAL_LDLIBS就可以了,具体的你可以参考我的BLOG关于How to add another component to the build - Android.mk templates的部分:
http://hi.csdn.net/link.php?url=http://blog.csdn.net%2Fyili_xie3、我不知道关机的代码具体在哪,但是你可以到android source的java目录里面去找,我可以告诉你java的目录:
框架的java source :
75 FRAMEWORKS_BASE_SUBDIRS := \
76 $(addsuffix /java, \
77 core \
78 graphics \
79 im \
80 location \
81 media \
82 opengl \
83 sax \
84 telephony \
85 wifi \
86 vpn \
87 keystore \
88 )
就是这些目录下的java目录~
默认APK的source :YourMenu/pacakges
1) 如果你有现成的.so,放在预编译目录下就可以了,至于如何在APK中调用,我觉得应该仔细看看Android NDK的文档,这个我不太清楚 ;
2) 你也可以把你的source编入Android框架,根据你想把它编成bin,.so,.a使用的模板不同,我曾经在mail list里面看到过google的engineer发过一个帖子说怎样加进去一个流程,但是现在找不到链接了。但是其实是很简单的,你看看一些模块里面的Android.mk再结合Android built目录下的那个文档就知道怎么写了~~
LOCAL_SHARED_LIBRARIES := \
libandroid_runtime \
libnativehelper \
libcutils \
libutils LOCAL_STATIC_LIBRARIES := \
libfreetype \
libt1
# Also need the JNI headers.
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) \
$(LOCAL_PATH)/include
LOCAL_CFLAGS += -O2 LOCAL_CFLAGS += -DHAVE_CONFIG_H LOCAL_LDLIBS += -lpthread
LOCAL_PRELINK_MODULE := falseinclude $(BUILD_SHARED_LIBRARY)
III. NDK development in practice:
---------------------------------Here's a very rough overview of how you can develop native code with the
Android NDK: 1/ Run build/host-setup.sh to configure the NDK 2/ Place your native sources under $PROJECT/jni/... 3/ Write $PROJECT/jni/Android.mk to describe your sources
to the NDK build system 4/ Write apps/<myapp>/Application.mk to describe your application
and the native sources it needs to the NDK build system 5/ Build your native code by running "make APP=<myapp>"
in the top-level NDK directory.你把NDK仔细看看就知道怎么弄了~~
其实多看看源码,很多问题都能找到答案
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
# Tell it to build an APK
include $(BUILD_PACKAGE)Building a APK that depends on a static .jar file LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# List of static libraries to include in the package
LOCAL_STATIC_JAVA_LIBRARIES := static-library
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
# Tell it to build an APK
include $(BUILD_PACKAGE)Building a APK that should be signed with the platform key LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_CERTIFICATE := platform
# Tell it to build an APK
include $(BUILD_PACKAGE)Building a APK that should be signed with a specific vendor key LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Name of the APK to build
LOCAL_PACKAGE_NAME := LocalPackage
LOCAL_CERTIFICATE := vendor/example/certs/app
# Tell it to build an APK
include $(BUILD_PACKAGE)Adding a prebuilt APK LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Module name should match apk name to be installed.
LOCAL_MODULE := LocalModuleName
LOCAL_SRC_FILES := $(LOCAL_MODULE).apk
LOCAL_MODULE_CLASS := APPS
LOCAL_MODULE_SUFFIX := $(COMMON_ANDROID_PACKAGE_SUFFIX)
include $(BUILD_PREBUILT)Adding a Static Java Library LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Build all java files in the java subdirectory
LOCAL_SRC_FILES := $(call all-subdir-java-files)
# Any libraries that this library depends on
LOCAL_JAVA_LIBRARIES := android.test.runner
# The name of the jar file to create
LOCAL_MODULE := sample
# Build a static jar file.
include $(BUILD_STATIC_JAVA_LIBRARY)找到点相关资料,现在只试了使用jar库,可以使用。非常感谢各位!
LOCAL_MODULE := 动态库名
LOCAL_SRC_FILES := C++文件名LOCAL_CPPFLAGS := -I$(LOCAL_PATH)/../../../Android/Include -I$(LOCAL_PATH)/../../../Android/Include/Embedded -I$(LOCAL_PATH)/../../../Android/LibShare/stlport/stlportLOCAL_LDLIBS := -ldl -lzLOCAL_STATIC_LIBRARIES := 静态包名
include $(BUILD_SHARED_LIBRARY)