0

I have an app in which I have implemented facebook login. I copied the sources from the facebook sdk directly into my project. Now I need to add google login. This time I have added GTMOAuth2 as a static library. (I also have the source for this too but I added as a static library for no specific reason). The problem is they are both using SBJson and I get duplicate symbols. It appears that the SBJson in the facebook sdk is newer than the one in the GTMOAuth2 library. I'm a noob I never had duplicate symbols before, what should I do? Are there solutions to this specific problem or to resolving duplicate symbols in general? Do I just delete stuff that appears twice until it works, are there some linker settings? Thanks.

Update - What I tried:

Added both projects as a static library.

  • I tried deleting the SBJSON.h/m files from GTMOAuth2, result: json parse error after google login:

  • I tried deleting the SBJSON.h/m files from the Facebook iOS SDK; result: json parse error after facebook login.

Can I make these two versions of SBJSON magically coexist in my app without duplicate symbols? Do I have to modify one library to work with the ONE SBJSON I decite to use?

gyozo kudor
  • 6,284
  • 10
  • 53
  • 80

2 Answers2

3

I'm using SBJSON from the facebook sdk. I just removed SBJSON from the GTMOAuth2 library to avoid duplicate symbol as suggested by Ishu. The next problem is that GTMOAuth2 tries to use SBJSONParser first and that class doesn't have objectWithString:error: method, only SBJSON has the method. I modified the code to use SBJSON class, and don't even try to use SBJSONParser because it doesn't work. In the original version SBJsonParser was checked first and then SBJSON.



- (NSDictionary *)dictionaryWithJSONData:(NSData *)data {
    ...
    // try SBJsonParser or SBJSON
    Class jsonParseClass = NSClassFromString(@"SBJSON");
    /*
    if (!jsonParseClass) {
      jsonParseClass = NSClassFromString(@"SBJsonParser");
    }
    */
    if (jsonParseClass) {
      GTMOAuth2ParserClass *parser = [[[jsonParseClass alloc] init] autorelease];
      NSString *jsonStr = [[[NSString alloc] initWithData:data
                                                 encoding:NSUTF8StringEncoding] autorelease];
      if (jsonStr) {
        obj = [parser objectWithString:jsonStr error:&error];
#if DEBUG
        if (error) {
          NSLog(@"%@ error %@ parsing %@", NSStringFromClass(jsonParseClass),
                error, jsonStr);
        }
#endif
        return obj;
      }
    }
  ...
}

UPDATE Here I asked the same question in the GTM-OAuth2 discussion group. This happened after I answered the question, but I forgot to update my answer here. In summary this is what I did:

  • Use both Facebook SDK and GTMOAuth2 as static libraries (probably this is not necessary)
  • Get latest version of SBJSON from here
  • Replace the SBJSON in Facebook SDK with this one
  • Delete the SBJSON sources from GTM-OAuth2 (or remove them from the build phase)

This leaves you with the most up to date SBJSON library included in the Facebook SDK. Both Facebook SDK and GTM-OAuth2 will use that one. It should work.

gyozo kudor
  • 6,284
  • 10
  • 53
  • 80
1

yes delete the SBJSON of GTMOAuth2 library (since it is older version).

Ishu
  • 12,797
  • 5
  • 35
  • 51
  • Well ok, but I'm not entirely sure which one is the newest. – gyozo kudor Jul 08 '11 at 10:08
  • Ok not a problem delete any one you want. your work also can be done with old one. – Ishu Jul 08 '11 at 10:26
  • Unfortunately it doesn't seem to work. It gives me an exception `NSInvalidArgumentException, reason: -[SBJsonParser objectWithString:error:]: unrecognized selector sent to instance 0x45bb1c0` I have no idea what exactly is wrong but it is something related to the json parser, if nothing else works I may modify the oauth library to make it work with the json parser from the facebook sdk – gyozo kudor Jul 08 '11 at 12:35
  • @gyozokudor I believe it might be because the SBJsonParser doesn't have the objectWithString method. Ensure that you're building the correct source file that contains this method. I recall not being able to see that method when I looked at the facebook SBJson... – Tony Jul 31 '12 at 00:46