Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ndk 构建与静态库依赖项共享的_Android Ndk_Shared Libraries_Static Linking_Dynamic Linking - Fatal编程技术网

Android ndk 构建与静态库依赖项共享的

Android ndk 构建与静态库依赖项共享的,android-ndk,shared-libraries,static-linking,dynamic-linking,Android Ndk,Shared Libraries,Static Linking,Dynamic Linking,我正在尝试使用NDK构建一个共享库。我的文件夹结构有两个文件夹,一个是C++编写的( Project < /Cuff>,这是Android Studio项目。C++库编译得很好,代码。生成了文件,但它没有与共享库链接。这是我的身材。格雷德尔: buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gra

我正在尝试使用NDK构建一个共享库。我的文件夹结构有两个文件夹,一个是C++编写的(),一个是java编写的,叫做“代码> Project < /Cuff>,这是Android Studio项目。C++库编译得很好,代码<>。生成了文件,但它没有与共享库链接。这是我的身材。格雷德尔:

buildscript {

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'net.sf.proguard:proguard-gradle:5.2.1'
    }
}

apply plugin: 'android-library'

android {

    compileSdkVersion 16
    buildToolsVersion "23.0.1"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        ndk {
            moduleName "core"
            cFlags "-std=c++11 -fexceptions -I../core/includes"
            stl "stlport_shared"
        }
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            jniLibs.srcDir 'libs'
            jni.srcDirs = ['src/main/jni', 'src/main/jni/', 'jni/']
        }
    }

    task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
        def ndkDir = plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
        commandLine "$ndkDir/ndk-build",
                '-C', file('jni').absolutePath,
                '-j', Runtime.runtime.availableProcessors(),
                'all',
                'NDK_DEBUG=1'
    }

    task cleanNative(type: Exec, description: 'Clean JNI object files') {
        def ndkDir = plugins.getPlugin('com.android.library').sdkHandler.getNdkFolder()
        commandLine "$ndkDir/ndk-build",
                '-C', file('jni').absolutePath,
                'clean'
    }

    task cleanBinaryFolders(type: Delete, description: 'Clean binary folders') {
        delete 'libs', 'obj'
    }

    clean.dependsOn 'cleanNative'
    clean.dependsOn 'cleanBinaryFolders'

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn buildNative
    }
}

dependencies {
    compile 'com.android.support:support-v4:20.0.0'
}
这是我的Android.mk:

SHELL = /bin/bash

MY_HOMEDIR = $(realpath $(shell pwd)/../..)
MY_COREDIR = $(MY_HOMEDIR)/core
MY_ANDROIDDIR = $(MY_HOMEDIR)/project

MY_CORESOURCES = $(shell find $(MY_COREDIR)/src -type f -name "*.cpp")
MY_BRIDGESOURCES = $(shell find $(MY_ANDROIDDIR)/jni -type f -name "*.cpp")

LOCAL_PATH = $(MY_HOMEDIR)

# Generate a static library from the core implementation
include $(CLEAR_VARS)
LOCAL_MODULE = core
LOCAL_SRC_FILES = $(MY_CORESOURCES)
TARGET_PLATFORM = android-16
TARGET_ARCH_ABI = all
LOCAL_C_INCLUDES = $(MY_COREDIR)/includes
#LOCAL_LDLIBS = -llog
LOCAL_CFLAGS = -llog -I$(MY_COREDIR)/includes
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE = project
LOCAL_SRC_FILES = $(MY_BRIDGESOURCES)
TARGET_PLATFORM = android-16
TARGET_ARCH_ABI = all
LOCAL_STATIC_LIBRARIES = core
LOCAL_C_INCLUDES = $(MY_COREDIR)/includes
LOCAL_LDLIBS = -lcore # I’m not sure about this
LOCAL_CFLAGS = -llog -I$(MY_COREDIR)/includes
include $(BUILD_SHARED_LIBRARY)
像这样编译时,我会得到一堆
未定义的引用
错误,即使这些方法是由核心模块实现的。我遗漏了什么?

内容如下:


仅对系统库依赖项使用本地\u ldlib。如果您想指向另一个库,最好将它们列在本地\u静态\u库和本地\u共享\u库中(即使这意味着为它们定义一个预构建的\u XXX模块),因为这可以让生成系统自动为您计算依赖项和排序。

尝试将定义jni.srcDirs的行替换为
jni.srcDirs=[]