前提・実現したいこと
AndroidStudioでcocos2d-xを使ってAndroidアプリ開発をしています。
C++側からJavaで書いたメソッドの呼び出しをしたいのですが、undefined reference to〜というエラーが出てビルドができません。
調べたところメソッドが未実装というエラーのようなのですが、自分では実装しているつもりです。
どこを修正すればエラーが出なくなるでしょうか。
発生している問題・エラーメッセージ
HelloWorldScene.cpp:125: error: undefined reference to 'NativeLauncher::launchNative()' clang++: error: linker command failed with exit code 1 (use -v to see invocation) ninja: build stopped: subcommand failed.
該当のソースコード
cpp
1// HelloWorldScene.cpp 2 3#include "HelloWorldScene.h" 4#include "SimpleAudioEngine.h" 5#include "NativeLauncher.h" 6 7〜略〜 8 9void HelloWorld::menuCloseCallback(Ref* pSender) 10{ 11 NativeLauncher::launchNative(); 12}
cpp
1// NativeLauncher.h 2 3#include "cocos2d.h" 4 5#ifdef __cplusplus 6extern "C" { 7#endif 8 9#ifndef NativeLauncher_h 10#define NativeLauncher_h 11 12class NativeLauncher{ 13 public: 14 static void launchNative(); 15}; 16 17#endif 18/* NativeLauncher_h */ 19 20#ifdef __cplusplus 21} 22#endif 23
cpp
1// NativeLauncher.cpp 2 3#include <stdio.h> 4#include "NativeLauncher.h" 5#include <jni.h> 6#include "platform/android/jni/JniHelper.h" 7#define CLASS_NAME "org/cocos2dx/cpp/AppActivity" 8 9void NativeLauncher::launchNative(){ 10 cocos2d::JniMethodInfo t; 11 if(cocos2d::JniHelper::getStaticMethodInfo(t, CLASS_NAME, "launchNative", "()V")){ 12 t.env->CallStaticVoidMethod(t.classID, t.methodID); 13 t.env->DeleteLocalRef(t.classID); 14 } 15}
java
1// AppActivity.java 2 3public class AppActivity extends Cocos2dxActivity { 4 private static AppActivity me = null; 5 6 @Override 7 protected void onCreate(Bundle savedInstanceState) { 8 super.setEnableVirtualButton(false); 9 super.onCreate(savedInstanceState); 10 11〜中略〜 12 13 me = this; 14 } 15 16 public static void launchNative(){ 17 System.out.println("launchNative"); 18 } 19}
試したこと
・extern "C" の追加
・メソッド名の変更
・Android.mkへ
LOCAL_SRC_FILES := $(LOCAL_PATH)/../../../Classes/NativeLauncher.cpp
の追加
補足情報(FW/ツールのバージョンなど)
http://glassonion.hatenablog.com/entry/20150318/1426687171
https://rakuishi.com/archives/5817/
こちらのサイトを参考にコーディングしました。
Xcode上でのiOSへのBuild、Runは成功しています。
・cocos2d-x 3.17.2
・AndroidStudio 3.4.2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。