Google Cloud Endpoints链接iOS客户端问题 [英] Google Cloud Endpoints linking iOS client issues

查看:117
本文介绍了Google Cloud Endpoints链接iOS客户端问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题来自于我没有完全理解iOS中的静态库,而谷歌的文档似乎有点稀疏。

我正尝试将Google Cloud Endpoints用于我的移动后端。

我为我的客户端库生成.m和.h文件。然后我创建了一个新项目(OwnItApi),将libGTLTouchStaticLib.a静态库从GTL.proj拖到这个新项目中。然后我将生成的文件.m和.h文件添加到此项目中。我将所有.m文件添加到编译源中,然后添加头文件复制文件。在Build Settings中,我将-ObjC -all_load添加到Other Linker Flags项目。



更新:我忘记提及我也将GTL.proj中的头文件复制到OwnItAPI项目中。这些包括文件GTLBase64.h,GTLBatchQuery.h,GTLBatchResult,h等。我认为我必须这样做,因为没有它们的构建失败。



没有标题,我得到:错误'GTLObject.h'文件未找到。然后我把这个项目生成的静态库添加到我的主项目中,其目标是一个iPhone应用程序。为了测试API是否工作,我将它添加到了App Delegate中。

pre $ #importOwnItApi / GTLServiceOwnit.h
#importOwnItApi / GTLQueryOwnit.h
#importOwnItApi / GTLOwnitApiBrands.h

这是在应用程序中:didFinishLaunchingWithOptions:function

  static GTLServiceOwnit * service = nil; 
if(!service){
service = [[GTLServiceOwnit alloc] init];
service.retryEnabled = YES;
[GTMHTTPFetcher setLoggingEnabled:YES];
}

GTLQueryOwnit * query = [GTLQueryOwnit queryForBrandsListWithUserID:@venkat];
[service executeQuery:query completionHandler:^(GTLServiceTicket * ticket,GTLOwnitApiBrands * object,NSError * error){
NSArray * items = [object brands] ;;
NSLog(@%@,items);
}];

当我编译时,我得到如下重复的错误:

 重复符号_OBJC_METACLASS _ $ _ GTLOwnitApiBrand in:
/ Users / vrao / Library / Developer / Xcode / DerivedData / Own_It!-ertvnctptaddricdrjyrmgemzgsh / Build / Products / Release-iphoneos / libOwnItApi.a(GTLOwnit_Sources.o)

17个看起来就像那样的错误。然后最后是

  clang:error:linker命令失败,退出代码1(使用-v查看调用)

更新:在GTL项目中,libGTLTouchStaticLib.a在构建之后呈红色,右键单击它查找器中显示灰显。要找到.a文件,我使用Show in Finder查找GTL.framework,然后返回一个文件夹来查找libGTLTouchStaticLib.a。

解决方案

我相信你看到了你看到的问题,因为你还包括 GTLOwnit_Sources。 m 文件。您可以从您包含的文件列表中省略。


This problem arises from the fact I don't completely understand static libraries in iOS and the docs from google seem to be a little sparse.

I am trying to use Google Cloud Endpoints for my mobile backend.

I generate the .m and .h files for my client library. Then I created a new project(OwnItApi), dragged the libGTLTouchStaticLib.a static library from GTL.proj to this new project. Then I add the generated files .m and .h files to this project. I add all the .m files to the Compile Sources and then I the header files Copy Files. In the Build Settings I add "-ObjC -all_load" to the Other Linker Flags item.

Update: I forgot to mention that I also copied the headers from the GTL.proj to OwnItAPI project. These include files GTLBase64.h, GTLBatchQuery.h, GTLBatchResult,h, etc. I think I had to do this because the build was failing without them.

Without the headers, I get: the error "'GTLObject.h'file not found." on the import statement.

Then I take the static library generated from this project and add it to my main project whose target is an iphone app. To test if the API is working, I added this to App Delegate

#import "OwnItApi/GTLServiceOwnit.h"
#import "OwnItApi/GTLQueryOwnit.h"
#import "OwnItApi/GTLOwnitApiBrands.h"

This is inside the application:didFinishLaunchingWithOptions: function

static GTLServiceOwnit *service = nil;
if (!service) {
    service = [[GTLServiceOwnit alloc] init];
    service.retryEnabled = YES;
    [GTMHTTPFetcher setLoggingEnabled:YES];
}

GTLQueryOwnit *query = [GTLQueryOwnit queryForBrandsListWithUserID:@"venkat"];
[service executeQuery:query completionHandler:^(GTLServiceTicket *ticket,    GTLOwnitApiBrands *object, NSError *error) {
    NSArray *items = [object brands];;
    NSLog(@"%@", items);
}];

When I compile I get duplicate errors like this:

duplicate symbol _OBJC_METACLASS_$_GTLOwnitApiBrand in:
/Users/vrao/Library/Developer/Xcode/DerivedData/Own_It!-ertvnctptaddricdrjyrmgemzgsh/Build/Products/Release-iphoneos/libOwnItApi.a(GTLOwnit_Sources.o)

17 errors that look just like that. and then finally

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Update: In GTL project, libGTLTouchStaticLib.a is red after I build it and when I right click it the "Show in Finder" is greyed out. To find the .a file I use "Show in Finder" for "GTL.framework" and then go back a folder to find libGTLTouchStaticLib.a.

解决方案

I believe you're seeing the issue you see because you're also including the GTLOwnit_Sources.m file. You can omit this from the list of files you include.

这篇关于Google Cloud Endpoints链接iOS客户端问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