AdMob接入踩坑记

首先列出参考文档:admob官方参考链接

我是cocos2d-x v3.9的工程,在按照官方文档接入之后,出现一堆编译错误例如:

Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_GLKView", referenced from:
      objc-class-ref in GoogleMobileAds(flat-arm64)
  "_CVOpenGLESTextureCacheCreateTextureFromImage", referenced from:
      l2673 in GoogleMobileAds(flat-arm64)
  "_CVOpenGLESTextureGetName", referenced from:
      l2673 in GoogleMobileAds(flat-arm64)
  "_kUTTagClassMIMEType", referenced from:
      l2987 in GoogleMobileAds(flat-arm64)
  "_CVOpenGLESTextureCacheCreate", referenced from:
      l2672 in GoogleMobileAds(flat-arm64)
  "_CVPixelBufferGetHeight", referenced from:
      l2670 in GoogleMobileAds(flat-arm64)
  "_CVOpenGLESTextureCacheFlush", referenced from:
      l2671 in GoogleMobileAds(flat-arm64)
  "_CVBufferGetAttachment", referenced from:
      l2670 in GoogleMobileAds(flat-arm64)
  "_UTTypeCreatePreferredIdentifierForTag", referenced from:
      l2987 in GoogleMobileAds(flat-arm64)
  "_CVPixelBufferGetWidth", referenced from:
      l2670 in GoogleMobileAds(flat-arm64)
  "_kCVImageBufferYCbCrMatrixKey", referenced from:
      l2670 in GoogleMobileAds(flat-arm64)
  "_CVOpenGLESTextureGetTarget", referenced from:
      l2673 in GoogleMobileAds(flat-arm64)
  "_kCVPixelBufferPixelFormatTypeKey", referenced from:
      l090 in GoogleMobileAds(flat-arm64)
  "_kCVImageBufferYCbCrMatrix_ITU_R_601_4", referenced from:
      l2670 in GoogleMobileAds(flat-arm64)
  "_GLKMatrix4Identity", referenced from:
      l2664 in GoogleMobileAds(flat-arm64)
      l2675 in GoogleMobileAds(flat-arm64)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

请参见这篇文章的对照表,加入相应的系统框架:参考文章


framework名 缺少框架会报的错
GLKit.framework _OBJC_CLASS_$_GLKView
_GLKMatrix4Identity
MobileCoreServices.framework _kUTTagClassMIMEType
_UTTypeCreatePreferredIdentifierForTag
CoreVideo.framework _CVOpenGLESTextureCacheCreateTextureFromImage
_CVOpenGLESTextureGetName
_CVOpenGLESTextureCacheCreate
_CVOpenGLESTextureCacheFlush
_CVPixelBufferGetWidth
_CVOpenGLESTextureGetTarget
_kCVPixelBufferPixelFormatTypeKey
_kCVImageBufferYCbCrMatrix_ITU_R_601_4
_CVPixelBufferGetHeight
_CVBufferGetAttachment
_kCVImageBufferYCbCrMatrixKey
StoreKit.framework _OBJC_CLASS_$_SKProductsRequest
_OBJC_CLASS_$_SKMutablePayment
_OBJC_CLASS_$_SKPaymentQueue
_OBJC_CLASS_$_SKStoreProductViewController
_SKStoreProductParameterITunesItemIdentifier
MediaPlayer.framework _MPMoviePlayerPlaybackDidFinishNotification
_MPMoviePlayerPlaybackStateDidChangeNotification
_OBJC_CLASS_$_MPMoviePlayerController
_OBJC_CLASS_$_MPVolumeView
SafariServices.framework _OBJC_CLASS_$_SFSafariViewController
AdSupport.framework _OBJC_CLASS_$_ASIdentifierManager
CoreMotion.framework _OBJC_CLASS_$_CMMotionManager
CoreTelephony.framework _CTRadioAccessTechnologyDidChangeNotification
_OBJC_CLASS_$_CTTelephonyNetworkInfo
MessageUI.framework _OBJC_CLASS_$_MFMailComposeViewController
_OBJC_CLASS_$_MFMessageComposeViewController
CoreText.framework _CTFramesetterCreateWithAttributedString
_CTFramesetterSuggestFrameSizeWithConstraints
GameKit.framework _OBJC_CLASS_$_GKAchievement
_OBJC_CLASS_$_GKScore
_OBJC_CLASS_$_GKGameCenterViewController
_OBJC_CLASS_$_GKLocalPlayer
SystemConfiguration.framework _SCNetworkReachabilityCreateWithAddress
_SCNetworkReachabilityGetFlags
_SCNetworkReachabilityCreateWithName
_SCNetworkReachabilitySetDispatchQueue
_SCNetworkReachabilitySetCallback
Security.framework _SecCertificateCreateWithData
_SecTrustCopyExceptions
_SecTrustEvaluate
_SecTrustSetAnchorCertificates
_SecTrustSetExceptions
CoreMedia.framework _CMTimeGetSeconds
_CMTimeMakeWithSeconds
_CMTimeMake
_kCMTimeZero
OpenGLES.framework _OBJC_CLASS_$_EAGLContext
_glActiveTexture
 
CFNetwork.framework _CFHostCreateWithName
_CFHostStartInfoResolution
_CFHostGetAddressing
一般国外的sdk文档都一个尿性,文档及其简单。

在接入admob插屏广告的时候,我就遇到上面的一类问题,然后就OK了


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
要在 Android 应用中接入 AdMob 广告,需要进行以下步骤: 1. 注册 AdMob 账号并创建广告单元 2. 在 Android Studio 中添加 AdMob SDK 3. 在 AndroidManifest.xml 文件中添加必要的权限和服务 4. 在布局文件中添加 AdView 控件 5. 在代码中加载广告并显示 以下是一个简单的示例: 1. 注册 AdMob 账号并创建广告单元 在 AdMob 的网站上注册账号,并创建一个广告单元。记下广告单元 ID,稍后将用到。 2. 在 Android Studio 中添加 AdMob SDK 在 app 模块的 build.gradle 文件中添加以下依赖: ```groovy implementation 'com.google.android.gms:play-services-ads:20.4.0' ``` 3. 在 AndroidManifest.xml 文件中添加必要的权限和服务 添加以下权限: ```xml <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> ``` 添加以下服务: ```xml <service android:name="com.google.android.gms.ads.AdService" android:exported="false" /> ``` 4. 在布局文件中添加 AdView 控件 在需要显示广告的布局文件中添加 AdView 控件: ```xml <com.google.android.gms.ads.AdView android:id="@+id/adView" android:layout_width="wrap_content" android:layout_height="wrap_content" ads:adSize="BANNER" ads:adUnitId="YOUR_AD_UNIT_ID" /> ``` 将 `adUnitId` 替换为你的广告单元 ID。 5. 在代码中加载广告并显示 在 Activity 或 Fragment 中加载广告并显示: ```java import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView; public class MainActivity extends AppCompatActivity { private AdView mAdView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 加载 AdView 控件 mAdView = findViewById(R.id.adView); // 创建广告请求 AdRequest adRequest = new AdRequest.Builder().build(); // 加载广告 mAdView.loadAd(adRequest); } @Override protected void onPause() { // 暂停广告 mAdView.pause(); super.onPause(); } @Override protected void onResume() { super.onResume(); // 恢复广告 mAdView.resume(); } @Override protected void onDestroy() { // 销毁广告 mAdView.destroy(); super.onDestroy(); } } ``` 以上就是接入 AdMob 广告的基本步骤。需要注意的是,为了获得更好的广告收益,建议遵循 Google 的广告政策并遵守良好的用户体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值