简体   繁体   English

我在初始化 Google 移动广告 SDK 时遇到问题

[英]I am having problem with Initialize the Google Mobile Ads SDK

I want to add Google Ads to my Android mobile app.我想将 Google Ads 添加到我的 Android 移动应用中。 So I went through this steps: https://developers.google.com/admob/android/quick-start?hl=de#kotlin所以我经历了这个步骤: https://developers.google.com/admob/android/quick-start?hl=de#kotlin

My problems:我的问题:

1- When I add the dependencies for the Google Mobile Ads SDK to my module's app-level Gradle file, normally app/build.gradle: 1-当我将谷歌移动广告 SDK 的依赖项添加到我的模块的应用级 Gradle 文件中时,通常是 app/build.gradle:

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.android.gms:play-services-ads:20.5.0' }

I get the following error我收到以下错误

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
   > The minCompileSdk (31) specified in a
     dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
     is greater than this module's compileSdkVersion (android-30).
     Dependency: androidx.work:work-runtime:2.7.0.
     AAR metadata file: C:\Users\moham\.gradle\caches\transforms-2\files-2.1\6ca6bfbb6ed79157a08fdd6548cc9e4d\work-runtime-2.7.0\META-INF\com\android\build\gradle\aar-metadata.properties.

2- When I want to Initialize the Google Mobile Ads SDK on MainActivity.kt I get the following error 2- 当我想在MainActivity.kt上初始化 Google 移动广告 SDK 时,我收到以下错误

e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (4, 12): Unresolved reference: google
e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (6, 22): Unresolved reference: AppCompatActivity
e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (7, 5): 'onCreate' overrides nothing
e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (7, 47): Unresolved reference: Bundle
e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (8, 15): Unresolved reference: onCreate
e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (9, 9): Unresolved reference: setContentView
e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (9, 33): Unresolved reference: activity_main
e: C:\Users\moham\flutter\zwei\android\app\src\main\kotlin\com\example\zwei\MainActivity.kt: (11, 9): Unresolved reference: MobileAds

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> Compilation error. See log for more details

What should I do to solve the errors?我应该怎么做才能解决错误?

Looked carefully at the error this time.这次仔细看了一下错误。

Soln(1): Try updating your compileSDKVersion to 31 or 32. Please let me know if the error still persists. Soln(1):尝试将您的 compileSDKVersion 更新为 31 或 32。如果错误仍然存在,请告诉我。

android { compileSdkVersion 32 //Like this buildToolsVersion "32.0.0".... } android { compileSdkVersion 32 //像这样 buildToolsVersion "32.0.0".... }

Soln(2): The other way is to actually "downgrade" the library to that stage when it didn't need the SDK version to be >=31(but I won't recommend doing this). Soln(2):另一种方法是在不需要 SDK 版本 >=31 时将库实际“降级”到那个阶段(但我不建议这样做)。

After doing Soln(1), do this: ext.kotlin_version = '1.4.32' (or the latest one available)完成 Soln(1) 后,执行以下操作: ext.kotlin_version = '1.4.32' (或可用的最新版本)

(Should solve the error you mentioned in the comment) (应该解决您在评论中提到的错误)

Also, make sure it's updated in Android Studio as well.此外,请确保它也在 Android Studio 中进行了更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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