Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add cocos2dx_static #715

Closed
wants to merge 2 commits into from

4 participants

@folecr

Add a cocos2dx_static library.

@minggo
Owner

As mentioned in NDK_ROOT/documentation.html.

LOCAL_STATIC_LIBRARIES
The list of static libraries modules (built with BUILD_STATIC_LIBRARY)
that should be linked to this module. This only makes sense in
shared library modules.

So we can not use LOCAL_STATIC_LIBRARIES when building a static library.
I have tried this way, and it failed.
Did you try it?

@folecr

Thanks for reviewing.

Could you send me the command you use to build?
I am using the modules documentation from NDK_ROOT/docs/IMPORT-MODULE.html

I am trying to build with either gnustl_static or stlport_static. My build is successful but I am seeing an error at runtime in libc.

@minggo
Owner

I use tests/test.android/build_native.sh to build tests.
And I meet the problem that when I build game_logic_shared module(refer tests/android.mk), it says that:

E:/cocos2d-x/tests/test.android/obj/local/armeabi/libcocos2d.a(CCImage.o): In fu
nction pngReadCallback(png_struct_def*, unsigned char*, unsigned int)':
CCImage.cpp:(.text._ZL15pngReadCallbackP14png_struct_defPhj+0xe): undefined refe
rence to
png_get_io_ptr'
CCImage.cpp:(.text._ZL15pngReadCallbackP14png_struct_defPhj+0x60): undefined ref
erence to `png_error'

There are many other errors.
It seems that it can not link to libpng, libjpeg and libxml2.
I also add

LOCAL_STATIC_LIBRARIES := curl_static_prebuilt
LOCAL_STATIC_LIBRARIES += png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libcurl)
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

in tests/Android.mk, but can not resolve the problem.

@folecr
@minggo
Owner

May be my question is:
cocos2dx is a static library, it dependents some other static libraries: libpng, libjpeg and libxml2.
Some other shared library dependents cocos2dx, then how to write the correct Android.mk?

@minggo
Owner

I think I find the method.
I should add

LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_STATIC_LIBRARIES += png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

in every module that depends cocos2dx.
Is there any good method to do like this?

@folecr
@moadib

I see that next cocos2d-x update will be pain in the ass for android-platform as previous :\ To many changes that do nothing usefull...

@minggo
Owner

I think it is useful, because many developers meet error when building with NDK.
And build cocos2dx as a static lib will remove the error when using dynamic_cast.

@moadib

I mean this romp with submodules and dynamic_cast. Static linking now strictly necessarily, confirm this. I've spended some time to find reason of app crashing after last update and damned author of "change to dynamic_cast" after found it :)

In my case, application must use LOCAL_WHOLE_STATIC_LIBRARIES to cocos2d-x to prevent jni-functions stripping.

You're must be very careful with such changes. This is reasons for some developers thinking that cocos2d-x not ready yet. Then we all know that it is very good library and ready for production :)

@minggo
Owner

Thank you moadib.
I will try LOCAL_WHOLE_STATIC_LIBRARIES to prevent jni-functions stripping.

@minggo
Owner

I use LOCAL_WHOLE_STATIC_LIBRARIES in cocos2dx/Android.mk.
But module that dependents cocos2dx should also import libpng, libxml2 and libjpeg also.

@moadib

I didn't examine module system yet. But for 0.11.0 it is nessesary to move all dependencies from cocos2d-x .mk to application .mk for static linking.

@folecr

Please see my recent updates to the pull request. I've added LOCAL_WHOLE_STATIC_LIBRARIES to the cocos2d-x makefiles.

Here is the NDK only project I am using (no Java files)
https://github.com/folecr/cocosdemo-android-ndk

Makefile used to integrate cocos2d-x is here:
https://github.com/folecr/cocosdemo-android-ndk/blob/master/jni/Android.mk

Note that I am trying to move away from crystax C++ libs and to gnustl from the Android NDK.

I am getting errors from spurious symbols defined in libjpeg :
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(djpeg.o): In function main':
/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/djpeg.c:426: multiple definition of
main'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(jpegtran.o): In function main':
/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/jpegtran.c:370: multiple definition of
main'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(rdjpgcom.o): In function main':
/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/rdjpgcom.c:455: multiple definition of
main'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(wrjpgcom.o): In function main':
/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/wrjpgcom.c:414: multiple definition of
main'
/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/jpeg.a(cjpeg.o):/cygdrive/e/android-ndk-r4-crystax/samples/jpeg-8c/jni/cjpeg.c:495: first defined here
collect2: ld returned 1 exit status
make: *** [/Users/folecr/ws/open/Cocos/cocosdemo-android-ndk/obj/local/armeabi/libnative-activity.so] Error 1

@folecr

My next steps will probaly be to build libjpeg, libpng, libxml2 from source...

@folecr

Please discuss if this is the right direction for the project.

Here are my goals :

  • Use Android supported libs where possible
  • Use an Android recommended makefile where possible, so that other Android developers may use Cocos2D-x easily and correctly
  • Build from source (no binary blobs for cocos2d-x developers)
  • Produce binary blobs for users of cocos2d-x
  • Reduce dependency on Java code... produce an example app using C/C++ code only. (I don't know if this is possible.)

Thanks!

@minggo
Owner

We only provide source for developers.
We should support android from level 2.1, so we can not produce an example app using C/C++ code only.

Could you please modify the codes from cocos2d-x(including HelloWorld, tests and cocos2dx), not only for cocos2d-x/cocos2dx. Then our environment will be the same.

We divides game logic into two parts: such as HelloWorld/Classes and HelloWorld/android. All the .cpp files under HelloWorld/Classes are platform-independent. So there are two Android.mk(HelloWorld/Classes/Andorid.mk and HelloWorld/android/jni/helloworld/Android.mk).

Of course we can only have one Android.mk just as previous version: including all HelloWorld/Classes/*.cpp files in HelloWorld/android/jni/helloworld/Android.mk. Then obj files will be put in HelloWorld/android/obj/local, not in HelloWorld/android/obj/local/TARGET_ARCH_ABI.

This can cause error when building multiple targets(armeabi and x86) at the same time. Suppose building armeabi first, x86 second. When building x86, the objs are exist in HelloWorld/android/obj/local, then it will not rebuild files under HelloWorld/Classes. This cause link error, because the objs are arm format.

@folecr

Our goals are not in conflict :)

Use Android supported libs where possible

We both agree? ie, move away from using Crystax C++ libs. Is there any dependency on external libs other than Crystax?

Use an Android recommended makefile where possible, so that other Android developers may use Cocos2D-x easily and correctly

We both agree.

Build from source (no binary blobs for cocos2d-x developers)

We both agree. Further, I think we should build libjpeg, libpng and libxml2 from source also.

Produce binary blobs for users of cocos2d-x

We only provide source for developers.

OK. Agreed. Primary deliverable must be source code.

Reduce dependency on Java code... produce an example app using C/C++ code only. (I don't know if this is possible.)

We should support android from level 2.1, so we can not produce an example app using C/C++ code only.

I think both are possible. ie,

  • If using Android 2.2 Java and JNI layer will be developed and used.
  • Android 2.3 and above I will try to use C/C++ only. I don't think this is possible because of TextInput requirements of Cocos. Also a game will have to use Java anyway. Still, I would personally like a C/C++ only library for a game engine. Again, I don't know if this is possible yet :)
@minggo
Owner

I use LOCAL_WHOLE_STATIC_LIBRARIES in other module that dependent cococos2dx and add
LOCAL_STATIC_LIBRARIES := png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

There is not error, and prevent jni-functions stripping.
I will pull request soon.

@folecr

I will take a look at HelloWorld, classes and the x86 Android build tomorrow.

@minggo
Owner

We both agree. Further, I think we should build libjpeg, libpng and libxml2 from source also.

But it will add compile time. I think we can offer source code, but use prebuilt lib as default. Developers can use source code if they want to.

Is there any dependency on external libs other than Crystax?

Because at first, stl is not supported by NDK, so we use Crystax version to build libpng, libjpeg. We should rebuild them. You are appreciated if you can do it for the community.

As far as I know, C++ now can not receive input message.

@minggo
Owner

folecr, moadib

I have pulled a request in #716.
Could you please discuss there?

Now I have to include libpng, libjpeg and so on in every module that dependents cocos2dx.
Could you please optimize it if possible based on my pull request?

And I think this pull request should be closed.
folecr, are you agree with me?

@walzer
Owner

Hi moadib, I think using RTTI is required, otherwise the code would be too fat.
Or do you have any smart resolution instead of RTTI? We can discuss in forum.
Sorry about digress from the topic. Go ahead guys.

@folecr

I have pulled a request in #716. Could you please discuss there?

OK.

And I think this pull request should be closed. folecr, are you agree with me?

Yes. Thanks.

@minggo minggo closed this
@pigpigyyy pigpigyyy referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@pigpigyyy pigpigyyy referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@rubymix rubymix referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@rubymix rubymix referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
@angeltown angeltown referenced this pull request from a commit in angeltown/cocos2d-x
@minggo minggo fixed #715: make sure selected image is valid 47ac0af
@angeltown angeltown referenced this pull request from a commit in angeltown/cocos2d-x
@minggo minggo fixed #715: make sure selected image is valid 92f1a98
@sumanx sumanx referenced this pull request from a commit in sumanx/cocos2d-x
@minggo minggo fixed #715: make sure selected image is valid cb5b1eb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 8, 2012
  1. @folecr

    Add cocos2dx_static

    folecr authored
Commits on Feb 9, 2012
  1. @folecr
This page is out of date. Refresh to see the latest.
Showing with 136 additions and 1 deletion.
  1. +136 −1 cocos2dx/Android.mk
View
137 cocos2dx/Android.mk
@@ -2,6 +2,8 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
+# A shared library for cocos2d
+
LOCAL_MODULE := cocos2dx_shared
LOCAL_MODULE_FILENAME := libcocos2d
@@ -109,7 +111,7 @@ touch_dispatcher/CCTouchHandler.cpp
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ \
$(LOCAL_PATH)/include \
$(LOCAL_PATH)/platform
-
+
LOCAL_EXPORT_LDLIBS := -llog\
-lz \
-lGLESv1_CM
@@ -131,6 +133,139 @@ LOCAL_CFLAGS := -DUSE_FILE32API
include $(BUILD_SHARED_LIBRARY)
+include $(CLEAR_VARS)
+
+# A static library for cocos2d
+
+LOCAL_MODULE := cocos2dx_static
+
+LOCAL_MODULE_FILENAME := libcocos2d
+
+LOCAL_SRC_FILES := \
+CCConfiguration.cpp \
+CCDrawingPrimitives.cpp \
+CCScheduler.cpp \
+CCCamera.cpp \
+actions/CCAction.cpp \
+actions/CCActionCamera.cpp \
+actions/CCActionEase.cpp \
+actions/CCActionGrid.cpp \
+actions/CCActionGrid3D.cpp \
+actions/CCActionInstant.cpp \
+actions/CCActionInterval.cpp \
+actions/CCActionManager.cpp \
+actions/CCActionPageTurn3D.cpp \
+actions/CCActionProgressTimer.cpp \
+actions/CCActionTiledGrid.cpp \
+base_nodes/CCAtlasNode.cpp \
+base_nodes/CCNode.cpp \
+cocoa/CCAffineTransform.cpp \
+cocoa/CCGeometry.cpp \
+cocoa/CCAutoreleasePool.cpp \
+cocoa/CCData.cpp \
+cocoa/CCNS.cpp \
+cocoa/CCObject.cpp \
+cocoa/CCSet.cpp \
+cocoa/CCZone.cpp \
+cocos2d.cpp \
+CCDirector.cpp \
+effects/CCGrabber.cpp \
+effects/CCGrid.cpp \
+keypad_dispatcher/CCKeypadDelegate.cpp \
+keypad_dispatcher/CCKeypadDispatcher.cpp \
+label_nodes/CCLabelAtlas.cpp \
+label_nodes/CCLabelBMFont.cpp \
+label_nodes/CCLabelTTF.cpp \
+layers_scenes_transitions_nodes/CCLayer.cpp \
+layers_scenes_transitions_nodes/CCScene.cpp \
+layers_scenes_transitions_nodes/CCTransitionPageTurn.cpp \
+layers_scenes_transitions_nodes/CCTransitionRadial.cpp \
+layers_scenes_transitions_nodes/CCTransition.cpp \
+menu_nodes/CCMenu.cpp \
+menu_nodes/CCMenuItem.cpp \
+misc_nodes/CCMotionStreak.cpp \
+misc_nodes/CCProgressTimer.cpp \
+misc_nodes/CCRenderTexture.cpp \
+misc_nodes/CCRibbon.cpp \
+particle_nodes/CCParticleExamples.cpp \
+particle_nodes/CCParticleSystem.cpp \
+particle_nodes/CCParticleSystemPoint.cpp \
+particle_nodes/CCParticleSystemQuad.cpp \
+platform/CCFileUtils.cpp \
+platform/CCGL.cpp \
+platform/CCImage.cpp \
+platform/CCStdC.cpp \
+platform/CCSAXParser.cpp \
+platform/CCThread.cpp \
+platform/CCCommon.cpp \
+platform/platform.cpp \
+platform/android/CCEGLView_android.cpp \
+platform/android/CCAccelerometer_android.cpp \
+platform/android/CCApplication_android.cpp \
+platform/android/jni/JniHelper.cpp \
+platform/android/jni/IMEJni.cpp \
+platform/android/jni/MessageJni.cpp \
+platform/android/jni/SensorJni.cpp \
+platform/android/jni/SystemInfoJni.cpp \
+platform/android/jni/TouchesJni.cpp \
+script_support/CCScriptSupport.cpp \
+sprite_nodes/CCAnimation.cpp \
+sprite_nodes/CCAnimationCache.cpp \
+sprite_nodes/CCSprite.cpp \
+sprite_nodes/CCSpriteBatchNode.cpp \
+sprite_nodes/CCSpriteFrame.cpp \
+sprite_nodes/CCSpriteFrameCache.cpp \
+support/CCArray.cpp \
+support/CCProfiling.cpp \
+support/CCPointExtension.cpp \
+support/TransformUtils.cpp \
+support/CCUserDefault.cpp \
+support/base64.cpp \
+support/ccUtils.cpp \
+support/image_support/TGAlib.cpp \
+support/zip_support/ZipUtils.cpp \
+support/zip_support/ioapi.cpp \
+support/zip_support/unzip.cpp \
+text_input_node/CCIMEDispatcher.cpp \
+text_input_node/CCTextFieldTTF.cpp \
+textures/CCTexture2D.cpp \
+textures/CCTextureAtlas.cpp \
+textures/CCTextureCache.cpp \
+textures/CCTexturePVR.cpp \
+tileMap_parallax_nodes/CCParallaxNode.cpp \
+tileMap_parallax_nodes/CCTMXLayer.cpp \
+tileMap_parallax_nodes/CCTMXObjectGroup.cpp \
+tileMap_parallax_nodes/CCTMXTiledMap.cpp \
+tileMap_parallax_nodes/CCTMXXMLParser.cpp \
+tileMap_parallax_nodes/CCTileMapAtlas.cpp \
+touch_dispatcher/CCTouchDispatcher.cpp \
+touch_dispatcher/CCTouchHandler.cpp
+
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ \
+ $(LOCAL_PATH)/include \
+ $(LOCAL_PATH)/platform
+
+LOCAL_EXPORT_LDLIBS := -llog\
+ -lz \
+ -lGLESv1_CM
+
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/ \
+ $(LOCAL_PATH)/include \
+ $(LOCAL_PATH)/platform
+
+LOCAL_LDLIBS := -lGLESv1_CM \
+ -llog \
+ -lz
+
+LOCAL_WHOLE_STATIC_LIBRARIES := png_static_prebuilt
+LOCAL_WHOLE_STATIC_LIBRARIES += xml2_static_prebuilt
+LOCAL_WHOLE_STATIC_LIBRARIES += jpeg_static_prebuilt
+
+# define the macro to compile through support/zip_support/ioapi.c
+LOCAL_CFLAGS := -DUSE_FILE32API
+
+include $(BUILD_STATIC_LIBRARY)
+
$(call import-add-path,$(LOCAL_PATH)/..)
# note that the import-module calls are relative to the parent directory
Something went wrong with that request. Please try again.