Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix the Android AdMob "Unable to obtain a JavascriptEngine" error?

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

like image 732
H.JiMan Avatar asked Sep 23 '20 03:09

H.JiMan


People also ask

How do I get Javascriptengine?

Under the “Settings” tab, locate the “Advanced” section and click on “Sites and downloads”. 5. Next, scroll down to locate “Allow JavaScript” and toggle on the switch beside it to enable JavaScript on your Android phone or tablet.


1 Answers

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.

like image 135
Merthan Erdem Avatar answered Sep 17 '22 20:09

Merthan Erdem