Ranjit
Ranjit

Reputation: 4646

Module 'GoogleMobileAds' not found in iOS

I updated Google AdMob SDK to 7.1.0 using Pods.

So in my appDelegate.m, I am trying to add this line

@import GoogleMobileAds;

But I get error saying Module 'GoogleMobileAds' not found.

This issue is also present in Interstial Ad example by google on gitHub.

Regards Ranjit

Upvotes: 38

Views: 54627

Answers (20)

Jabson
Jabson

Reputation: 1703

I deleted pod and install again... SOLVED my problem

rm -Rf Pods; pod install

in my project dir.

Upvotes: 5

Abdelrahman Ellithy
Abdelrahman Ellithy

Reputation: 224

This sometimes happen when trying not not to use GoogleMobileAds, if this is the case (as me when viewed this): 1- Click the project name. 2- Build settings. 3- Linked Frameworks. 4- Select GoogleMobileAds then the (-) button at the button.

This solved my problem when removing ads from an app template.

Upvotes: 0

Scott Pilgrim
Scott Pilgrim

Reputation: 1

I leave a script that generates inject static frameworks

pod --version 1.3.1
Version 9.1 (9B55)

Podfile [Target]

target 'generic' do
    #Google
    pod 'GoogleAds-IMA-iOS-SDK', '~> 3.6.1'
    pod 'Google-Mobile-Ads-SDK', '~> 7.25.0'

    #pod Module 'GoogleMobileAds' not found 
    pod '#LIB_ERROR#'
    sd
end

Podfile [Fuction]

def inject_frameworks(installer, targetName, listPaths)
    def print_info(text)
        puts "\e[33m[!] #{text}\e[0m"
    end

    installer.pods_project.targets.each do |target|
        if target.name == targetName
            print_info "Inject frameworks in #{target.name}"
            config = target.build_configurations.first
            if config
                xcconfig_path = config.base_configuration_reference.real_path
                build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]

                frameworks_paths = Array.new
                if build_settings['FRAMEWORK_SEARCH_PATHS']
                    frameworks_paths.concat(build_settings['FRAMEWORK_SEARCH_PATHS'].delete!("\n").split(/ /))
                end 

                listPaths.each do |frameworks_path|
                    print_info "[#{target.name}] Add search path frameworks #{File.dirname frameworks_path}"
                    frameworks_paths.push(File.dirname frameworks_path)
                end

                build_settings['FRAMEWORK_SEARCH_PATHS'] = frameworks_paths.join(" ")
                File.open(xcconfig_path, "w") { |file| file << "" }
                build_settings.each do |key,value|
                  File.open(xcconfig_path, "a") {|file| file << "#{key} = #{value.strip}\n"}
                end

                listPaths.each do |frameworks_path|
                    print_info "[#{target.name}] Add frameworks #{File.basename frameworks_path}"
                    new_file_framework = config.project.frameworks_group.new_file(frameworks_path)
                    target.frameworks_build_phase.add_file_reference(new_file_framework, true)
                end
            end
        end
    end
end

Podfile [Run Fuction]

post_install do |installer|
    inject_frameworks(installer, "#LIB_ERROR#", [
        '$(PROJECT_DIR)/Google-Mobile-Ads-SDK/Frameworks/frameworks/GoogleMobileAds.framework',
        '$(PROJECT_DIR)/GoogleAds-IMA-iOS-SDK/GoogleInteractiveMediaAds/GoogleInteractiveMediaAds.framework'
    ])
end

Upvotes: 0

jason z
jason z

Reputation: 1377

I ran into this problem when updating my pods and using Firebase. Unfortunately, none of the answers here helped, so I figured I would post what did work for me.

I found a great thread that helped me here. Basically doing the following worked:

  • Delete my pods - rm -rf Pods
  • Reinstall my pods - pod install --repo-update

Hope this helps someone because this troubled me for a while.

Upvotes: 20

Roman86
Roman86

Reputation: 2319

I was stuck with this problem for few hours, but graceful solution is finally found. My method doesn't use "manual files linking", only pure podfile usage.

I faced this problem when I have updated my pods ('pod install' or 'pod update') after adding another target to the project.

My solution is:

