我想在android和ios上部署一款游戏。 ios版本工作正常,编译时没有错误。但是当我运行 build_native.py 时,我得到了未定义的错误。我将在下面包含我的代码和错误消息。提前谢谢。
CODE
#ifndef __SETTING_SCENE_H__
#define __SETTING_SCENE_H__
#include "cocos2d.h"
#include "ui/CocosGUI.h"
USING_NS_CC;
using namespace ui;
class SettingScreen : public cocos2d::Layer {
public:
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(SettingScreen);
int fontSize = 18;
int bgmVolume = 100;
int sfxVolume = 100;
void Back(Ref *pSender);
void BgmSliderEvent(Ref *pSender, Slider::EventType type);
void SfxSliderEvent(Ref *pSender, Slider::EventType type);
};
#endif // __SETTING_SCENE_H__
错误
The Selected NDK toolchain version was 4.8 !
Android NDK: WARNING:jni/../../cocos2d/cocos/./Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries
Android NDK: WARNING:jni/../../cocos2d/cocos/platform/android/Android.mk:cocos2dxandroid_static: LOCAL_LDLIBS is always ignored for static libraries
make: Entering directory `/cocos2dx/TestGame/proj.android'
[armeabi] SharedLibrary : libcocos2dcpp.so
jni/../../Classes/Scenes/SettingScene.cpp:72: error: undefined reference to 'cocos2d::ui::Slider::create()'
jni/../../Classes/Scenes/SettingScene.cpp:73: error: undefined reference to 'cocos2d::ui::Slider::loadBarTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cocos2d::ui::Widget::TextureResType)'
jni/../../Classes/Scenes/SettingScene.cpp:74: error: undefined reference to 'cocos2d::ui::Slider::loadSlidBallTextures(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cocos2d::ui::Widget::TextureResType)'
jni/../../Classes/Scenes/SettingScene.cpp:80: error: undefined reference to 'cocos2d::ui::Slider::setPercent(int)'
jni/../../Classes/Scenes/SettingScene.cpp:81: error: undefined reference to 'cocos2d::ui::Slider::addEventListener(std::__1::function<void (cocos2d::Ref*, cocos2d::ui::Slider::EventType)> const&)'
jni/../../Classes/Scenes/SettingScene.cpp:91: error: undefined reference to 'cocos2d::ui::Slider::create()'
jni/../../Classes/Scenes/SettingScene.cpp:92: error: undefined reference to 'cocos2d::ui::Slider::loadBarTexture(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cocos2d::ui::Widget::TextureResType)'
jni/../../Classes/Scenes/SettingScene.cpp:93: error: undefined reference to 'cocos2d::ui::Slider::loadSlidBallTextures(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cocos2d::ui::Widget::TextureResType)'
jni/../../Classes/Scenes/SettingScene.cpp:99: error: undefined reference to 'cocos2d::ui::Slider::setPercent(int)'
jni/../../Classes/Scenes/SettingScene.cpp:100: error: undefined reference to 'cocos2d::ui::Slider::addEventListener(std::__1::function<void (cocos2d::Ref*, cocos2d::ui::Slider::EventType)> const&)'
jni/../../Classes/Scenes/SettingScene.cpp:113: error: undefined reference to 'cocos2d::ui::Slider::getPercent() const'
jni/../../Classes/Scenes/SettingScene.cpp:116: error: undefined reference to 'typeinfo for cocos2d::ui::Slider'
jni/../../Classes/Scenes/SettingScene.cpp:121: error: undefined reference to 'cocos2d::ui::Slider::getPercent() const'
jni/../../Classes/Scenes/SettingScene.cpp:124: error: undefined reference to 'typeinfo for cocos2d::ui::Slider'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1
make: Leaving directory `/cocos2dx/TestGame/proj.android'
Traceback (most recent call last):
File "TestGame/proj.android/build_native.py", line 159, in <module>
build(opts.ndk_build_param,opts.android_platform,opts.build_mode)
File "TestGame/proj.android/build_native.py", line 146, in build
do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
File "TestGame/proj.android/build_native.py", line 82, in do_build
raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
Exception: Build dynamic library for project [ /cocos2dx/TestGame/proj.android ] fails!
答案 0 :(得分:1)
您应该使用以下代码替换proj.android
目录下的Android.mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
$(call import-module,audio/android)
$(call import-module,ui)
注意LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_static
和$(call import-module,ui)
。这两行将ui依赖项添加到项目中。