I'm trying to show native test ads on my project (play-services-ads:20.5.0). I tried this way and get different errors with the same error code. Can't really figure out is it a server issue or my implementation can't fulfill SDK's requirements. I waited more than 2 hours (SpinUp Time) but it doesn't work.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MobileAds.initialize(getApplicationContext());
Log.d("him", "SDK initialized");
AdLoader adLoader = new AdLoader.Builder(getApplicationContext(), "ca-app-pub-3940256099942544/2247696110")
.forNativeAd(new NativeAd.OnNativeAdLoadedListener() {
@Override
public void onNativeAdLoaded(@NonNull NativeAd nativeAd) {
Log.d("him", "NativeAdLoaded");
NativeTemplateStyle styles = new
NativeTemplateStyle.Builder().build();
TemplateView template = findViewById(R.id.my_template);
template.setStyles(styles);
template.setNativeAd(nativeAd);
}
}) .withAdListener(new AdListener() {
@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
// Handle the failure by logging, altering the UI, and so on.
Log.d("him", "AdFailedToLoad error is: \n" + adError);
}
})
.build();
adLoader.loadAd(new AdRequest.Builder().build());
}
}
I'm getting two types error one is from physical device which is this:
"Code": 0,
"Message": "Unable to obtain a JavascriptEngine.",
"Domain": "com.google.android.gms.ads",
"Cause": "null",
"Response Info": {
"Response ID": "null",
And another is from emulator, which is this:
"Code": 0,
"Message": "Internal error.",
"Domain": "com.google.android.gms.ads",
"Cause": "null",
"Response Info": {
"Response ID": "hu2sYZCLOJO39QP7qIvoBw",
"Mediation Adapter Class Name": "",
"Adapter Responses": [
{
"Adapter": "com.google.ads.mediation.admob.AdMobAdapter",
"Latency": 29,
"Credentials": {},
"Ad Error": {
"Code": 0,
"Message": "Internal error.",
"Domain": "com.google.android.gms.ads",
"Cause": "null"
}
}
I got another issue while using emulator which is here:
Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: lu@bc13fba
Thanks in advance
I tried another device to test the code and it worked perfectly.
Please check if you have an adblock installed on that device.
Please also try this TEMP solution "it might help":- in build.gradle
app level, change the app id to:
applicationId "com.google.example.gms.nativeadvancedexample"
and let's know if the result.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.