【发布时间】:2016-12-05 13:15:37
【问题描述】:
我是 Android 开发新手,想了解如何在 Android 应用中添加广告。我研究了各种Firebase 和 Android 开发者链接,最后添加了代码。
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"/>
应用级分级:
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'
项目级 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);
有什么我遗漏的吗?当我将其作为 Play 商店中已发布应用的更新发布时,我能否看到广告?另外,Admob 将如何付款给我?
应用程序运行后没有错误。
谢谢, Kvaibhav01.
更新:我尝试在开发者控制台中发布 app-release.apk 文件,它显示:
您上传了一个使用不同证书签名的 APK 您以前的 APK。您必须使用相同的证书。
如何解决这个问题?
【问题讨论】:
-
您的问题是因为您使用不同的密钥来签署 apk。不是因为 admob。
-
好的@ישואוהבאותך。但是如何更正密钥呢?
-
@ישואוהבאותך 没有给出解决方案!我的应用遇到 same certificate 错误。