美文网首页
android ndk开发-android.mk

android ndk开发-android.mk

作者: To_HG | 来源:发表于2019-04-16 11:18 被阅读0次

    最近在研究ndk开发,需要编译动态库so或者静态库.a文件,就在Android.mk文件中配置,

    首先在jni下创建Android.mk,然后在app的build.gradle里配置文件路径 Android.mk:
    LOCAL_PATH := $(call my-dir)
    #加载动态库
    include $(CLEAR_VARS)
    LOCAL_MODULE := curl
    LOCAL_SRC_FILES := libcurl.so
    include $(PREBUILT_SHARED_LIBRARY)# PREBUILT_SHARED_LIBRARY动态库
    
    # 加载静态库
    include $(CLEAR_VARS)
    LOCAL_MODULE    := soundiotarch
    LOCAL_SRC_FILES := libsoundiot_sdk_arch64.a
    include $(PREBUILT_STATIC_LIBRARY) # PREBUILT_STATIC_LIBRARY静态文件
    
    # Program
    include $(CLEAR_VARS)
    LOCAL_MODULE := soundplus #编译so库名字
    LOCAL_SRC_FILES :=com_aitek_soundplus_sound_SoundDenoise.c #自己的c文件
    LOCAL_C_INCLUDES += $(LOCAL_PATH)/include        #头文件搜索路径
    LOCAL_LDLIBS :=-llog -lz                         #附加的链接器选项
    LOCAL_STATIC_LIBRARIES := curl soundiotarch  #编译上面两个lib
    include $(BUILD_SHARED_LIBRARY) #$(BUILD_STATIC_LIBRARY)编译成so库或者.a文件
    

    最后加载

    package com.aitek.soundplus.sound;//c文件提供native方法必须包名一样
    public class SoundDenoise {
        static {
            System.loadLibrary("soundplus");
        }
    }
    

    相关文章

      网友评论

          本文标题:android ndk开发-android.mk

          本文链接:https://www.haomeiwen.com/subject/aaevwqtx.html