gpt4 book ai didi

android - 如何修复 Android AdMob "Unable to obtain a JavascriptEngine"错误?

转载 作者:行者123 更新时间:2023-12-04 12:00:22 33 4
gpt4 key购买 nike

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>

我创建了 <meta-dat>在 list 中并添加了 admob_app_id作为 android:value里面的值。在 Android Studio 提供的 AVD 测试设备中,出现了一个测试广告没有任何问题,但测试广告并没有出现在实际设备上。所以,就像 MainActivity上面的代码,我调用了 RequestConfiguration并将我的移动设备 ID( "ABCDEF012345")添加到测试设备 ID,但问题没有解决。错误内容如下。
enter image description here

最佳答案

可能不是每个人的解决方案,但为我修复了它:不要忘记关闭各种广告拦截器 .
我配置了一个 adblocker DNS,花了我一些时间才最终弄清楚。

关于android - 如何修复 Android AdMob "Unable to obtain a JavascriptEngine"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64020685/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com