[Solved] 3.17 release build error. "warning: relocation refers to discarded section"

[Solved] 3.17 release build error. "warning: relocation refers to discarded section"
0

cocos2dx v3.17
NDK r16b
SDKBOX IAP 2.4.0.1

The debug build succeeded, but the following error is issued in the release build.
Is there a solution?

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:puzzlegame:externalNativeBuildRelease’.
    Build command failed.
    Error while executing process /Applications/android/android-ndk-r16b/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/user/android/puzzlegame/proj.android/app/jni/Android.mk NDK_APPLICATION_MK=/Users/user/android/puzzlegame/proj.android/app/jni/Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-15 NDK_OUT=/Users/user/android/puzzlegame/proj.android/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=/Users/user/android/puzzlegame/proj.android/app/build/intermediates/ndkBuild/release/lib NDK_TOOLCHAIN_VERSION=clang -j8 NDK_DEBUG=0 /Users/user/android/puzzlegame/proj.android/app/build/intermediates/ndkBuild/release/obj/local/armeabi-v7a/libcocos2dcpp.so}
    [armeabi-v7a] StaticLibrary : libcocostudio.a
    [armeabi-v7a] StaticLibrary : libcocosbuilder.a
    [armeabi-v7a] StaticLibrary : libcocos3d.a
    [armeabi-v7a] StaticLibrary : libspine.a
    [armeabi-v7a] StaticLibrary : libui.a
    [armeabi-v7a] StaticLibrary : libcocosdenshion.a
    [armeabi-v7a] StaticLibrary : flatbuffers.a
    [armeabi-v7a] StaticLibrary : libaudioengine.a
    [armeabi-v7a] StaticLibrary : libnetwork.a
    [armeabi-v7a] StaticLibrary : libvorbisidec.a
    [armeabi-v7a] StaticLibrary : libpvmp3dec.a
    [armeabi-v7a] StaticLibrary : librecast.a
    [armeabi-v7a] StaticLibrary : libcocos2dandroid.a
    [armeabi-v7a] StaticLibrary : libcpufeatures.a
    [armeabi-v7a] StaticLibrary : libextension.a
    [armeabi-v7a] StaticLibrary : libcocos2dxinternal.a
    [armeabi-v7a] SharedLibrary : libcocos2dcpp.so
    /Users/user/android/puzzlegame/proj.android/app/jni/./sdkbox/libs_c++_static/armeabi-v7a/libsdkbox.a(Utils.o):function std::__ndk1::basic_stringstream<char, std::__ndk1::char_traits, std::__ndk1::allocator >::~basic_stringstream(): warning: relocation refers to discarded section
    /Applications/android/android-ndk-r16b/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/…/…/…/…/arm-linux-androideabi/bin/ld: error: treating warnings as errors
    clang++: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [/Users/user/android/puzzlegame/proj.android/app/build/intermediates/ndkBuild/release/obj/local/armeabi-v7a/libcocos2dcpp.so] Error 1

I tested with android-ndk-r14b, would you use r14b instead of r16.

I 'll test the r16.

cocos2dx v3.17 is written as ndk r16.
Does it work even on r14?

yes, r14 also works.

I tried it with ndk r14b, but I got the same error :cold_sweat:

What commands are you running?

This command.

cocos compile -p android --android-studio -m release

I added SDKBO IAP to the v3.17 new project, but there are no errors in r16 and r14.
I do not understand :sob:
I am investigating the problem…

Try adding LOCAL_DISABLE_FATAL_LINKER_WARNINGS=true to .mk file.
Reference: https://stackoverflow.com/questions/35950410/ndk-11-linker-is-treating-warnings-as-errors/35950411#35950411

1 Like

Thanks.
After adding it to Android.mk, the build succeeded.
But crash with sdkbox.init().

SDKBox.init(this);

