Trouble compiling on Android

try once after removing NDK_MODULE_PATH from bash_profile

Sorry. I had done that and re-sourced. Still the same error.

wow what happening:D that u trying to code something in coco2d-x? Is it for some kind tutorial/documentation? :slight_smile:

which instruction u used to make project with prebuilt libraries, I can try to reproduce then to find what causing issue for you.

I’m working to write some docs on using pre-builts more and integrating them into YOUR applications, not just starting a project with cocos new. Right now, I cannot seem to compile a project with pre-builts.

1 Like

@slackmoehrle
Are you using version 3.14.1? I just asked @dumganhar, the library tremolo is added to the v3 branch of cocos2d-x. But not in the version 3.14.1.

It’s a problem of command cocos gen-libs. I’ll fix it in v3 branch later.

@zhangbin I am using v3 branch and latest download-deps

So you are saying to switch to 3.14.1 branch and recompile gen-libs and try again?

As I know, the problem should not be happened in version 3.14.1. So, you can try it by the steps you mentioned.

@slackmoehrle I just solved the problem with this PR in v3 branch.

I will test this today.

I still see this:


Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
Android NDK: Trying to define local module 'audioengine_static' in /Users/slackmoehrle/Projects/cocos2d-x/cocos/audio/android/Android.mk.
Android NDK: But this module was already defined by /Users/slackmoehrle/Projects/cocos2d-x/cocos/audio/android/prebuilt-mk/Android.mk.
/usr/local/Cellar/android-ndk/r13b/build/core/build-module.mk:34: *** Android NDK: Aborting.    .  Stop.
Error running command, return code: 2.

is it related? Any idea?

I found that you’re linking the module audio/android in your Android.mk. It’s the reason of your problem.

  1. The module audio/android has already linked in the cocos/Android.mk.
  2. When you’re using binary libraries of engine, the cocos/prebuilt-mk/Android.mk will be used ( instead of cocos/Android.mk). It will be using audio/android/prebuilt-mk/Android.mk.
  3. Then there will be conflict with the audio/android/Android.mk configured in the Android.mk of your project.

Also, I think the following configurations in your project’s Android.mk will cause similar problems:

$(call import-module,Box2D)
$(call import-module,editor-support/cocosbuilder)
$(call import-module,editor-support/spine)
$(call import-module,editor-support/cocostudio)
$(call import-module,network)
$(call import-module,extensions)

The principle of the binary libraries usage is:

  1. cocos gen-libs will generate the binary libraries & the corresponding Android.mk for each source code module. Because the Android.mk is different between source code & prebuilt libraries. (The prebuilt Android.mk will be gerenated in folder prebuilt-mk).
  2. The project should link the prebuilt Android.mk to use the binary libraries of engine.

If you mixed prebuilt Android.mk & the source code Android.mk in the Android.mk of your project. The problem you mentioned will be occurred.

Can you provide a proper Android.mk for prebuilts? I guess I don’t know how to make one.

In fact, most of the libraries you configured in the Android.mk have already linked in cocos/Android.mk & cocos/prebuilt-mk/Android.mk.

So, what you should do is remove following lines from your Android.mk:

LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosbuilder_static
LOCAL_WHOLE_STATIC_LIBRARIES += spine_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocostudio_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_network_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static


$(call import-module,audio/android)
$(call import-module,Box2D)
$(call import-module,editor-support/cocosbuilder)
$(call import-module,editor-support/spine)
$(call import-module,editor-support/cocostudio)
$(call import-module,network)
$(call import-module,extensions)

Hope it’s helpful!

1 Like

@zhangbin yup, very helpful! This will help our many users.

Hi!
The same problem.
Except I am trying to compile a new project without pre build mode.

Can you create a new project and compile it without pre build mode?

@slackmoehrle could you please me a bit please? I’ve already been struggling for like 2 days. So I’m also working with prebuilt libs, everything was working as expected on cocos2d-x-3.14 but when I updated to cocos2d-x-3.14.1 and I try to compile a Hello World application I get this error and I really couldn’t figure it out:

[armeabi] SharedLibrary  : libMyGame.so
/Users/anieduard/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: error: /Users/anieduard/cocos2d-x-3.14.1/external/flatbuffers/prebuilt-mk/../../../prebuilt/android/armeabi/flatbuffers.a(flathash.o): multiple definition of 'main'
/Users/anieduard/Library/Android/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: /Users/anieduard/cocos2d-x-3.14.1/external/flatbuffers/prebuilt-mk/../../../prebuilt/android/armeabi/flatbuffers.a(flatc.o): previous definition here
/Users/anieduard/cocos2d-x-3.14.1/external/flatbuffers/prebuilt-mk/../../../prebuilt/android/armeabi/flatbuffers.a(flatc.o):flatc.cpp:generators: error: undefined reference to 'flatbuffers::GenerateCppGRPC(flatbuffers::Parser const&, std::string const&, std::string const&)'
/Users/anieduard/cocos2d-x-3.14.1/external/flatbuffers/prebuilt-mk/../../../prebuilt/android/armeabi/flatbuffers.a(flatc.o):flatc.cpp:generators: error: undefined reference to 'flatbuffers::GenerateGoGRPC(flatbuffers::Parser const&, std::string const&, std::string const&)'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi/libMyGame.so] Error 1
make: Leaving directory `/Users/anieduard/Desktop/MyGame/proj.android-studio/app'
Error running command, return code: 2. 

My Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := MyGame_shared

LOCAL_MODULE_FILENAME := libMyGame

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../../Classes/AppDelegate.cpp \
                   ../../../Classes/HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes

#LOCAL_WHOLE_STATIC_LIBRARIES += PluginAdMob
#LOCAL_WHOLE_STATIC_LIBRARIES += sdkbox

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,./prebuilt-mk)

# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

Thanks!

Having the same error as @anieduard after updating to 3.15. Tried to build with NDK r10c, r11c, r14b.

I had the same problem when using prebuilt libraries for 3.15 today on Windows 10 in my test project. Error states exactly what is the problem - both flatc.cpp and flathash.cpp have defined main() function in them and both are compiled and added to the same library flatbuffers.a. Linker does not know which main() of the two it has to refer to from your code and fails with the error. It looks like a bug to me in cocos2d-x, so I removed flatc.cpp file from external/flatbuffers/Android.mk and external/flatbuffers/CMakeLists.txt (I am not sure if editing CMakeLists.txt is really needed) and rebuilt prebuilt library again.

Excerpt from edited external/flatbuffers/Android.mk:

LOCAL_SRC_FILES :=
#flatc.cpp
flathash.cpp \

And I could then successfully compile the prebuilt libraries and use them in my test cocos2d-x project.
I would like to point out that it might be that not flatc.cpp file should be removed from library, but flathash.cpp instead, so if you face issues, try comment out flathash.cpp. If you’d look at sources of 3.14.1, you could see that flathash.cpp is not there, so it is a new file in 3.15.
Anyone who is more familiar with the source could elaborate more whether this is really a bug.

Good luck.

/Users/piotr/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/arm-linux-androideabi/bin/ld
Error:error: /Users/piotr/Documents/pierdoly/cocos2d-x-3.15/external/flatbuffers/prebuilt-mk/../../../prebuilt/android/armeabi-v7a/flatbuffers.a(flathash.o): multiple definition of 'main'
Error:error: linker command failed with exit code 1 (use -v to see invocation)

the same problem…
edit:
@inkus your fix works. App is running, yet sigh… now in 3.15 all labels disappeared.