在 Android Studio gradle 项目中使用 NDK 和 STL [英] Using NDK with STL in Android Studio gradle project

查看:43
本文介绍了在 Android Studio gradle 项目中使用 NDK 和 STL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将 stlport 链接到 Android Studio 中的 gradle 项目时遇到问题.

I have a trouble with linking stlport into gradle project in Android Studio.

使用 NDK 的 Eclipse Android 项目迁移到 Android Studio.

Eclipse Android project with using NDK migrates into Android Studio.

该项目使用 STL,我有包含内容的 android.mk 文件

The project uses STL and I have android.mk file with contents

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)

似乎 gradle 忽略 .mk 文件,我将以下代码添加到 build.gradle 文件中:

It seems gradle to ignore .mk file, and I added the folowing code into build.gradle file:

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

此 gradle 构建成功后,但在设备上运行应用程序会导致错误:

After this gradle building became successful, but running the application on device causes an error:

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

推荐答案

如果您使用共享变体,则需要在 Java 代码中手动加载 stlport 共享库.如果您不需要共享变体,请改为指定 stlport_static:

You need to load the stlport shared library manually in your Java code if you are using the shared variant. If you do not need the shared variant, specify stlport_static instead:

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

这篇关于在 Android Studio gradle 项目中使用 NDK 和 STL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