05-30 11:30:52.109 18082-18082/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: jp.co.puzzlegame, PID: 18082
java.lang.UnsatisfiedLinkError: Native method not found: com.c.b.a.a:(Ljava/lang/Object;Ljava/lang/ClassLoader;)V
at com.c.b.a.a(Native Method)
at com.c.b.a.a(SDKBox.java:71)
at org.cocos2dx.lib.Cocos2dxActivity.onCreate(Cocos2dxActivity.java:129)
at org.cocos2dx.cpp.AppActivity.onCreate(AppActivity.java:83)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)

Debug build is working properly.

cocos compile -p android --android-studio

Umm…

ok, I 'll check with RELEASE mode.

UPDATE:

~/test/cpp317 [master] $ echo $NDK_ROOT
/Users/admin/Documents/sdk/android/android-ndk-r16b
~/test/cpp317 [master] $ sdkbox info
  _______ ______  _     _ ______   _____  _     _
  |______ |     \ |____/  |_____] |     |  \___/
  ______| |_____/ |    \_ |_____] |_____| _/   \_
 Copyright (c) 2016-2018 SDKBOX Inc. v1.0.1.35
 installed packages:
     v2.4.0.1 iap

~/test/cpp317 [master] $ cocos run -p android -m release

works for me.

would you plz check your test project, must create from cocos2d-x-3.17 tag .
Thanks,

Thanks.
3.17 new project + ndk r16b is no error.
But in my project I get an error.
It can not be reproduced with a new project.
Are there any hints?

It was reproduced.
I get an error with the this code.

std :: stringstream aaa;

In the case of “prebuilt”, get an error even if you do not write the above code.

Can you reproduce it?
Is this a problem for me?

whats prebuilt mean? plz show me the steps, thanks.

Create a static library with this command.

cocos gen-libs -e /Applications/Cocos/Cocos2d-x/cocos2d-x-3.17 -p ios -p android --ap android-26 -m release

But in 3.17 prebuilt-mk is not created and the procedure is tough.

It may be that “std :: stringstream” is somewhere in cocos2dx.

Can you reproduce it?

Case 1

  • Error in release build when adding the this code.

std :: stringstream aaa;

Case 2

  • Error in release build with cocos2dx prebuilt.

I think Case 1 can be reproduced quickly.
Do you need further details on Case 2?

?

I added bellow codes to cocos2d.cpp file:

#include <sstream>

std :: stringstream aaa;

BUILD SUCCESSFUL in 5s
59 actionable tasks: 6 executed, 53 up-to-date
Move apk to /Users/admin/repos/cocos2d-x/tests/cpp-empty-test/bin/release/android
Build succeed.
~/repos/cocos2d-x [cocos2d-x-3.17] $ cocos gen-libs -e `pwd` -p android --ap android-26 -m release

Case 1 and Case 2 separately, no relation.
Either way you get an error.

Case 1

  1. Add SDKBox IAP

  2. Add Code.
    AppDelegate.cpp

     bool AppDelegate::applicationDidFinishLaunching() {
         std::stringstream aaa;
         ...
    
  3. building.

     cocos compile -p android --android-studio -m release
    

Case 2

  1. Add SDKBox IAP

  2. Generate cocos2dx prebuilt, And setting using prebuilt.

     cocos gen-libs -e /Applications/Cocos/Cocos2d-x/cocos2d-x-3.17 -p ios -p android --ap android-26 -m release
    
     Update android.mk, build.gradle.
     Set cocos2dx each prebuilt-mk/android.mk.
     Etc Settings.....
    
  3. building.

     cocos compile -p android --android-studio -m release

BUILD SUCCESSFUL in 11s
80 actionable tasks: 6 executed, 74 up-to-date
Move apk to /Users/admin/test/cpp317/bin/debug/android
Build succeed.
~/test/cpp317 [master] $ cocos compile -p android
~/test/cpp317 [master] $ echo $NDK_ROOT
/Users/admin/Documents/sdk/android/android-ndk-r16b

sorry, I sent it on the way.
We are updating the contents.

Is the result a release build?

ok, i reproduce it.