Cocos2d-x extensions in an Android app - android

I'm having trouble using CCHttpRequest in an Android app that's part of a Cocos2d-x project. Specifically I get a bunch of build errors when building in Eclipse that I don't get when building the iOS app in Xcode.
An example build error that I receive in Eclipse (but not in Xcode) is:
`Type 'CCHttpResponse' could not be resolved`
This error is for the line:
CCHttpResponse *response = (CCHttpResponse *)data;
Both Eclipse and Xcode projects reference the same .cpp files. To make the Eclipse project aware of the Cocos2d-x extensions I did the following:
Open Project => Properties => C/C++ General => Paths and Symbols => Source Location
Click Link Folder...
Check Link to folder in the file system
Browse to the folder containing the extensions (that work in the Xcode project)
Click Ok, Apply, and Ok
Note there are some other surprising errors in my HelloWorldScene.cpp file. For example:
Symbol 'vector' could not be resolved.
I'm guessing the problem is related to how I've set-up something in Eclipse. Since I'm new to Eclipse I'm not sure what to try. Everything builds and runs fine in the Xcode project.
Edit #1: After commenting the code responsible for most of the Eclipse build errors I noticed the error:
`make: *** [obj/local/armeabi/libgame.so] Error 1`
I don't know what this means but it seems like it might be a more fundamental error than unresolved symbols.
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/StringHelper.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1

I think Android.mk and Application.mk have some problem, Because in my application Android.mk is loading more files, and my application is running properly in both platform android and ios. You can see the differences.. it may help you. I am also using cocos2dx library.
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/FixPhotoScene.cpp \
../../Classes/SplashScene.cpp \
../../Classes/TableViewTest.cpp\
../../Classes/ProcessImage.cpp \
../../Classes/TestUI.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,CocosDenshion/android)
$(call import-module,extensions)
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)
Application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1

Related

Can't compile Cocos2d-x Game for Android because of Admob Plugin

I made a game with cocos2d-x and it runs without any problems on iOS, I have already released it on the App Store. But somehow it doesn't work on Android, i tried compiling it wtih the command "cocos compile -s ~/path/to/game/ -p android" but I get the following error:
/Users/lukas/Documents/CocosGame/Classes/AppDelegate.cpp:27:10: fatal error: 'PluginAdMob/PluginAdMob.h' file not found
#include "PluginAdMob/PluginAdMob.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.
I defined the build type in the gradle properties as: "PROP_BUILD_TYPE=ndk-build". In Android.mk i correctly inlcude all my plugins, it looks like this:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyGame_shared
LOCAL_MODULE_FILENAME := libMyGame
LOCAL_SRC_FILES := \
$(LOCAL_PATH)/../../../Classes/AppDelegate.cpp \
# $(LOCAL_PATH)/hellocpp/main.cpp \
$(LOCAL_PATH)/../../../Classes/MenuScene.cpp \
all classes...
LOCAL_CPPFLAGS := -DSDKBOX_ENABLED \
-DSDKBOX_COCOS_CREATOR
LOCAL_LDLIBS := -landroid \
-llog
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes
# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END
LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox
LOCAL_WHOLE_STATIC_LIBRARIES += PluginSdkboxAds
LOCAL_WHOLE_STATIC_LIBRARIES += PluginAdMob
LOCAL_WHOLE_STATIC_LIBRARIES += PluginShare
LOCAL_WHOLE_STATIC_LIBRARIES += PluginSdkboxPlay
LOCAL_STATIC_LIBRARIES := cc_static
# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END
include $(BUILD_SHARED_LIBRARY)
$(call import-add-path, $(LOCAL_PATH))
$(call import-module, cocos)
$(call import-module, ./sdkbox)
$(call import-module, ./PluginSdkboxAds)
$(call import-module, ./PluginAdmob)
$(call import-module, ./PluginShare)
$(call import-module, ./PluginSdkboxPlay)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END
How can I fix this error? I tried to find a solution for a few hours now but nothing works for me...

Cocos2d-x 3.X build Android "cocos2d.h" file not found

