【发布时间】:2022-01-11 03:34:48
【问题描述】:
我正在尝试在我的项目中展示原生测试广告 (play-services-ads:20.5.0)。我尝试过这种方式并使用相同的错误代码得到不同的错误。无法确定是服务器问题还是我的实现无法满足 SDK 的要求。我等了 2 个多小时(SpinUp Time),但它不起作用。
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());
}
}
我收到两种类型的错误,一种来自物理设备:
"Code": 0,
"Message": "Unable to obtain a JavascriptEngine.",
"Domain": "com.google.android.gms.ads",
"Cause": "null",
"Response Info": {
"Response ID": "null",
另一个来自模拟器,是这样的:
"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"
}
}
我在使用模拟器时遇到了另一个问题:
Exception thrown while unbinding
java.lang.IllegalArgumentException: Service not registered: lu@bc13fba
提前致谢
【问题讨论】:
标签: android service admob ads illegalargumentexception