Trouble compiling on Android

Trouble compiling on Android
0.0 0

#1

I’m starting to create my own projects on Android. I’m having a bit of trouble compiling my project.

Cocos2d-x 3.14.1
using the pre-built libraries.

Here is my error:

Android NDK: /Users/slackmoehrle/Projects/cocos2d-x/cocos/audio/android/prebuilt-mk/Android.mk: Cannot find module with tag 'android-specific/tremolo/prebuilt-mk' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
/Users/slackmoehrle/Projects/cocos2d-x/cocos/audio/android/prebuilt-mk/Android.mk:36: *** Android NDK: Aborting.    .  Stop.
Error running command, return code: 2.

My Android.mk is:

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/CornSprite.cpp \
                   ../../Classes/GameObject.cpp \
                   ../../Classes/GameScene.cpp \
                   ../../Classes/HUDAboutBackgroundSprite.cpp \
                   ../../Classes/HUDForAbout.cpp \
                   ../../Classes/HUDForAchievement.cpp \
                   ../../Classes/HUDForIAP.cpp \
                   ../../Classes/MainScene.cpp \
                   ../../Classes/PurpleKernel.cpp \
                   ../../Classes/SQLManager.cpp \
                   ../../../libraries/sqlite/sqlite3.cpp

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

# _COCOS_HEADER_ANDROID_BEGIN
# _COCOS_HEADER_ANDROID_END

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
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

#LOCAL_STATIC_LIBRARIES := cocos2dx_static

# _COCOS_LIB_ANDROID_BEGIN
# _COCOS_LIB_ANDROID_END

include $(BUILD_SHARED_LIBRARY)

$(call import-module,./prebuilt-mk)
$(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)
# _COCOS_LIB_IMPORT_ANDROID_BEGIN
# _COCOS_LIB_IMPORT_ANDROID_END

My bash_profile

# Cocos2d-x console
export COCOS_CONSOLE_ROOT=/Users/slackmoehrle/Projects/cocos2d-x/tools/cocos2d-console/bin
export PATH=$COCOS_CONSOLE_ROOT:$PATH

# Add environment variables for Android Cocos2d-x development
export NDK_ROOT=/usr/local/Cellar/android-ndk/r13b
export PATH=$NDK_ROOT:$PATH
export NDK_MODULE_PATH=/Users/slackmoehrle/Projects/cocos2d-x/prebuilt/android/armeabi
export PATH=$NDK_MODULE_PATH:$PATH
export ANDROID_HOME=/usr/local/opt/android-sdk
export ANDROID_SDK_ROOT=/usr/local/Cellar/android-sdk/24.4.1_1
export PATH=$ANDROID_SDK_ROOT:$PATH
export PATH=$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools:$PATH
export ANT_ROOT=/Users/slackmoehrle/Applications/ant/bin
export PATH=$ANT_ROOT:$PATH
export COCOS_X_ROOT=/Users/slackmoehrle/Projects/cocos2d-x
export PATH=$COCOS_X_ROOT:$PATH

What mistake am I making?


Building multiple Android apps from the same proj.android directory?
#2

ndk_module_path should not be in your bash file, it should be inside proj.android/build-cfg.json

like this

"ndk_module_path" :[
    "../cocos2d",
    "../cocos2d/cocos",
    "../cocos2d/external"
],

#3

Thanks. Mine looks like this:

{
    "ndk_module_path" :[
        "${COCOS_X_ROOT}",
        "${COCOS_X_ROOT}/cocos",
        "${COCOS_X_ROOT}/external"
    ],
    "copy_resources": [
        {
            "from": "../Resources",
            "to": ""
        }
    ]
}

but still getting the same error


#4

try once after removing NDK_MODULE_PATH from bash_profile


#5

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


#6

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.


#7

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.


#8

@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.


#9

@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?


#10

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


#11

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


#12

I will test this today.


#13

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?


#14

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)

#15

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.


#16

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


#17

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!


#18

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


#19

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?


#20

@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!