I am using build_native.py to build to Android platform, but it says
"fatal error: fatal error:'cocos2d.h' file not found".
Before this problem it says can't import import module and I set NDK_MODULD_PATH in environment variable to fix it I don't know if this cause this problem.
In file included from jni/hellocpp/main.cppIn file included from
jni/../../Class
es/AppDelegate.cppIn file included from jni/../../Classes/GameOverScene.cpp:1:
::jni/../../Classes/GameOverScene.h1:
:4:10: jni/../../Classes/AppDelegate.hfatal error: :4'cocos2d.h' file not found1
:
In file included from #include "cocos2d.h"
this is my 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/Adapter.cpp \
../../Classes/ControlLayer.cpp \
../../Classes/GameOverScene.cpp \
../../Classes/GameRunScene.cpp \
../../Classes/GameStartScene.cpp \
../../Classes/SceneManager.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../cocos2d/cocos/physics
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../libcocos2d
LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_STATIC_LIBRARIES := cocos2dx_extension_static
LOCAL_LDLIBS += -L$(call host-path,$(NDK_ROOT)/sources/cxx-stl/llvm-libc++/libs/$(TARGET_ARCH_ABI)) -lc++_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,./prebuilt-mk)
In this situation, most error comes from wrong Path setting of NDK_MODULD_PATH. I once met this error when using Cocos2d-x 2.2.6. And I suggest you checking the path of NDK_MODULE_PATH again to set it to
${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source;${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt
replace ${COCOS2DX_ROOT} to your own path. You can also check this article, although it is talking about Cocos2d-x 2.x.
I miss this error also when I use cocos2d-x-3.7.My solution is at jni/Android.mk set:
LOCAL_STATIC_LIBRARIES := cocos2d_lua_static
see more at this FixBug

Include Protobuf Library - cocos2dx

Hi I would like to add protobufs to my project. So far I am only trying with android and have not been lucky so far.
I have placed my libs : libprotobuf.a , libprotobuf-lite.a, libprotoc.a in "Protobuf" folder right where "Classes" folder can be found.
I have generated one Proto named "Msg.pb.cc" and placed it in Classes folder.
I have placed the Protobuf .h files in the classes folder. i.e. Classes/google/protobuf/....
This is what my Android.mk looks right now.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotoc
LOCAL_SRC_FILES := ../../Protobuf/libprotoc.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf-lite
LOCAL_SRC_FILES := ../../Protobuf/libprotobuf-lite.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf.a
LOCAL_SRC_FILES := ../../Protobuf/libprotobuf.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_CPP_EXTENSION := .cxx .cpp .cc
LOCAL_SRC_FILES += hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/GameSprite.cpp \
../../Classes/GameLayer.cpp \
../../Classes/Control.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/NativeInterface.cpp \
../../Classes/Msg.pb.cc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,CocosDenshion/android)
$(call import-module,extensions)
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)
I get a lot of errors as soon as it compiles the Msg.pb.cc. Here's a few:
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
Somehow, I guess the files are not linked. The code is unable to find the protobuf library.
I don't know how Android.mk files are written and do not have much experience with cpp as well. This is just the result of some google searches and reading the original Android.mk file.
Any help is appreciated.
-cocos2dx-2.2.5
-eclipse+ADT.
-sdk 5.0.1
-ndk r8e

Error in compiling cocos2d-x project for android when using json

I'am using cocos2d-x version 3.3rc
In some of my class I #include "cocos2d/external/json/writer.h"
when I want to compile my project to make android apk, by running build_native.py script, it shows the following error to me:
fatal error: cocos2d/external/json/writer.h: No such file or directory
But I include its file in my android.mk file with this syntax:
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../../cocos2d/external/json \
And here is the complete android.mk file:
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/Database/CacheData.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../../cocos2d/external/json
#LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static
LOCAL_WHOLE_STATIC_LIBRARIES += json_external_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
How can I fix the problem?
I found the solution.
In cocos2d-x version 3.3 the default android.mk file that generated is sufficient and all other library was imported. Then the default android.mk file in jni folder was completely integrated with other .mk files. i see that the files in json folder that located in 'cocos2s/external/json' are .h files and there is no dependency between them and other cocos2d files and library.
then I simply copy this folder to my Classes folder and include them locally.Now the problem is solved :)

Android NDK:linking static library with shared library

Iam trying to compile my native code. Here is my android.mk file
//part1-static lib
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := irrlicht
IRRLICHT_LIB_NAME := lib$(LOCAL_MODULE).a
LOCAL_C_INCLUDES := include
LOCAL_SRC_FILES := \
CColorConverter.cpp \
CCSMLoader.cpp \
CCubeSceneNode.cpp \
CD3D8Driver.cpp \
include $(BUILD_STATIC_LIBRARY)
//part-2 shared lib
include $(CLEAR_VARS)
LOCAL_MODULE := irrlichttest
LOCAL_SRC_FILES := test-app.cpp test.cpp android-receiver.cpp
LOCAL_C_INCLUDES := include
LOCAL_CFLAGS := -O3 -DANDROID_NDK -DDISABLE_IMPORTGL -I$(LOCAL_PATH)/../include/ - I./include/
LOCAL_CPPFLAGS := -Wno-error=format-security
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog -lGLESv2
LOCAL_STATIC_LIBRARIES := irrlicht
include $(BUILD_SHARED_LIBRARY)
and here is my application.mk
APP_ABI := armeabi armeabi-v7a
APP_PLATFORM := android-10
APP_MODULE := irrlicht irrlichttest
i want to compile "irrlicht" module first and then "irrlichttest' module. The problem iam facing is my irrlichttest module compile first and it start looking for reference and give me undefined reference error.Right now If i compile part1(static lib) only it successfully generate libirrlicht.a, But with part2 it start giving me error. What am i doing wrong.
You have one extra \ at the end of your first LOCAL_SRC_FILES definition, this makes the 'include $(BUILD_STATIC_LIBRARY)' part go into LOCAL_SRC_FILES, and the line is never parsed / executed. In other words, due to this your module definition for the 'iirlicht' module is completely ignored by ndk-build, hence the problem you're seeing.
Remove the \ after CD3D8Driver.cpp, and that should fix it.
NDK will compile the irrlichttest sources, then irrlich sources, then create libirrlich.a, and only after that it will link libirrlichttest.so. It is very insightful to run
ndk-build clean all V=1
and see in the build log which commands are actually executed to build the project.

Categories

Resources