什么是Android.mk中的target_link_libraries等效项

时间:2019-03-23 16:44:24

标签: android android-ndk opensl android.mk android-assetmanager

我正在尝试使用Android.mk编译android项目,并且需要包含以下库:native-audio-jni android log OpenSLES。 包含相同库但使用CMakeLists.txt而不是Android.mk的类似项目(https://github.com/googlesamples/android-ndk/tree/master/native-audio)在CMakeLists.txt中具有以下行:

target_link_libraries(native-audio-jni android log OpenSLES)

此示例项目可以正常运行。

根据有关该主题的在线研究发现,我尝试将以下行添加到jni文件夹中的Android.mk文件中:

LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -lOpenSLES -lnative-audio-jni
LOCAL_LDLIBS    += -landroid
ldLibs = ["android", "log", "native-audio-jni", "OpenSLES"]
LOCAL_SHARED_LIBRARIES += libandroid
LOCAL_LDLIBS := -llog

但是,我仍然收到类似以下错误:

undefined reference to `AAssetManager_fromJava'
undefined reference to `AAssetManager_open'
undefined reference to `SL_IID_SEEK'
undefined reference to `SL_IID_MUTESOLO' ...

我的.c文件中还包含以下内容,其中会生成错误:

// for native audio
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>

// for native asset manager
#include <sys/types.h>
#include <android/asset_manager.h>
#include <android/asset_manager_jni.h>
#include <android/log.h>

所以我的问题是:如何将这些库添加到我的Android.mk中,或者换句话说:Android.mk中的target_link_libraries(native-audio-jni android log OpenSLES)等效于什么?由于多种原因,我需要在项目中使用Android.mk而不是CMakeLists.txt。

如果有任何帮助,这也是我的build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 27

defaultConfig {
        applicationId "com.google.ar.sceneform.samples.drawing"

    // 24 is the minimum since ARCore only works with 24 and higher.
    minSdkVersion 24
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    ndk {
        //ldLibs "android", "log", "native-audio-jni", "OpenSLES" // Not helping
        /*
         * Sceneform is available for the following ABIs: arm64-v8a, armv7a,
         * x86_64 and x86. This sample app enables arm64-v8a to run on
         * devices and x86 to run on the emulator. Your application should
         * list the ABIs most appropriate to minimize APK size (arm64-v8a recommended).
         */
        abiFilters 'arm64-v8a' ,'x86' // , 'armeabi-v7a'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

externalNativeBuild {
    ndkBuild {
        path '../jni/Android.mk'
    }
}

    lintOptions {
        abortOnError false
    }
}

dependencies {
    //implementation fileTree(dir: 'libs', include: ['*.jar']) // NOT helping
    implementation 'com.google.ar.sceneform.ux:sceneform-ux:1.7.0'
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation files('Libs/YouTubeAndroidPlayerApi.jar')
    implementation 'com.github.barteksc:android-pdf-viewer:2.0.3'
    implementation 'com.xw.repo:bubbleseekbar:3.19-lite'
}
repositories {
    mavenCentral()
}

apply plugin: 'com.google.ar.sceneform.plugin'

sceneform.asset('sampledata/models/andy.obj',
        'default',
        'sampledata/models/andy.sfa',
        'src/main/res/raw/andy')

还有我的Android.mk文件:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

include $(CLEAR_VARS)
LOCAL_MODULE := aubio
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/libaubio.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := pitch
LOCAL_SRC_FILES := pitch.c
LOCAL_SHARED_LIBRARIES := aubio
include $(BUILD_SHARED_LIBRARY)

LOCAL_LDLIBS := -llog -lOpenSLES -lnative-audio-jni -landroid

这是内置错误的屏幕截图: enter image description here

1 个答案:

答案 0 :(得分:0)

您的 Android.mk 出现了一些不必要的定义,这些定义毁于一旦掩盖了他的正确答案:

LOCAL_LDLIBS := -llog -lOpenSLES -lnative-audio-jni -landroid

代替您发布的所有行。 NDK知道在哪里可以找到这些库,因此-L$(SYSROOT)/…不是必需的,但只会造成伤害。其他几行可能来自无奈。

相关问题