I'm new to Android development and want to know about adding ads in Android app. I researched through various Firebase and Android Developers links and finally added the code(s).
ActivityMain.XML:
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
AndroidManifest.XML:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package.name">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
App-level gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "my.ID"
minSdkVersion 15
targetSdkVersion 23
versionCode 2
versionName "2"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:support-v4:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.android.support:multidex:1.0.0'
}
apply plugin: 'com.google.gms.google-services'
Project-level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Strings.XML:
<string name="banner_ad_unit_id">AppID from AdMob</string>
MainActivity.JAVA:
MobileAds.initialize(getApplicationContext(), "ca-app-pub-APPID from ADMob");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Is there something which I'm missing? Will I be able to see ads when I publish it as an update to the already published app in Play Store? Also, how will Admob pay me?
There're no errors after running the app.
Thanks, Kvaibhav01.
Update: I tried to publish the app-release.apk file in the Developer Console and it says:
You uploaded an APK that is signed with a different certificate to your previous APKs. You must use the same certificate.
How to fix this?