Module 'GoogleMobileAds' not found in iOS

后端 未结 20 2318
感动是毒
感动是毒 2020-12-09 07:42

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

20条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 08:34

    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
    

提交回复
热议问题