[SOLVED] Proj.android build error, undefined reference to ui component (ScrollView)

Hi,

So I made a project with cocos console tool, v3.2.

I have a class (ChooseDiscMenu) that uses ui::ScrollView which is failing on build:

**** Build of configuration Release for project IceSlide ****

python /Users/mikeg/Projects/IceSlide/proj.android/build_native.py -b release all
Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 9 in ./AndroidManifest.xml
Android NDK: WARNING:jni/…/…/cocos2d/cocos/./Android.mk:cocos2dx_static: LOCAL_LDLIBS is always ignored for static libraries
Android NDK: WARNING:jni/…/…/cocos2d/cocos/platform/android/Android.mk:cocos2dxandroid_static: LOCAL_LDLIBS is always ignored for static libraries
make: Entering directory /Users/mikeg/Projects/IceSlide/proj.android' [armeabi] SharedLibrary : libcocos2dcpp.so jni/../../Classes/ChooseDiscMenu.cpp:88: error: undefined reference to 'cocos2d::ui::ScrollView::create()' jni/../../Classes/ChooseDiscMenu.cpp:91: error: undefined reference to 'cocos2d::ui::ScrollView::setBounceEnabled(bool)' jni/../../Classes/ChooseDiscMenu.cpp:94: error: undefined reference to 'cocos2d::ui::ScrollView::setInnerContainerSize(cocos2d::Size const&)' jni/../../Classes/ChooseDiscMenu.cpp:109: error: undefined reference to 'cocos2d::ui::ScrollView::getInnerContainerSize() const' clang++: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1 make: Leaving directory/Users/mikeg/Projects/IceSlide/proj.android’
Traceback (most recent call last):
The Selected NDK toolchain version was 4.8 !
File “/Users/mikeg/Projects/IceSlide/proj.android/build_native.py”, line 159, in
build(opts.ndk_build_param,opts.android_platform,opts.build_mode)
File “/Users/mikeg/Projects/IceSlide/proj.android/build_native.py”, line 146, in build
do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
File “/Users/mikeg/Projects/IceSlide/proj.android/build_native.py”, line 82, in do_build
raise Exception(“Build dynamic library for project [ " + app_android_root + " ] fails!”)
Exception: Build dynamic library for project [ /Users/mikeg/Projects/IceSlide/proj.android ] fails!

**** Build Finished ****

Here is what I have in 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)
# $(call import-add-path,$(LOCAL_PATH)/…/…/cocos2d/cocos/ui)

LOCAL_MODULE := cocos2dcpp_shared

LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_SRC_FILES := hellocpp/main.cpp
…/…/Classes/AppDelegate.cpp
…/…/Classes/Stage.cpp
…/…/Classes/ObstacleSpawner.cpp
…/…/Classes/MainMenu.cpp
…/…/Classes/SplashScreen.cpp
…/…/Classes/BodyParser.cpp
…/…/Classes/ChooseDiscMenu.cpp
…/…/Classes/Magnet.cpp
…/…/Classes/Scoreboard.cpp
…/…/Classes/Settings.cpp
…/…/Classes/TouchableSprite.cpp

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

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
# LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_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

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)
$(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)

What am I missing here?
It’s probably something at the linkage stage, I guess.

Regards,
Mike.

you should add

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_static
$(call import-module,ui)
2 Likes

@owen Thanks a lot!

Now it’s failing with another error:

