.so正确编译进apk里打包

来源:互联网 发布:用java 编写一个计算器 编辑:程序博客网 时间:2024/06/05 03:32

我先说说我犯错的 地方。

1.jni下的Android.mk里的c文件 没有写全 LOCAL_SRC_FILES := 

2.app下的Android.mk没有这句:include $(LOCAL_PATH)/jni/Android.mk

好。这样之后 make android的时候就不会报错了。会在out/target/product/generic/obj/lib下生成相应的.so。这里有就说明你的.so编译成功。

JNI下的Android.mk:

#
# Copyright 2009 Cedric Priscal
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#TARGET_PLATFORM := android-3

LOCAL_MODULE_TAGS := eng
#LOCAL_MODULE_TAGS := optional

# This is the target being built.
LOCAL_MODULE    := libserialport         //


# All of the source files that we will compile.
LOCAL_SRC_FILES :=  \
    SerialPort.c \
     RemoTIAPI.c                                                //这里只要你的jni下有多少c文件都要写完。不然。。。


# All of the shared libraries we link against.
LOCAL_SHARED_LIBRARIES := \
    libutils

# No static libraries.
LOCAL_STATIC_LIBRARIES :=

# Also need the JNI headers.
LOCAL_C_INCLUDES += \
    $(JNI_H_INCLUDE)

# No special compiler flags.
LOCAL_CFLAGS +=


#LOCAL_LDLIBS := -ldl -llog

LOCAL_PRELINK_MODULE := false

include $(BUILD_SHARED_LIBRARY)   //编译so


项目下的Android.mk:


TOP_LOCAL_PATH:= $(call my-dir)

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

#  LOCAL_MODULE_TAGS := user, eng
  LOCAL_MODULE_TAGS := optional                     //这里也要注意!这里 要与你make android源码后出现的列表里的TARGET_BUILD_VARIANT=xxx 一样
 LOCAL_SRC_FILES := $(call all-subdir-java-files)

  LOCAL_PACKAGE_NAME :=FieldTest
#  LOCAL_CERTIFICATE := platform

LOCAL_JNI_SHARED_LIBRARIES := libserialport         //安装库

## Use the folloing include to make our RemoteControl apk.
  include $(BUILD_PACKAGE)                                         //编译成apk
  include $(LOCAL_PATH)/jni/Android.mk                     //调用库的编译

# ============================================================

# Also build all of the sub-targets under this one: the shared library.
#include $(call all-makefiles-under,$(LOCAL_PATH))


其他的 注释可以在网上搜到。



原创粉丝点击