Go to your podfile and make sure you have defined "target ..." block for each target of your project (voila! seems like not documented, at least I didn't find it). For example you have 2 targets: "theApp" and "theApp Lite". In this case your pod file must look like this:

target 'theApp' do
# ...your pods and options here
end

target 'theApp Lite' do
# ...your pods and options here
end

Then do "pod install" or "pod update" to update your libraries.

Then go to each target's General settings and make sure you have proper (corresponding to you target) "libPods...a" (or "libPods...framework", in case you use "use_frameworks!" podfile option) file linked under "Linked Frameworks and Libraries" section. Remove garbage/wrong/confused links if any. Add manually if missing (must appear under "Workspace" group/dir when you hit "+").

Under "Build Phases" you should observe "[CP]"-prefixed items for each target.

After this I had no problems with building.

Upvotes: 2

Mustapha Madani
Mustapha Madani

Reputation: 1

I got the same problem. Here is what I did. Hope it helps someone.

  1. Delete GoogleMobileAds.framework from your project (or store it on another folder).
  2. Go to Build Phases, Link Binary with Libraries. Click the + sign for the Link Binary with Libraries section and click Add Other.... Navigate to where you've stored GoogleMobileAds.framework > Versions > A > GoogleMobileAds and open it.

That perfectly fixed the issue for me.

Upvotes: 0

Bram
Bram

Reputation: 8283

The actual issue here is that in the build settings of your app, you are missing the setting:

Framework Search Paths

Either edit your project.pbxproj so that BuildSettings includes something like:

FRAMEWORK_SEARCH_PATHS = "/Users/bram/src/GoogleMobileAdsSdkiOS-7.16.0/";

Or use Xcode's UI to change the build settings like this:

setting in Xcode UI

Upvotes: 3

Robert TuanVu
Robert TuanVu

Reputation: 843

I got the same problem. here is what I did. It worked for me (Hope it helps someone).

  1. copy GoogleMobileAds.framework to somewhere and remove it from pod if you have it.
  2. Add this framework to your project manually( select "copy items if needed"). Check build phases to make sure you have it in "link binary ..." section.
  3. Clear and rebuild it again => success.

Upvotes: 1

Dasoga
Dasoga

Reputation: 5695

Here is the answer:

Import this into your .m file:

#import <GoogleMobileAds/GADInterstitial.h>
#import <GoogleMobileAds/GADBannerView.h>

Upvotes: 8

Pavel Kataykin
Pavel Kataykin

Reputation: 1557

I just add "use_frameworks!" in the podfile, update pod and it works. This problem appeared when I updated my OS to El Captain (10.11.15) and XCode to 8 version. My podfile now:

    target 'My Target' do
       use_frameworks!
       pod 'MagicalRecord'
       pod 'AFNetworking'
       pod 'Firebase'
       pod 'Firebase/Core'
       pod 'Firebase/AdMob'
    end

Upvotes: 0

Bluesky
Bluesky

Reputation: 1

Do not unzip lib files under windows, it can not handle symbolic links correctly.

Upvotes: 0

Chaudhry Talha
Chaudhry Talha

Reputation: 7898

Here is the solution that worked for me:

Don't Do this
don't do this
Instead of this drag the GoogleMobileAds.framework to your project and add all the other frameworks mentioned here and while drag and drop check copy items if needed.

enter image description here

Upvotes: 4

Pierce
Pierce

Reputation: 3158

If anyone is still experiencing this same problem, I was just able to find a solution. I spent hours attempting everything that was recommended so far and NOTHING worked, I still don't know what I was doing wrong, but here was a little hack that worked for me: Whatever framework I kept downloading from Google (I tried the manual and Cocoa Pods methods) would not work, but when I just downloaded their little tester xCode project (BannerExample.xcodeproj I believe), I copied the framework that was bundled with that test project, pasted it in my target project file and then added the framework and linked it. After doing this I was able to import the framework just fine and adMob works great. I can't for the life of me figure out what the difference would be, but this did work. I hope this solution might help anyone else dealing with the same problem. I believe I ripped out one of the last five hairs on my head. Good luck!

Upvotes: 1

Gerard G
Gerard G

Reputation: 3463

Xcode Version 7.2.1 (7C1002) Objective C

I had this problem and had to keep on adding the GoogleMobileAds each time to the project to get rid of this. Not sure if this is a bug. First select the GoogleMobileAds.framework then just untick and tick the Target Membership then try build the error goes away. This worked for me. I hope it helps.

Upvotes: 0

Donovan
Donovan

Reputation: 926

For me, the issue was that I hadn't updated my app's "Deployment Target". It was set to < 7.0 which is why it probably was complaining. Once I updated the target to > 7.0, the errors went away. (for future people updating their apps just a few times a year like me)

Upvotes: 1

kaplya
kaplya

Reputation: 239

try to copy your GoogleMobileAds.framework into your root project folder and after that add it to libraries. It works perfectly for me.

Upvotes: 18

M Swapnil
M Swapnil

Reputation: 2381

Make sure to check "copy item if needed" box when copy GoogleMobileAds.framework to your App.

enter image description here

In my case, I had removed framework and again added that framework and checked that box and issue disappeared.

Upvotes: 23

Mark
Mark

Reputation: 2726

None of the other answers to date worked for me. This is what did:

Go to 'Build Phases', 'Link Binary with Libraries'. I had already added the GoogleMobileAds.framework here, so I removed it and re-added it.

To add it, click the + sign for the 'Link Binary with Libraries' section and click 'Add Other...'. Navigate to where you've stored GoogleMobileAds.frameworkand select it.

Make sure you've first added GoogleMobileAds.framework to your project by going to 'File' > 'Add Files to your-project-name'.

That fixed the issue for me.

Upvotes: 15

Shapes Workshop
Shapes Workshop

Reputation: 23

In case somebody is still occuring this error - check if in build settings field "Framework Search Paths" is filled with correct path to your framework

Upvotes: 0

FranMowinckel
FranMowinckel

Reputation: 4343

I solved setting the "Defines Modules" to YES in the Build Settings and reimporting the Framework.

Upvotes: 4

Related Questions