简体   繁体   中英

Flutter plugin: No such module 'google_mobile_ads' in iOS native code

I create a Flutter plugin for Admob to reuse in my different projects for banner, interstitial, native ad and rewarded ads. I create it so that I can just add the plugin to other project's pubspec.yaml and use without recode everytime.

It works fine on Android code, the "google_mobile_ads" sdk is recognized and can be accessed without adding any dependency.

But, the problem is that the google_mobile_ads is not recognized in my iOS code (to create the Native Ad Factory) when Run Build in Xcode. When I use "Ctrl + Click" the "FLTNativeAdFactory" class to "Jump to Definition" in Xcode, it works but the build fail with the error. See the attached image.

Here is my code and setup:

  • admob_ads plugin pubspec.yaml admob_ads 插件 pubspec.yaml

  • the ios code podspec

Pod::Spec.new do |s|
  s.name             = 'admob_ads'
  s.version          = '0.0.1'
  s.summary          = 'A new Flutter plugin project.'
  s.description      = <<-DESC
A new Flutter plugin project.
                       DESC
  s.homepage         = 'http://example.com'
  s.license          = { :file => '../LICENSE' }
  s.author           = { 'Your Company' => 'email@example.com' }
  s.source           = { :path => '.' }
  s.source_files = 'Classes/**/*'
  s.dependency 'Flutter'
  s.dependency 'Cosmos', '~> 23.0'
  s.platform = :ios, '9.0'

  # Flutter.framework does not contain a i386 slice.
  s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES', 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'i386' }
  s.swift_version = '5.0'
end
  • The ios code tree and error: 在此处输入图像描述

Please help!

You can refer to this error log: https://github.com/googleads/googleads-mobile-flutter/issues/594

Until it gets fixed, this is the current workaround:

In your pubspec.yaml, change

google_mobile_ads: ^1.0.1

to:

  google_mobile_ads:
    git:
      url: https://github.com/googleads/googleads-mobile-flutter
      ref: 356875362ddb2ac2e0056385d2729c093722fb8d
      path: packages/google_mobile_ads

or this:

  google_mobile_ads:
    git:
      url: https://github.com/jjliu15/googleads-mobile-flutter-1.git
      path: packages/google_mobile_ads/

I found it worked better when I took the ref: out.

You could try this one:

  google_mobile_ads:
    git:
      url: https://github.com/jjliu15/googleads-mobile-flutter-1.git
      ref: delete_deprecations
      path: packages/google_mobile_ads/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM