FirebaseExtended / cocos2dx-cpp-sample

Firebase Cocos2d-x samples
http://firebase.google.com/games
MIT License
53 stars 25 forks source link

_OBJC_CLASS_$_FIREmailPasswordAuthProvider linker error #8

Closed retrobrain closed 7 years ago

retrobrain commented 7 years ago

Operating system: macos Operating system version: 10.12.3 CocoaPods version: 1.2.1 Firebase C++ SDK version: 3.1.2

Podfile contents: platform :ios, '8.0' target 'firebaseTest-mobile' do use_frameworks! pod 'Firebase/Core' pod 'Firebase/AdMob' pod 'Firebase/Auth' pod 'GoogleSignIn' pod 'Firebase/Database' pod 'Firebase/RemoteConfig' pod 'Firebase/Storage' end

I'm trying to add Firebase C++ SDK to my cocos2d app. The app builds and runs successfully but when I add this piece of code: std::string token = UserDefault::getInstance()->getStringForKey("GID"); firebase::auth::Credential credential = firebase::auth::GoogleAuthProvider::GetCredential(token.c_str(), nullptr);

a linker error appears: Undefined symbols for architecture armv7: "_OBJC_CLASS_$_FIREmailPasswordAuthProvider", referenced from: objc-class-ref in firebase_auth(credential_ios_de0c3e1fa34e9a30835a63e195323a0f.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've added the $(inherited) flag to the Framework Search path, Other Linker Flags and Preprocessor Macros. The other suggestion from StackOverflow was to downgrade the pods version to 3.17.0. I tried it and this fixed the linker error but the app crashed in runtime on the same line of code and an exception was thrown '*** +[NSString stringWithUTF8String:]: NULL cString'

I also tried running the quickstart-cpp-master and the cocos2dx-cpp-sample but always got the same linker error.

stewartmiles commented 7 years ago

The stack overflow suggestion is correct you need to downgrade the pods (i.e all Firebase pods) to 3.17.0.

Regarding the exception, do you have the complete stack trace you could share?

On Fri, May 26, 2017 at 9:25 AM, Artem Chystikov notifications@github.com wrote:

Operating system: macos Operating system version: 10.12.3 CocoaPods version: 1.2.1 Firebase C++ SDK version: 3.1.2

Podfile contents: platform :ios, '8.0' target 'firebaseTest-mobile' do use_frameworks! pod 'Firebase/Core' pod 'Firebase/AdMob' pod 'Firebase/Auth' pod 'GoogleSignIn' pod 'Firebase/Database' pod 'Firebase/RemoteConfig' pod 'Firebase/Storage' end

I'm trying to add Firebase C++ SDK to my cocos2d app. The app builds and runs successfully but when I add this piece of code: std::string token = UserDefault::getInstance()->getStringForKey("GID"); firebase::auth::Credential credential = firebase::auth:: GoogleAuthProvider::GetCredential(token.c_str(), nullptr);

a linker error appears: Undefined symbols for architecture armv7: "_OBJCCLASS$_FIREmailPasswordAuthProvider", referenced from: objc-class-ref in firebase_auth(credentialios de0c3e1fa34e9a30835a63e195323a0f.o) ld: symbol(s) not found for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've added the $(inherited) flag to the Framework Search path, Other Linker Flags and Preprocessor Macros. The other suggestion from StackOverflow was to downgrade the pods version to 3.17.0. I tried it and this fixed the linker error but the app crashed in runtime on the same line of code and an exception was thrown '*** +[NSString stringWithUTF8String:]: NULL cString'

I also tried running the quickstart-cpp-master and the cocos2dx-cpp-sample but always got the same linker error.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/firebase/cocos2dx-cpp-sample/issues/8, or mute the thread https://github.com/notifications/unsubscribe-auth/AFw1RHKAANIbapv8a8f9oB1dTVsOZN1Hks5r9vz0gaJpZM4NnzQt .

retrobrain commented 7 years ago

@stewartmiles , yes sure I can.

stewartmiles commented 7 years ago

Ah the crash is due to you passing a null string to GoogleAuthProvider::GetCredential();

You have... firebase::auth::GoogleAuthProvider::GetCredential(token.c_str(), nullptr);

You need to provide a valid access token. See https://firebase.google.com/docs/reference/cpp/class/firebase/auth/google-auth-provider

I'm not sure what you're trying to do but the code snippet you posted looks pretty incomplete for Google Sign-in.

retrobrain commented 7 years ago

I'm sure that I'm not passing an empty string. My test flow is next: sign in with google and save the token on the native side as an UserDefault value -> notify c++ side that sign in was successful and retrieve the token value -> call GetCredential() method passing it the token value saved before.

UPD. This is a dirty but clear example. It still crashes on the GetCredential() line

- (void)signIn:(GIDSignIn *)signIn
didSignInForUser:(GIDGoogleUser *)user
     withError:(NSError *)error {
    if (error == nil) {
        GIDAuthentication *authentication = user.authentication;

        std::string token = authentication.idToken.UTF8String;
        if (token.empty())
            return;
        firebase::auth::Credential credential =
        firebase::auth::GoogleAuthProvider::GetCredential(token.c_str(), nullptr);
    }
}
stewartmiles commented 7 years ago

The second argument to GetCredential is null, it shouldn't be.

`- (void)signIn:(GIDSignIn )signIn didSignInForUser:(GIDGoogleUser )user withError:(NSError )error { if (error == nil) { GIDAuthentication authentication = user.authentication;

    std::string token = authentication.idToken.UTF8String;
    if (token.empty())
        return;
    firebase::auth::Credential credential =
    firebase::auth::GoogleAuthProvider::GetCredential(token.c_str(), **nullptr**);
}

}`

retrobrain commented 7 years ago

I was confused by the official tutorial (Authenticate with Firebase paragraph). Anyway I've should been checked the function signature. Thanks for your help

stewartmiles commented 7 years ago

Well that tutorial looks a bit wrong :/ We'll get that fixed.

stewartmiles commented 7 years ago

We took another look at this today and noticed that we should be handling null string arguments for the GoogleAuthCredential so it is definitely a bug in the SDK rather than the docs. We've fixed this internally and should have a release very soon.

stewartmiles commented 7 years ago

Ok this is now fixed in version 4.0.0 https://firebase.google.com/support/release-notes/cpp-relnotes#4.0.0