My app works. Then I add the one line into my build.gradle
(ie the admob adverts):
implementation 'com.google.android.gms:play-services-ads:22.5.0'
and then my app will not work, automatically closing as soon as it loads.
My phone is Android Nougat 7.0 (ie sdk 24.0). As far as I am aware the ads should be ok on that. Am I correct?
Any idea why this fails?
Edit:
The error is (sorry it does not format very well, please scroll right):
E FATAL EXCEPTION: main
Process: com.myapp.www.myapp, PID: 6415
java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:
******************************************************************************
* Invalid application ID. Follow instructions here: *
* https://googlemobileadssdk.page.link/admob-android-update-manifest *
* to find your app ID. *
* Google Ad Manager publishers should follow instructions here: *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest. *
******************************************************************************
at android.app.ActivityThread.installProvider(ActivityThread.java:5977)
at android.app.ActivityThread.installContentProviders(ActivityThread.java:5545)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5484)
at android.app.ActivityThread.-wrap2(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6251)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1067)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)
Caused by: java.lang.IllegalStateException:
******************************************************************************
* Invalid application ID. Follow instructions here: *
* https://googlemobileadssdk.page.link/admob-android-update-manifest *
* to find your app ID. *
* Google Ad Manager publishers should follow instructions here: *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest. *
******************************************************************************
at com.google.android.gms.ads.internal.client.zzek.attachInfo(com.google.android.gms:play-services-ads-lite@@22.5.0:15)
at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@22.5.0:1)
at android.app.ActivityThread.installProvider(ActivityThread.java:5974)
... 10 more
My project build.gradle
is (note I have to hash out allprojects
or otherwise the gradle will not sync):
buildscript {
repositories {
google()
mavenCentral()
}
}
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
}
//allprojects {
// repositories {
// google()
// mavenCentral()
// }
//}
My android manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.myapp.www.myapp">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />
<!-- android:dataExtractionRules="@xml/data_extraction_rules"-->
<!-- android:fullBackupContent="@xml/backup_rules"-->
<!-- tools:targetApi="33"-->
<!-- tools:ignore="ExtraText">-->
<!-- <meta-data-->
<!-- android:name="android.app.lib_name"-->
<!-- android:value="" />-->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher_foreground"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round_foreground"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp">
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
My app build.gradle
:
plugins {
id 'com.android.application'
}
android {
compileSdk 34
defaultConfig {
applicationId "com.myapp.www.myapp"
minSdk 19
targetSdk 34
versionCode 1021
versionName "1.021"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
javaCompileOptions {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
def billing_version = "6.0.1"
/* This is for the billing library we are using */
/* implementation 'com.anjlab.android.iab.v3:library:1.0.44' */
/* New Google's Billing */
/* implementation 'com.android.billingclient:billing:2.2.0' */
implementation "com.android.billingclient:billing:$billing_version"
/* TEMP ADVERTS */
/* This is for adverts */
/* implementation 'com.google.android.gms:play-services-ads:15.0.0' */
/* Consent for Adverts GDPR */
/* /* implementation 'com.google.android.ads.consent:consent-library:1.0.6' */
/* implementation 'com.google.android.ads.consent:consent-library:1.0.7' */
/* Adverts */
implementation 'com.google.android.gms:play-services-ads:22.5.0'
/* GDPR */
/* implementation 'com.google.android.ump:user-messaging-platform:2.1.0' */
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
/* This for ImmutableList */
implementation 'com.google.guava:guava:31.1-android'
implementation 'androidx.multidex:multidex:2.0.1'
}
In my onCreate
function:
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
Error log:
******************************************************************************
* Invalid application ID. Follow instructions here: *
* https://googlemobileadssdk.page.link/admob-android-update-manifest *
* to find your app ID. *
* Google Ad Manager publishers should follow instructions here: *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest. *
******************************************************************************
You should provide a valid id for it to start. Find your app ID from Ad Manager web interface. Moreover you can use a sample ID to test the SDK. If you try with this ID, the application will open.
You must replace this part with your own id.
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"
With sample ID:
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>