簡體   English   中英

錯誤:找不到符號導入 com.google.android.gms.ads.InterstitialAd

[英]Error: cannot find symbol import com.google.android.gms.ads.InterstitialAd

我在項目中添加了 google AdMob 並發現了這個錯誤: error: cannot find symbol import com.google.android.gms.ads.InterstitialAd; ^ 符號:class InterstitialAd 位置:package com.google.android.gms.ads

如果在將com.google.android.gms:play-services-ads依賴項更新為更新版本后出現此錯誤,請注意導入com.google.android.gms.ads.InterstitialAd自版本 19.7.0 以來已被棄用並已被完全刪除。

新的導入應該是:

import com.google.android.gms.ads.interstitial.InterstitialAd;

要么將com.google.android.gms:play-services-ads恢復到 19.7.0 之前的版本,要么按照此處的文檔更新您的代碼: https://developers.google.com/admob/android/interstitial

我找到了答案:將此代碼添加到 build.gradle(app) (在 android 標簽中)


configurations.all {
  resolutionStrategy {
    force "com.google.android.gms:play-services-basement:17.0.0"
    force "com.google.android.gms:play-services-base:17.1.0"
    force "com.google.android.gms:play-services-stats:17.0.0"
    force "com.google.android.gms:play-services-gcm:17.0.0"
    force "com.google.android.gms:play-services-ads:19.7.0"
 }
}

如果您在一個庫中使用了 admob,請將上面的代碼也添加到庫 gradle 中

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM