Andriod源码开发,打包so到apk
命令方式将so文件 打包进apk
使用android SDK原代码 开发 APK,将so文件打包进apk,这样可以只提供给客户一个apk.
1. 含义全代码的so打包.
a) 建立工程,并使用本地调用,java文件如下
package test.jni;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView ;
public class jnitest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
int x = 55;
int y = 8;
System.loadLibrary("apptest");
//System.loadLibrary("testapi");
int z = appadd(x, y);
tv.setText( x + "+" + y + "=" + z );
setContentView(tv);
}
public native int appadd(int x, int y);
}
b) 在工程的根目录建立Android.mk,内容如下.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := user eng
LOCAL_SRC_FILES := $(call all-subdir-java-files)
LOCAL_PACKAGE_NAME := jnitest
LOCAL_JNI_SHARED_LIBRARIES := libapptest
include $(BUILD_PACKAGE)
include $(LOCAL_PATH)/jni/Android.mk
# Use the folloing include to make our test apk.
include $(call all-makefiles-under,$(LOCAL_PATH))
其中LOCAL_MODULE_TAGS名字要和目标系统 一致,否则编译 产生的apk文件不能安装到目标系统,.
LOCAL_JNI_SHARED_LIBRARIES := libapptest 把我们另外编译成的so文件放到apk文件里的libs/armeabi里
include $(LOCAL_PATH)/jni/Android.mk为了编译本地文件成为so
c) 在工程根目录创建jni文件夹,在jni文件里创建Android.mk和callapp.c,他们内容如下:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := user eng
LOCAL_MODULE := libapptest
LOCAL_SRC_FILES := callapp.c
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE)
LOCAL_PRELINK_MODULE := false
include $(BUILD_SHARED_LIBRARY)
LOCAL_MODULE_TAGS :要和工程的一致,否则编译不通过
LOCAL_C_INCLUDES += \
$(JNI_H_INCLUDE) 为了让jni编译通过,因为工程通过jni调用本地库
#include <jni.h>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>