以前のリビジョンの文書です
—-
Warning: Declaration of syntax_plugin_linebreak::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in
/home/stepism/www/ue4/wiki/lib/plugins/linebreak/syntax.php on line
52
Warning: Declaration of syntax_plugin_linebreak::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in
/home/stepism/www/ue4/wiki/lib/plugins/linebreak/syntax.php on line
74
Warning: Declaration of syntax_plugin_markdownextra::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in
/home/stepism/www/ue4/wiki/lib/plugins/markdownextra/syntax.php on line
38
Warning: Declaration of syntax_plugin_markdownextra::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in
/home/stepism/www/ue4/wiki/lib/plugins/markdownextra/syntax.php on line
47
Warning: Declaration of syntax_plugin_syntaxhighlighter3_syntax::handle($match, $state, $pos, &$handler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in
/home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/syntax/syntax.php on line
53
Warning: Declaration of syntax_plugin_syntaxhighlighter3_syntax::render($mode, &$renderer, $data) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in
/home/stepism/www/ue4/wiki/lib/plugins/syntaxhighlighter3/syntax/syntax.php on line
82
087 ndk-buildで生成したライブラリを利用する
ライブラリの作成
Visual Studio 2010を起動します。
ファイル → 新規作成 → プロジェクト と選択します。
Win32 コンソールアプリケーション を選択し、プロジェクト名を「DLLImport_VS」とします。
アプリケーションの種類をDLLにチェックを入れて、追加のオプションは「空のプロジェクト」に変えて完了します。
ソースファイルを追加します。(plugin.cpp/h)
// plugin.h
extern "C"
{
int Hoge();
}
// plugin.cpp
#include "plugin.h"
int Hoge()
{
return 999;
}
ここで一度VisualStudioでビルドしてエラーが出ないか確認します。エラーが出なければAndroid用にndk-buildします。ndk-build用のAndroid.mk ファイルを用意します。
include $(CLEAR_VARS)
# override strip command to strip all symbols from output library; no need to ship with those..
cmd-strip = $(TOOLCHAIN_PREFIX)strip $1
LOCAL_ARM_MODE := arm
LOCAL_PATH := $(NDK_PROJECT_PATH)/jni
LOCAL_MODULE := libjni
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := jni.cpp
LOCAL_SRC_FILES += ../plugin.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
plugin.cpp がlibjniに含まれる様にします。
ndk-buildでエラーが出なければ.soファイルが生成されます。
Unity側にプラグインを呼び出すクラスを用意する
Unity を起動し、新規プロジェクトを作成します。名前はDLLImport とします。
Project のAssetsにPlugins → Android フォルダを作成します。
Androidフォルダに、soファイルが含まれているlibsフォルダ毎ドラッグ&ドロップします。
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
using System;
public class JNI
{
[DllImport ("jni")] public static extern int Hoge();
}
これで呼び出せる様になりました。任意の場所からJNI.Hoge() とすれば999 と値が返ってきます。
実行時にEntryPointNotFoundException エラーがが出てしまう場合は関数の実態を見つけられずにいます。例えば以下の場合は関数が見つけられずエラーが出ます。
extern "C"
{
static int Hoge();
}
#include "plugin.h"
static int Hoge()
{
return 999;
}
static 宣言が余計に付いてます。