jni/../../cocos2d/cocos/platform/android/jni/TouchesJni.cpp:79: error: relocation overflow in R_ARM_THM_CALL
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: Leaving directory `/Users/mikeg/Projects/IceSlide/proj.android'
make: *** [obj/local/armeabi/libcocos2dcpp.so] Error 1
The Selected NDK toolchain version was 4.8 !
Traceback (most recent call last):
  File "/Users/mikeg/Projects/IceSlide/proj.android/build_native.py", line 159, in <module>
    build(opts.ndk_build_param,opts.android_platform,opts.build_mode)
  File "/Users/mikeg/Projects/IceSlide/proj.android/build_native.py", line 146, in build
    do_build(cocos_root, ndk_root, app_android_root,ndk_build_param,sdk_root,android_platform,build_mode)
  File "/Users/mikeg/Projects/IceSlide/proj.android/build_native.py", line 82, in do_build
    raise Exception("Build dynamic library for project [ " + app_android_root + " ] fails!")
Exception: Build dynamic library for project [ /Users/mikeg/Projects/IceSlide/proj.android ] fails!

Here is what I have in 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/Stage.cpp \
                   ../../Classes/ObstacleSpawner.cpp \
                   ../../Classes/MainMenu.cpp \
                   ../../Classes/SplashScreen.cpp \
                   ../../Classes/BodyParser.cpp \
                   ../../Classes/ChooseDiscMenu.cpp \
                   ../../Classes/Magnet.cpp \
                   ../../Classes/Scoreboard.cpp \
                   ../../Classes/Settings.cpp \
                   ../../Classes/TouchableSprite.cpp

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

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_ui_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,.)
$(call import-module,audio/android)
$(call import-module,ui)

I am not sure… but see whether you have included ChooseDiscMenu.h in the file where you’re writing the code:
cocos2d::ui::ScrollView::create() and other things used from this class.

@catch_up yes, I did have included ChooseDiscMenu.h in the file, it’s his own implementation ChooseDiscMenu.cpp.

I didn’t understand this…

Anyways, if you’ve included in that file(I am not talking about including ChooseDiscMenu.h to be included ChooseDiscMenu.cpp because that is obviously you would have added). I am talking about adding ChooseDiscMenu.h in the Suppose GameScene.cpp if you’re using functions of ChooseDiscMenu.cpp inside GameScene.cpp.

I think you’ve already got what I was saying in my previous post… Anyways…

Yes, this is probably so.

Now I have this error:

jni/…/…/cocos2d/cocos/platform/android/jni/TouchesJni.cpp:79: error: relocation overflow in R_ARM_THM_CALL

TouchesJni.cpp line 79:

static std::unordered_map<int, cocos2d::EventKeyboard::KeyCode> g_keyCodeMap = {
    { KEYCODE_BACK , cocos2d::EventKeyboard::KeyCode::KEY_ESCAPE},
    { KEYCODE_MENU , cocos2d::EventKeyboard::KeyCode::KEY_MENU},
    { KEYCODE_DPAD_UP  , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_UP },
    { KEYCODE_DPAD_DOWN , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_DOWN },
    { KEYCODE_DPAD_LEFT , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_LEFT },
    { KEYCODE_DPAD_RIGHT , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_RIGHT },
    { KEYCODE_ENTER  , cocos2d::EventKeyboard::KeyCode::KEY_ENTER},
    { KEYCODE_PLAY  , cocos2d::EventKeyboard::KeyCode::KEY_PLAY},
    { KEYCODE_DPAD_CENTER  , cocos2d::EventKeyboard::KeyCode::KEY_DPAD_CENTER},
    
};

By the way, do I have to put something into AppAcitivity.java?
It’s almost empty now:

/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011      Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
 
http://www.cocos2d-x.org

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
package org.cocos2dx.cpp;

import org.cocos2dx.lib.Cocos2dxActivity;

public class AppActivity extends Cocos2dxActivity {
}

No, you don’t have to put anything inside that function…

And for that error have you tried to move some folders inside the ‘cocos’ folder?

I think I won’t be able to help more… I never had an encounter wtih that error.

1 Like

some folders, like what?

I mean can you tell us if you have changed the place of any folder inside the cocos folder inside your project.
I am not much sure whether this is the possible problem… But have you changed location of any folder?

And yeah you’ve just quoted

which was not the suggestion but a question :smiley:

I’ve made no changes there.

In the android.mk
I can see that you’ve not uncommented the line

$(call import-add-path,$(LOCAL_PATH)/…/…/cocos2d/cocos/ui)

Infact you’ve removed it… As @owen has suggested… You should also uncomment that line.

Please check after doing it… :smile:

@catch_up I’ve removed the comment from that line but it still fails with the same error message. :frowning:

I think it has something relevant to instruction sets support: “ARM” vs “Thumb”

The default mode is thumb.

Add this line to your Android.mk:

LOCAL_ARM_MODE := arm

Another option would be in using the .arm suffix.

https://groups.google.com/forum/m/#!topic/android-ndk/R4bsms66RvE

1 Like

@iQD big thanks!

I think we shouldn’t force the mode to arm, since NDK suggest us to use thumb mode.

And if we just use ui::ScrollView, we don’t need to change anything about the build mode.

We do use ui::ScrollView in cpp-tests and we don’t change anything about the mode.

So maybe they are other better solutions here.

Of course this would be just a quick “hack”, but thumb is just the default, because it produces smaller binaries and the performance setback is negligible in most cases. Nevertheless there is no penalty in using arm.

I also don’t have problems with thumb regarding ui::ScrollView, but those errors just always boil down to a compiler-linker combination/incompatibility. The error might just go away, when using the gold linker or using a different ABI. There are also some rare cases with toolchain bugs.

It’s just those errors, that struggle people. Like the -fPIC error with the provided, prebuilt libcurl, which will occure on using NDK r10x.

To iron out those errors without forcing the mode, engine test.builds with different compiler/linker/ABI combinations would be needed.

For the first step, we would need detailed information about the used toolchain from the thread starter.

cocos2d-x v3.2
ndk 10c
eclipse from adt bundle

what else should i specify?

  • The version of the adt bundle
  • The compiler used and its version
  • The linker used and it’s version
  • adt: adt-bundle-mac-x86_64-20140702
  • ant 1.9.4
  • java version “1.6.0_65” Java™ SE Runtime Environment (build
    1.6.0_65-b14-462-11M4609) Java HotSpot™ 64-Bit Server VM (build 20.65-b04-462, mixed mode)
  • Xcode 5.1.1 (5B1008)