Can't get GoogleMaps SDK to work on Xcode Test Target (works on App Target)

时光怂恿深爱的人放手 提交于 2019-12-23 17:33:29

问题


The Setup

I have successfully integrated the GoogleMaps SDK into my Swift 2 project using CocoaPods.

My setup is pretty much that suggested by the Ray Wenderlich tutorial on the subject. The only difference I can find is, I have to add this line to AppDelegate:

import UIKit
import GoogleMaps // <- THIS LINE

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
    ...

...in order to use the framework's classes. The tutorial suggests importing:

#import <GoogleMaps/GoogleMaps.h>

...to the bridging header instead.

The app works without problems.


The Problem:

When I tried to run the test target auto-generated by Xcode, I get the error:

No such module 'GoogleMaps'

...pointing at the to the swift import statement in AppDelegate above.

So, I decide to switch to the way it is in the tutorial instead: I comment out the line import GoogleMaps in AppDelegate.swift and add an Objective-C-style import statement to the bridging header.

However, I can not get it right:

  1. If I use: #import <GoogleMaps/GoogleMaps.h> or #import "GoogleMaps/GoogleMaps.h", it gives me:

    Use of unresolved identifier 'GMServices'

    at AppDelegate.swift when building the app target.

  2. If I use: #import "GoogleMaps.h", it gives me:

    'GoogleMaps.h': file not found

    at the bridging header.

I have tried the solution in this answer, but the results are (puzzlingly) the same...?


Next, I checked the value of Build Settings / Search Paths / Framework Search Paths for both targets (app and tests). The app target had the entry:

"${PODS_ROOT}/GoogleMaps/Frameworks"

...which the test target lacked, so I added it, and reverted to the swift-style import (the only one that works at least when building the app target), but I still get:

import GoogleMaps   <! No such module 'GoogleMaps'

How can I run tests for my app??


回答1:


So, it turns out all I had to do is fix the Podfile (and run pod install), as explained in this answer.

My old pod file:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'

def import_pods
    pod 'GoogleMaps'
end

workspace 'MyWorkspace'
xcodeproj 'MyApp/MyApp.xcodeproj'

target : MyApp do
    xcodeproj 'MyApp MyApp.xcodeproj'
    pod 'GoogleMaps'
end

My current pod file:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'

def import_pods
    pod 'GoogleMaps'
end

workspace 'MyWorkspace'
xcodeproj 'MyApp/MyApp.xcodeproj'

target 'MyApp', :exclusive => true do
    xcodeproj 'MyApp/MyApp.xcodeproj'
    import_pods
end

target 'MyAppTests', :exclusive => true do
    xcodeproj 'MyApp/MyApp.xcodeproj'
    import_pods
end


来源:https://stackoverflow.com/questions/35451837/cant-get-googlemaps-sdk-to-work-on-xcode-test-target-works-on-app-target

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!