2
我正在構建一個具有兩個版本的Android應用程序。和一個沒有廣告。 。我已成功將AdMob
集成到應用程序中。但廣告沒有顯示在屏幕上。AdMob - 廣告未顯示 - 錯誤2
這裏是我的
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myapp"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors{
free{
applicationId "com.myapp"
buildConfigField "boolean","IS_PAID_VERSION", "false"
}
paid{
applicationId "com.myapp.paid"
buildConfigField "boolean","IS_PAID_VERSION", "true"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
tools:context="com.myapp.activities.AdTestActivity">
<com.google.android.gms.ads.AdView
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/ad_unit_id" />
</RelativeLayout>
AdTestActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.myapp.R;
public class AdTestActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ad_test);
final AdView adView = (AdView) findViewById(R.id.ad_view);
final AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("A144A6A159A94CC77CE70EC1A874B93A") //My test device 1
.addTestDevice("8477FA9B6C105C84897FC2717E19A548") //My test device 2
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
}
}
的廣告是沒有得到顯示在屏幕上,而logcat
說...
I/Ads: Starting ad request.
02-12 00:24:41.381 15472-15493/com.myapp W/Ads: There was a problem getting an ad response. ErrorCode: 2
02-12 00:24:41.382 15472-15472/com.myapp I/Ads: Scheduling ad refresh 60000 milliseconds from now.
02-12 00:24:41.382 15472-15472/com.myapp W/Ads: Failed to load ad: 2
PS:我有一個良好的互聯網連接和有效AdUnitId
。我的設備中沒有任何種類的AdBlock
應用程序。我也讀過關於這個問題的所有線程,但他們都沒有爲我工作。
我在這做錯了什麼? :(
在以下問題,我發現錯了日期導致錯誤2: http://stackoverflow.com/a/31811314/4860513 – W0rmH0le
是的,我正確的日期是從網絡同步 – theapache64
錯誤列表在這裏: https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#ERROR_CODE_NETWORK_ERROR 錯誤2似乎是一個網絡錯誤...不幸的是,我不知道如何幫助您更多..您正在使用最新版本(8.4.0 )對我而言,廣告停止工作imes也在調試應用程序,而商業應用程序永遠不會失敗......也許,是一個暫時的問題。希望你找到解決方案。 – W0rmH0le