简体   繁体   English

在Android Studio gradle项目中使用NDK和STL

[英]Using NDK with STL in Android Studio gradle project

I have a trouble with linking stlport into gradle project in Android Studio. 我在将stlport链接到Android Studio中的gradle项目时遇到了麻烦。

Eclipse Android project with using NDK migrates into Android Studio. 使用NDK的Eclipse Android项目迁移到Android Studio。

The project uses STL and I have android.mk file with contents 该项目使用STL,我有android.mk文件的内容

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := MyProject
LOCAL_SRC_FILES := jniapi.cpp renderer.cpp
LOCAL_LDLIBS    := -llog -landroid -lEGL -lGLESv1_CM -ljnigraphics

include $(BUILD_SHARED_LIBRARY)

It seems gradle to ignore .mk file, and I added the folowing code into build.gradle file: 忽略.mk文件似乎有点儿,我将以下代码添加到build.gradle文件中:

ndk {
   moduleName "MyProject"
   stl "stlport_shared"
   ldLibs "log", "EGL", "android", "jnigraphics", "GLESv1_CM"
   //No equivalent for the "include $(BUILD_SHARED_LIBRARY)" here
}

After this gradle building became successful, but running the application on device causes an error: 此gradle构建成功后,但在设备上运行应用程序会导致错误:

27446-27446/com.example.test E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libstlport_shared.so" needed by "libMyProject.so"; caused by load_library(linker.cpp:745): library "libstlport_shared.so" not found

You need to load the stlport shared library manually in your Java code if you are using the shared variant. 如果使用共享变体,则需要在Java代码中手动加载stlport共享库。 If you do not need the shared variant, specify stlport_static instead: 如果您不需要共享变体,请指定stlport_static:

ndk {
    moduleName "MyProject"
    stl "stlport_static"
    ldLibs "log", "EGL", "android", "jnigraphics", "GLESv1_CM"
    //No equivalent for the "include $(BUILD_SHARED_LIBRARY)" here
}

I think the newer way to do this is to use APP_STL in your Application.mk, something like this: 我认为更新的方法是在Application.mk中使用APP_STL,如下所示:

APP_STL := c++_shared
APP_ABI := armeabi-v7a
NDK_TOOLCHAIN_VERSION := clang

See the official documentation here: https://developer.android.com/ndk/guides/application_mk.html 请参阅此处的官方文档: https//developer.android.com/ndk/guides/application_mk.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM