Okay, So I’ve been beating my head against the desk for two days trying to resolve this problem and I’m at a loss. Hoping it’s something simple, but not sure.
I have an Android project making use of Google AdMob. I’ve followed all of the instructions from the AdMob developer site. When building my project it fails with the following error:
Task :app:processDebugResources FAILED
AGPBI: {“kind”:”error”,”text”:”Android resource linking failed”,”sources”:[{“file”:”/Users/user12345/Developer/Android Studio Projects/MyApp/app/src/main/res/layout/activity_main.xml”,”position”:{“startLine”:213}}],”original”:”ERROR: /Users/user12345/Developer/Android Studio Projects/MyApp//app/src/main/res/layout/activity_main.xml:214: AAPT: error: attribute adUnitID (aka com.someorg.MyApp.debug:adUnitID) not found.n “,”tool”:”AAPT”}
Execution failed for task ‘:app:processDebugResources’.
A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
Android resource linking failed
ERROR: /Users/user12345/Developer/Android Studio Projects/MyApp/app/src/main/res/layout/activity_main.xml:214: AAPT: error: attribute adUnitID (aka com.someorg.myapp.debug:adUnitID) not found.
Clearly it’s pointing at the XML file. In my XML, this is what I have:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:context=".MainActivity">
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="0dp"
android:layout_height="75dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:backgroundTint="#000000"
ads:adSize="BANNER"
ads:adUnitID="@string/banner_ad_unit_id"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent">
</com.google.android.gms.ads.AdView>
</androidx.constraintlayout.widget.ConstraintLayout>
For some reason the resource linker isn’t finding adUnitID. This my app-level build.gradle file:
android {
namespace 'com.someorg.myapp'
compileSdk 34
defaultConfig {
applicationId "com.someorg.myapp"
minSdkVersion 24
targetSdkVersion 34
versionCode 7
versionName '1.0.7'
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildFeatures {
buildConfig true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
signingConfig signingConfigs.debug
debuggable false
}
debug {
applicationIdSuffix ".debug"
debuggable true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dependencies {
implementation 'com.squareup.okhttp3:okhttp:4.11.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.11.0"))
implementation 'com.google.android.gms:play-services-maps:18.2.0'
implementation 'androidx.activity:activity:1.9.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.squareup.retrofit2:converter-jackson:2.7.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.10.3'
implementation 'com.fasterxml.jackson.core:jackson-core:2.10.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.10.3'
implementation 'com.android.support:multidex:1.0.3'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'
implementation 'com.google.android.gms:play-services-ads:23.3.0'
implementation 'com.google.android.gms:play-services-ads-base:23.3.0'
}
}
And this is the portion of the Manifest.XML file that contains the :
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-################~##########"/>
(I have redacted the app-id in the above)
I have no idea what to do at this point. I might try building a new sample project and see if I can get just an adview working.
2
Per Mike M. – the problem was a capital D in this line of XML:
ads:adUnitID="@string/banner_ad_unit_id"
which I changed to:
ads:adUnitId="@string/banner_ad_unit_id"
And this resolved the problem.