14

MainActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {

        MobileAds.initialize(this) {}
        MobileAds.setRequestConfiguration(
            RequestConfiguration.Builder()
                .setTestDeviceIds(listOf("ABCDEF012345"))
                .build()
        )

        val adRequest = AdRequest.Builder().build()
        Log.d("Activity", "Is Test Device? : ${adRequest.isTestDevice(this)}")
        adView.loadAd(adRequest)

        adView.adListener = object : AdListener() {
            override fun onAdLoaded() {
                super.onAdLoaded()
                Log.d("Activity", "@@ onAdLoaded()")
            }

            override fun onAdFailedToLoad(err: LoadAdError?) {
                super.onAdFailedToLoad(err)
                Log.d("Activity", "@@ onAdFailedToLoad()\n$err")
            }

            override fun onAdOpened() {
                super.onAdOpened()
                Log.d("Activity", "@@ onAdOpened()")
            }

            override fun onAdClicked() {
                super.onAdClicked()
                Log.d("Activity", "@@ onAdClicked()")
            }

            override fun onAdLeftApplication() {
                super.onAdLeftApplication()
                Log.d("Activity", "@@ onAdLeftApplication()")
            }

            override fun onAdClosed() {
                super.onAdClosed()
                Log.d("Activity", "@@ onAdClosed()")
            }
        }
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout                       
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id_for_test" />

</LinearLayout>

string.xml

<resources>
    <string name="admob_app_id">ca-app-pub-000000000000~00000000000</string>
    <string name="bannera_ad_unit_id_for_test">ca-app-pub-3940256099942544/6300978111</string>
</resources>
    

I created <meta-dat> in the manifest and added admob_app_id as the android:value value inside. In the AVD test device provided by Android Studio, a test advertisement appeared without any problems, but the test advertisement did not appear on the actual device. So, as in the MainActivity code above, I called RequestConfiguration and added my mobile device ID("ABCDEF012345") to the test device ID, but the problem was not resolved. The contents of the error were as follows.

enter image description here

Teng-pao Yu
  • 1,313
  • 15
  • 30
H.JiMan
  • 269
  • 1
  • 2
  • 10
  • check the error code, it must be the error code: 0 (internal error) as mentioned here. https://support.google.com/admob/thread/3494603?hl=en – Himanshu Malik Oct 19 '20 at 05:16

8 Answers8

19

Probably not the solution for everyone, but fixed it for me: don't forget to turn off all kinds of adblockers.

I had a adblocker DNS configured, took me some time to finally figure that out.

Merthan Erdem
  • 5,598
  • 2
  • 22
  • 29
  • 2
    this is the correct answer, I had the same error on my rooted device with an adblocker installed (lucky patcher), when I re-enabled ads on the adblocker the error is no more. – yazan sayed Jul 18 '21 at 11:31
  • 1
    also, this happens if you have pi-hole like me. this answer helped a lot. – ads Oct 19 '21 at 05:48
  • also this happens when you are using manual proxy on your device connection – Ali Tamoor Mar 15 '22 at 05:10
2

Most of the time AdMob does not perform as expected on the emulator, because there was no same stuff like play store services on it. Try on a real device. Sometimes a cold boot on the emulator solve the problem.

  1. Visit the AdMob Policy Center to view any pending violations.
  2. Don't use VPN, Don't use Proxy at all.
  3. Just make sure to use test ad unit ID while debugging.
  4. Perform a cold boot on the emulator.
  5. Use a real device instead emulator.
ucMedia
  • 4,105
  • 4
  • 38
  • 46
1

I was using manual proxy for the WIFI, ad forget to change and this strange thing happened to me was Unable to obtain a JavascriptEngine in onAdFailedToLoad, just soled by modifying the WIFI Network to Proxy>NONE in the Advance option by Long Tap on the connected WIFI

Ali Tamoor
  • 896
  • 12
  • 18
0

In my case, the device wifi was ON but no internet connection, once I fixed the Internet issue, Ads started loading.

SidHunt
  • 19
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 05 '22 at 10:46
0

For Russia where AdMob is blocked by Google nowdays, you otherwise should switc VPN On.

0

Add these lines in proguard-rule file

-keep class com.google.android.gms.ads.** { *; }
-keep class com.google.ads.** { *; }

Also read about Proguard and AdMob

Proguard and AdMob mediation

Hesham Yemen
  • 437
  • 5
  • 6
-2

I've got a similar issue on Android when using native ads. The error information is very similar :

code:0 message:Unable to obtain a JavascriptEngine. domain:com.google.android.gms.ads cause:null responseInfo:{
  "Response ID": "null",
  "Mediation Adapter Class Name": "",
  "Adapter Responses": []
}

But, I've got a clue that might be the reason for this: As I've noticed weird crashes sometimes on the app, I've decided to add a check that indeed the app seems valid, by checking its signature.

What I've found is that in this case, at least 2 devices had the app changed (maybe by the same person). So this user for some reason tried to change the app. No idea what he tried to do with it, but I hope this could solve your problem.

If you want, here's a basic way to do it:

private var sIsValidInstall: Boolean? = null
private const val BYTE_SIZE_FOR_DEBUG_SIGNATURE=...
private const val CRC_FOR_DEBUG_SIGNATURE=...
private const val BYTE_SIZE_FOR_DEBUG_SIGNATURE=...
private const val CRC_FOR_DEBUG_SIGNATURE=...

@SuppressLint("PackageManagerGetSignatures")
fun isValidInstall(context: Context): Boolean {
    sIsValidInstall?.let { return it }
    var isValid = false
    val signatures = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
        context.packageManager.getPackageInfo(context.packageName, PackageManager.GET_SIGNING_CERTIFICATES).signingInfo.apkContentsSigners
    else context.packageManager.getPackageInfo(context.packageName, PackageManager.GET_SIGNATURES).signatures
    for (signature in signatures) {
        val bytes = signature.toByteArray()
        if (bytes != null) {
            val bytesSize = bytes.size
            val checksum = CRC32()
            checksum.update(bytes, 0, bytes.size)
            val crc = checksum.value
            isValid = (BuildConfig.DEBUG && bytesSize == BYTE_SIZE_FOR_DEBUG_SIGNATURE && crc == CRC_FOR_DEBUG_SIGNATURE) || (!BuildConfig.DEBUG && bytesSize == BYTE_SIZE_FOR_DEBUG_SIGNATURE && crc == CRC_FOR_DEBUG_SIGNATURE)
            if (isValid)
                break

        }
    }
    sIsValidInstall = isValid
    return isValid
}

Another possible reason :

The time setting is wrong on the device.

android developer
  • 114,585
  • 152
  • 739
  • 1,270
-4

I got same issue, i fixed it just by change device. Detail: I integrated google admob and mediation for native android. Based on a google tutorial, when building for samsung s7, i got problem “Unable to obtain a JavascroptEngine". After that I found a way to solve that but nothing change. I tried by using another device (shark 1) and the ad loaded. If you got the same problem, try using another device.

Mahir Islam
  • 1,941
  • 2
  • 12
  • 33