【发布时间】:2018-12-14 03:13:01
【问题描述】:
我正在制作一个用 C++ 编写的 Android 原生插件,并打包在 Unity 游戏引擎的共享库中。但是,我得到了一个 EntryPointNotFoundException,甚至是由 Android Studio 生成的默认 native-lib.cpp。
#include <jni.h>
#include <string>
extern "C" JNIEXPORT jstring JNICALL Java_com_example_willgauthier_stublibrary_MainActivity_stringFromJNI(
JNIEnv *env,
jobject /* this */) {
std::string hello = "Hello from C++";
return env->NewStringUTF(hello.c_str());
}
我在 Android Studio 中构建了该项目。然后在 Unity 中创建文件夹结构 Assets/Plugins/Android/libs 并复制到共享的 libnative-lib.so 库 armeabi-v7a和 x86。
我将此脚本附加到一个空的游戏对象:
using System;
using System.Runtime.InteropServices;
using UnityEngine;
using UnityEngine.UI;
public class LibLoadTest : MonoBehaviour
{
public Text debugText;
[DllImport("native-lib")]
private static extern string stringFromJNI();
private void Start()
{
try
{
debugText.text = stringFromJNI();
}
catch(Exception exception)
{
debugText.text = exception.ToString();
}
}
}
我的 debugText 显示“System.EntryPointNotFoundException: stringFromJNI at (wrapper managed-to-native) LibLoadTest::stringFromJNI() at LibLoadTest.Start() [0x00000] in :0”而不是“Hello from C++”。
有谁知道如何在 Unity 中成功使用 Android 的原生插件共享库以及我的过程中哪里出错了?谢谢。
【问题讨论】:
标签: android c++ unity3d plugins