我的应用程序在尝试加载facebook本机广告时崩溃,以下是日志错误:
2020-11-14 12:31:15.968 5710-5710/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.demopackage.name, PID: 5710
java.lang.NoSuchMethodError: No static method isChildDirected()Z in class Lcom/facebook/ads/AdSettings; or its super classes (declaration of 'com.facebook.ads.AdSettings' appears in /data/app/com.demopackage.name-meNj0dpRfln7Tuz2WwJzdQ==/base.apk)
at com.facebook.ads.redexgen.X.1l.A01(:3647)
at com.facebook.ads.redexgen.X.S9.A0B(:53051)
at com.facebook.ads.redexgen.X.S9.A0Q(:53123)
at com.facebook.ads.redexgen.X.S9.A0R(:53125)
at com.facebook.ads.redexgen.X.cR.A1M(:74774)
at com.facebook.ads.redexgen.X.Jy.loadAd(:41976)
at com.facebook.ads.redexgen.X.cR.loadAd(:74897)
at com.facebook.ads.NativeAdBase.loadAd(NativeAdBase.java:242)
at com.demopackage.name.activities.MainActivity.loadNativeAd(MainActivity.java:216)
at com.demopackage.name.activities.MainActivity.onCreate(MainActivity.java:157)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
我正在使用最新版本的facebook受众网络sdk 'com.facebook.android:audience-network-sdk:6.2.0'
还试过 'com.facebook.android:audience-network-sdk:6.0.0'
以下是在许多其他应用程序上使用的实现及其工作原理,但不适用于此应用程序:
nativeAd = new NativeAd(this, getString(R.string.fb_native));
NativeAdListener nativeAdListener = new NativeAdListener() {
@Override
public void onMediaDownloaded(Ad ad) {
// Native ad finished downloading all assets
Log.e(TAG, "Native ad finished downloading all assets.");
}
@Override
public void onError(Ad ad, AdError adError) {
// Native ad failed to load
Log.e(TAG, "Native ad failed to load: " + adError.getErrorMessage());
}
@Override
public void onAdLoaded(Ad ad) {
// Render the Native Ad Template
View adView = NativeAdView.render(MainActivity.this, nativeAd);
LinearLayout nativeAdContainer = (LinearLayout) findViewById(R.id.native_ad_container);
// Add the Native Ad View to your ad container.
// The recommended dimensions for the ad container are:
// Width: 280dp - 500dp
// Height: 250dp - 500dp
// The template, however, will adapt to the supplied dimensions.
nativeAdContainer.addView(adView, new ViewGroup.LayoutParams(MATCH_PARENT, 800));
// Native ad is loaded and ready to be displayed
Log.d(TAG, "Native ad is loaded and ready to be displayed!");
}
@Override
public void onAdClicked(Ad ad) {
// Native ad clicked
Log.d(TAG, "Native ad clicked!");
}
@Override
public void onLoggingImpression(Ad ad) {
// Native ad impression
Log.d(TAG, "Native ad impression logged!");
}
};
// Request an ad
nativeAd.loadAd(
nativeAd.buildLoadAdConfig()
.withAdListener(nativeAdListener)
.withMediaCacheFlag(NativeAdBase.MediaCacheFlag.ALL)
.build());
应用程序在不调用 loadAd
方法。
以下是我在应用程序上使用的依赖项:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.exifinterface:exifinterface:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.browser:browser:1.2.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.multidex:multidex:2.0.1'
implementation "androidx.work:work-runtime:2.4.0"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.hold1:keyboardheightprovider:0.0.9'
implementation 'org.wysaid:gpuimage-plus:2.6.3'
implementation 'com.karumi:dexter:6.2.1'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.steelkiwi:cropiwa:1.0.3'
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.airbnb.android:lottie:3.4.1'
implementation 'com.github.pavlospt:circleview:1.3'
implementation 'de.hdodenhof:circleimageview:3.1.0'
implementation 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'
implementation 'io.reactivex.rxjava2:rxjava:2.2.19'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.agrawalsuneet.androidlibs:dotsloader:1.4'
implementation 'com.isseiaoki:simplecropview:1.1.8'
implementation 'com.google.android.gms:play-services-ads:19.5.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.facebook.android:audience-network-sdk:6.2.0'
// implementation 'com.unity3d.ads:unity-ads:3.4.6'
}
暂无答案!
目前还没有任何答案,快来回答吧!