firebase / firebase-cpp-sdk

Firebase C++ SDK
http://firebase.google.com
Apache License 2.0
276 stars 114 forks source link

Build error on Android: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)' #7

Closed AGulev closed 5 years ago

AGulev commented 5 years ago

When I'm trying to build Firebase SDK 5.7.0 I'm receiving next error (with 5.6.1 everything works fine).

armeabi-v7a/gnustl

Android:GCC 4.8 Android: NDK 10e, Build Tools 23.0.2, Api Level 14

Log:

/opt/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_string.h:878: error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
collect2: error: ld returned 1 exit status
a-maurice commented 5 years ago

Hi @AGulev,

Is there a particular library (like Analytics, Auth, etc) in the C++ SDK you are seeing this error in?

AGulev commented 5 years ago

Hi @a-maurice , Sorry, I forgot to mention, it's Analytics only.

jonsimantov commented 5 years ago

Hi,

I believe the issue you are seeing is due to your old version of the NDK. Are you using the binary version of the Firebase C++ SDK available at http://firebase.google.com/docs/cpp/setup, or are you building the SDK yourself from source via this GitHub project?

We build our binary Firebase C++ SDK using android-ndk-r16b, which still supports gnustl. Could you try downloading that NDK version (or later) from the old NDK releases page and building your app using that? That should ensure maximum compatibility with the C++ STL functions used by the C++ SDK.

AGulev commented 5 years ago

Hi @jonsimantov , I'm using the binary version of the Firebase c++ SDK armeabi-v7a/gnustl.

Unfortunately, I can't change the NDK version, because it's a part of the build process of the whole game engine.

What should I do in this case? The only solution is to continue to use 5.6.1 ? Could you add more information into release notes for 5.7.0 about the transition to the newer NDK, I think it will be useful for people with the same problem.

jonsimantov commented 5 years ago

We've been building against r16b for a long time, but it's possible that there's some code that changed in 5.7.0 that is causing the new incompatibility.

I tried building our Firebase C++ Analytics Quickstart using NDK r10e and Firebase C++ SDK 5.7.0 and I didn't get that same linker error. (I also didn't get the error using our latest C++ SDK 6.0.0.) So it's possible our C++ quickstart is not exercising some functionality that's being used by your app, which has the incompatibility.

Could you try the C++ version SDK 6.0.0? And if it continues to have a linker error, could you share your code that uses Firebase Analytics, or at least provide a full list of the Analytics functions you are calling? I'll try to reproduce the issue and see if we can get it back to being compatible (though not supported) with earlier NDKs.

Thanks!

AGulev commented 5 years ago

I have the same error with C++ SDK 6.0.0.

arm-linux-androideabi-g++ --sysroot=/opt/platformsdk/android/android-ndk-r10e/platforms/android-14/arch-arm build/main_tmp4e23f663-c49e-43b6-928c-92c42538d26b.o  -o build/libdmengine.so -Wl,-soname=libdmengine.so -DDLIB_LOG_DOMAIN="ENGINE_MAIN" -DDM_PLATFORM_ANDROID -DLUA_BYTECODE_ENABLE_32 -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__   -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -landroid -fpic -z text -L/tmp/job6235077936769032454/build -L/tmp/job6235077936769032454/upload/firebase/lib/armv7-android -L/tmp/job6235077936769032454/upload/firebase/lib/android  -L/dynamo_home//lib/armv7-android -L/dynamo_home//ext/lib/armv7-android -L/opt/platformsdk/android/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a  -Wl,-Bstatic -Wl,--start-group  -l017c27a3-1ff0-4189-859e-e326d651f351 -lfirebase_app -lfirebase_analytics  -lengine -lengine_service -laxtls -lwebviewext -lprofilerext -lfacebookext -liapext -lpushext -liacext -lrecord_null -lgameobject -lddf -lresource -lgamesys -lgraphics -lphysics -lBulletDynamics -lBulletCollision -lLinearMath -lBox2D -lrender -lscript -lluajit-5.1 -lextension -lhid -linput -lparticle -lrig -ldlib -ldmglfw -lgui -ltracking -lcrashext -lsound -lopenal_soft -ltremolo -lliveupdate -lunwind -lcares  -Wl,--end-group -Wl,-Bdynamic  -lEGL -lGLESv1_CM -lGLESv2 -lOpenSLES -lm -llog -lc  -lgnustl_static -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared
/opt/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_string.h:878: error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
collect2: error: ld returned 1 exit status

2019-05-13 12:37:19.487  WARN 1 --- [tp1439337960-15] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [com.defold.extender.ExtenderException: java.io.IOException: /opt/android-ndk-r16b/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_string.h:878: error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
collect2: error: ld returned 1 exit status

could you share your code that uses Firebase Analytics, or at least provide a full list of the Analytics functions you are calling? Yes, np : https://github.com/defold/extension-firebase-analytics/blob/sdk-update/firebase/src/firebase.cpp

jonsimantov commented 5 years ago

What happens if you remove the call to AppOptions::LoadFromJsonConfig and instead just let it load from your app's google-services.json normally? It's possible that the C++ JSON parsing we're doing is not compatible with the old NDK's gnustl.

(Note that if you don't use gradle with the google services plugin to build, you'll need to convert your app's google-services.json to Android resources manually by running generate_xml_from_google_services_json.py, included in the C++ SDK.)

AGulev commented 5 years ago

Yes, you are right. Without AppOptions::LoadFromJsonConfig it works fine. Thank you.

jonsimantov commented 5 years ago

Glad to hear it! We use the Flatbuffers library to manually parse the JSON data in LoadOptionsFromJson, and it seems that it's not playing nice with that version of the C++ STL in the old NDK you have, so as long as you don't call that function it should be fine.

It should be possible to patch Flatbuffers to fix the issue, so I'll leave this open until we are able to publish a proper fix, or at least remove LoadOptionsFromJson from iOS/Android (it really should only be used on desktop).

ryanmeier commented 5 years ago

Closing this issue, as it should now be resolved with the 6.1.0 Release.