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
Related
I am having an issue compiling a shared C library into a .so for android. I've copied all the .c and .h files into the jni folder. I posted a screenshot below to show the contents of the Android.mk file as well as the folder hierarchy.
below is the output of ndk-build run in the project root folder NTRUMLS
[kenway#jackdaw NTRUMLS]$ ndk-build
make: *** No rule to make target '/media/bigdata/Android/Sdk/ndk-bundle/build/core/crypto_hash_sha512.c', needed by 'obj/local/arm64-v8a/objs/ntrumls/crypto_hash_sha512.o'. Stop.
i checked for spaces and typo's. here's the contents of my Android.mk copied directly below.
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_PATH := $(call my-dir)
LOCAL_MODULE := libntrumls
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := crypto_hash_sha512.c \
crypto_stream.c \
convert.c \
randombytes.c \
fastrandombytes.c \
pack.c \
pol.c \
params.c \
pqntrusign.c \
shred.c
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
Move
LOCAL_PATH := $(call my-dir)
to be the first statement of your Android.mk script.
Try following
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_MODULE := libntrumls
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := Main_M1_play.cpp
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)
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
so I'm relatively new to Android-NDK and trying to add an uncompiled c-library to android.
I've downloaded the library's source from here and followed these instructions to create a static library (.a-File) from the downloaded files using ndk-build.
So now I have a folder-structure that looks like this:
-srtp
--include (srtp.h, crypto.h)
--srtp (srtp.c...)
--obj
---local
----armeabi
-----libsrtp_static.a
In my Android-project I want to include srtp.h in a c-file inside my /jni/ folder. I've tried to just add the .a-file to the /jni folder but than it says "srtp.h no such file or direcotry". If I add the entire srtp-folder to the project and include the header with "srtp/include/srtp.h" it compiles but fails to link the source as I get the error "Undefined reference to srtp-function-call"
Here's my Android.mk (parts of it copied from Android.mk within the downloaded source):
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1 #name of my project
LOCAL_SRC_FILES := native.c #name of the c-source file
include $(BUILD_SHARED_LIBRARY)
LOCAL_PATH:= /home/dev/programing/srtp
common_SRC_FILES := \
srtp/srtp.c \
srtp/ekt.c \
crypto/cipher/cipher.c \
#...more files like that
common_CFLAGS := \
-DPOSIX -iquote$(LOCAL_PATH)/crypto/include \
-Werror \
-Wno-ignored-qualifiers \
-Wno-sign-compare \
-Wno-missing-field-initializers
common_C_INCLUDES = $(LOCAL_PATH)/include
# For the device
# =====================================================
# Device static library
include $(CLEAR_VARS)
ifneq ($(TARGET_ARCH),x86)
LOCAL_NDK_VERSION := 5
LOCAL_SDK_VERSION := 9
endif
LOCAL_SRC_FILES := libsrtp_static.a
LOCAL_CFLAGS += $(common_CFLAGS)
LOCAL_C_INCLUDES += /home/dev/programing/srtp/include
LOCAL_MODULE:= libsrtp_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
Any help is greatly appreciated! Thank you very much.
You need to add the reference to libsrtp_static from your lib (ndk1) declaration :
LOCAL_STATIC_LIBRARIES := libsrtp_static
Also, you don't need to copy all the strp sources to your project, only add this to your static prebuilt library definition
LOCAL_EXPORT_C_INCLUDES += /home/dev/programing/srtp/include
This path will then be automatically added to the LOCAL_C_INCLUDES of your library that is using the library.
Are you building libsrtp or just using a prebuilt static library ? If you're using a prebuilt (lib*.a), replace BUILD_STATIC_LIBRARY with PREBUILT_STATIC_LIBRARY and set only the .a as SRC_FILE:
In summary, once libstrp_static.a is built, this should work:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -llog
LOCAL_MODULE := ndk1 #name of my project
LOCAL_SRC_FILES := native.c #name of the c-source file
LOCAL_STATIC_LIBRARIES := libsrtp_static
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := /home/dev/programing/srtp/libsrtp_static.a #check path to libsrtp_static.a
LOCAL_EXPORT_C_INCLUDES += /home/dev/programing/srtp/include
LOCAL_MODULE:= libsrtp_static
LOCAL_MODULE_TAGS := optional
include $(BUILD_STATIC_LIBRARY)
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
I meet a problem when I build the libjpeg on android in eclipse. The jni contains Android.mk as follow:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
#LOCAL_C_INCLUDES := $(LOCAL_PATH)/jpeg8d-master
#LOCAL_STATIC_LIBRARIES := libjpeg
include $(BUILD_STATIC_LIBRARY)
#include $(LOCAL_PATH)/jpeg8d-master/Android.mk
The jpeg8d is the source code I download from github. The android.mk
LOCAL_PATH:= $(call my-dir)
# ------------------------------------------------------------------
# Static library for Cocos
# ------------------------------------------------------------------
include $(CLEAR_VARS)
LOCAL_MODULE := cocos_jpeg_static
LOCAL_MODULE_FILENAME := libjpeg
LOCAL_SRC_FILES := \
jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c \
jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c \
jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c \
jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c \
jdinput.c jdmainct.c jdmarker.c jdmaster.c jdmerge.c \
jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c jfdctfst.c \
jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \
jquant2.c jutils.c jmemmgr.c jcarith.c jdarith.c jaricom.c
# Use the no backing store memory manager provided by
# libjpeg. See install.txt
LOCAL_SRC_FILES += \
jmemnobs.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_STATIC_LIBRARY)
ndk-build give the tips :
make: Nothing to be done for `all'.
But if I Set the jpeg8d Android.mk BUILD_SHARED_LIBRARY,I get the libjpeg.so.
I don't know why. Can anyone help me ?
Solution:
You can redefine the library name by the LOCAL_MODULE_FILENAME. In my problem, I have set the LOCAL_MODULE_FILENAME=libjpeg, but I don't add the
APP_MODULES:=cocos_jpeg_static (remember cocos_jpeg_staic is the LOCAL_MODULE not the LOCAL_MODULE_FILENAME) into the Application.mk which is in the jni directory not in the jpeg8d-master directory.
I generate the libjpeg.a when i add this line into the Appliction.mk
APP_MODULES:=cocos_jpeg_static