【问题标题】:Adding ads in Android Studio在 Android Studio 中添加广告
【发布时间】: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 错误。

标签: android firebase admob


【解决方案1】:

您上传的 APK 使用与之前的 APK 不同的证书进行签名。您必须使用相同的证书。 如何解决这个问题?

我搜索了other StackOverflow questions 并得知上述查询的答案只有一个。也就是说,APK 发布文件必须使用相同的私钥或您所说的 KeyStore 进行签名。(更具体地说,是 Java KeyStore。)

我犯的错误是我不小心删除了原来的 KeyStore 文件。现在,如果我使用新的 KeyStore 上传更新的 APK,Google Developer Console 将不会将其识别为对现有应用程序的更新。相反,它假定您正在上传新应用的 APK。这就是您收到上述错误的原因。即使更新versionCode 错误仍然存​​在。

您可以在此处详细阅读解决方案:https://stackoverflow.com/a/26296942/3647180

【讨论】:

    猜你喜欢
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多