test ad not show after proguard

164 views
Skip to first unread message

贾鑫

unread,
Feb 16, 2020, 3:18:32 AM2/16/20
to Google Mobile Ads SDK Developers
My test ads not show after the proguard option is open.
Ads are shown in debug mode or the proguard option is off.

Here are some logs when ads not show:

E/Ads     ( 9712): Unable to invokeJavascript

E/Ads     ( 9712): java.lang.NullPointerException: Attempt to invoke interface method 'org.json.JSONObject d.c.b.a.f.a.j8.a(java.lang.Object)' on a null object reference

E/Ads     ( 9712): at d.c.b.a.f.a.r8.a(SourceFile:5)

E/Ads     ( 9712): at d.c.b.a.f.a.u8.a(SourceFile:3)

E/Ads     ( 9712): at d.c.b.a.f.a.km.onSuccess(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.k81.run(SourceFile:2)

E/Ads     ( 9712): at d.c.b.a.f.a.d81.execute(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.zl.execute(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.k71.b(SourceFile:36)

E/Ads     ( 9712): at d.c.b.a.f.a.k71.a(SourceFile:61)

E/Ads     ( 9712): at d.c.b.a.f.a.k71.a(SourceFile:22)

E/Ads     ( 9712): at d.c.b.a.f.a.z81.a(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.b8.a(SourceFile:5)

E/Ads     ( 9712): at d.c.b.a.f.a.km.onSuccess(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.k81.run(SourceFile:2)

E/Ads     ( 9712): at d.c.b.a.f.a.d81.execute(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.zl.execute(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.k71.b(SourceFile:36)

E/Ads     ( 9712): at d.c.b.a.f.a.k71.a(SourceFile:61)

E/Ads     ( 9712): at d.c.b.a.f.a.k71.a(SourceFile:22)

E/Ads     ( 9712): at d.c.b.a.f.a.z81.a(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.m7.a(SourceFile:14)

E/Ads     ( 9712): at d.c.b.a.f.a.f7.a(SourceFile:2)

E/Ads     ( 9712): at d.c.b.a.f.a.iq.a(SourceFile:114)

E/Ads     ( 9712): at d.c.b.a.f.a.br.a(SourceFile:5)

E/Ads     ( 9712): at d.c.b.a.f.a.dr.run(SourceFile)

E/Ads     ( 9712): at android.os.Handler.handleCallback(Handler.java:815)

E/Ads     ( 9712): at android.os.Handler.dispatchMessage(Handler.java:104)

E/Ads     ( 9712): at d.c.b.a.f.a.z51.a(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.bj.a(SourceFile:1)

E/Ads     ( 9712): at d.c.b.a.f.a.z51.dispatchMessage(SourceFile:1)

E/Ads     ( 9712): at android.os.Looper.loop(Looper.java:194)

E/Ads     ( 9712): at android.app.ActivityThread.main(ActivityThread.java:5714)

E/Ads     ( 9712): at java.lang.reflect.Method.invoke(Native Method)

E/Ads     ( 9712): at java.lang.reflect.Method.invoke(Method.java:372)

E/Ads     ( 9712): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:984)

E/Ads     ( 9712): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)

I/Ads     ( 9712): Ad failed to load : 0

I/Ads     ( 9712): Ad failed to load : 0


when i close the proguard, it will load the javascript and show ads.

I/Ads     ( 2944): SDK version: afma-sdk-a-v19649000.19649000.0

D/WebView ( 2944): evaluateJavascript=google.afma.response.normalize({"id":"2b5c6744-dc6b-4ed5-b71a-3c9e45907098","args":{"request":{"base_url":"https:\/\/googleads.g.doubleclick.net\/mads\/gma?caps=inlineVideo_interactiveVideo_mraid1_mraid2_mraid3_sdkVideo_th_autoplay_mediation_scroll_av_transparentBackground_sdkAdmobApiForAds_di_sfv_dinm_dim_nav_navc_dinmo_ipdof_gls_xSeconds&eid=318483742&format=360x56_as&heap_free=266896&heap_max=268435456&heap_total=106083488&js=afma-sdk-a-v19649000.19649000.0&msid=com.jasonjia.animalsounds&preqs=3&seq_num=4&target_api=29#caps=inlineVideo_interactiveVideo_mraid1_mraid2_mraid3_sdkVideo_th_autoplay_mediation_scroll_av_transparentBackground_sdkAdmobApiForAds_di_sfv_dinm_dim_nav_navc_dinmo_ipdof_gls_xSeconds&eid=318483742&format=360x56_as&heap_free=266896&heap_max=268435456&heap_total=106083488&js=afma-sdk-a-v19649000.19649000.0&msid=com.jasonjia.animalsounds&preqs=3&seq_num=4&target_api=29","signals":{"submodel":"vivo X6Plus D","consent_string":"{\"providers\":[],\"consent_state\":\"unknown\",\"consented_providers\":[],\"has_any_npa_pub_id\":false,\"is_request_in_eea_or_unknown\":false,\"pub_ids\":[\"pub-6199052120886352\"],\"raw_response\":\"{\\\"is_request_in_eea_or_unknown\\\":false}\",\"plat\":\"android\",\"version\":\"1.0.7\",\"tag_for_under_age_of_consent\":false}","simulator":false,"android_app_volume":1,"disable_ml":false,"ad_types":["banner"],"device":{"battery":{"battery_level":0.44,"is_charging":true},"build":"vivo\/PD1501D\/PD1501D:5.1\/LMY47I\/1569469295:user\/release-keys","browser":{"is_browser_custom_tabs_capable":false},"android_mem_info":{"web_view_count":6,"runtime_total":106083488,"runtime_max":268435456,"runtime_free":266896},"network":{"active_network_state":5,"active_network_metered":false},"play_store":{"parental_controls":{}}},"extras":{},"format":"360x56_as","slotname":"ca-app-pub-3940256099942544\/6300978111","is_nonagon":true,"category_exclusions":[],"valid_ad_sizes":[{"height":56,"width":360,"is_fluid_height":false}],"test_request":true,"android_app_muted":false,"am":0,"dv":0,"gl":"CN","hl":"zh","js":"afma-sdk-a-v19649000.19649000.0","lv":21001,"ma":false,"ms":"CoACUwF69Y4ajkCwOSjcgaDW6RzlDS_e_6oRV34fZ5QOpnDjBQ7eCVLYk2UXxJUwY84qL1lv9PfBc2RxJ5my7ca9wZS_PWNrPYzJ5aVnmzn12JRHEiXNky5LG1Qk0R1AhRuq-VQWJLtrGtv0-aO03AuQcqfR77sIEhtcQVyZ-WElE8gjG_ovxOw_YbePjCXY5qO-alTwLNT2DqfOF-TdbQvW21c15kNL0onUhiaz3i27AIhPidvFyme4-yl5il1vA68QuOQtY7DnJP9j32i9JLxBTcxdLWz4loa_LlopKgtXbDXQ8wk1IqhDwWgzUhVGQw7EDVWdlBEdryrU3L2SgzSyLAqAAh4rJtGf6G7aUSfN1idlgpKG1jlznjcZ7rg8yNSZjalEf1Fh87c58AjHIh9q9hB9dtqrjicqYW9DFfx_qffp6lSV3N8FVq0M8Ji-SAN2oj86kqA87c6IYjJJr20GLGj8Ut1s49VBMGFrbJu55chJl5Y7L-0iMsXQnY_vsrwUqaPqk7-T5u-4ziJv43bE6ea-acDBKAZIj-Ht7iYofshTZVZu5qRppbiIAEGH8R8iBZwhsptf-sqYnBZ28FZ87z08WJ7DTEq85tboRfiia4aNJtFFH_rI9LRQLdAeFbaeTXFrEJZTDSzaaqoZyiEFgjy_Nayqsgzi93jCLjKMBgsi8nkSEHS4roPiuAK7CSUT7LUuwDc","mv":"7030.com.bbk.appstore","pn":"com.jasonjia.animalsounds","pt":1,"rm":2,"sh":1920,"sp":true,"sw":1080,"vc":2,"cnt":1,"cog":true,"coh":true,"gct":"","gnt":13,"muv":15,"riv":1,"u_sd":3,"render_in_browser":false,"rafmt":"102","custom_targeting":{},"target_api":29,"is_designed_for_families":false,"carrier":"46000","iab_consent_info":{},"extra_caps":"","android_permissions":["android.permission.INTERNET","android.permission.ACCESS_NETWORK_STATE","android.permission.WAKE_LOCK"],"is_sidewinder":false,"session_id":"6552341717999667031","quality_signals":{"ads":[{"slotid":"ca-app-pub-3940256099942544\/6300978111","tclick":[],"tfetch":-1,"pcc":0,"timp":245542694,"treq":245541856,"tload":245542687,"tresponse":245542431,"ismediation":false,"seq_num":"3"}],"app":{"basets":245473997,"currts":245612746,"preqs_in_session":3,"pclick":0,"support_transparent_background":true,"pimp":1,"preqs":3,"time_in_session":138749,"session_id":"6552341717999667031","seq_num":"4"},"slots":{}},"fc_consent":"","sdk_env":{"instant_app":false,"build_meta":{"rapid_rollup":"HEAD","cl":"278033407","rapid_rc":"dev"},"mf":false,"lite":false,"is_privileged_process":false,"container_version":12451009},"seq_num":"4","is_latchsk

D/WebView ( 2944): addJavascriptInterface=googleAdsJsInterface

D/WebView ( 2944): loadDataWithBaseURL=https://googleads.g.doubleclick.net/mads/gma?caps=inlineVideo_interactiveVideo_mraid1_mraid2_mraid3_sdkVideo_th_autoplay_mediation_scroll_av_transparentBackground_sdkAdmobApiForAds_di_sfv_dinm_dim_nav_navc_dinmo_ipdof_gls_xSeconds&eid=318483742&format=360x56_as&heap_free=266896&heap_max=268435456&heap_total=106083488&js=afma-sdk-a-v19649000.19649000.0&msid=com.jasonjia.animalsounds&preqs=3&seq_num=4&target_api=29#caps=inlineVideo_interactiveVideo_mraid1_mraid2_mraid3_sdkVideo_th_autoplay_mediation_scroll_av_transparentBackground_sdkAdmobApiForAds_di_sfv_dinm_dim_nav_navc_dinmo_ipdof_gls_xSeconds&eid=318483742&format=360x56_as&heap_free=266896&heap_max=268435456&heap_total=106083488&js=afma-sdk-a-v19649000.19649000.0&msid=com.jasonjia.animalsounds&preqs=3&seq_num=4&target_api=29



Here are my codes about ads:
private void loadAds() {
Log.d(TAG, "loadAds");
// 插屏广告
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(getString(R.string.admob_test_interstitial_adid));
interstitialAd.loadAd(getAdRequest());
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
Log.d(TAG, "onAdClosed");
interstitialAd.loadAd(getAdRequest());
}
});

// 原生广告
AdLoader adLoader = new AdLoader.Builder(this, getString(R.string.admob_test_native_adid))
.forUnifiedNativeAd(unifiedNativeAd -> {
this.unifiedNativeAd = unifiedNativeAd;
})
.build();
adLoader.loadAd(getAdRequest());
}

private AdRequest getAdRequest() {
Log.d(TAG, "getAdRequest isNonPersonalizedAds:" + isNonPersonalizedAds);
AdRequest.Builder requestBuilder = new AdRequest.Builder();
requestBuilder.addTestDevice("58F97BC11C131C8269294FD4F07E2F88");
if (isNonPersonalizedAds) { // 用户仅同意接收非个性化广告
Bundle extras = new Bundle();
extras.putString("npa", "1");
requestBuilder.addNetworkExtrasBundle(AdMobAdapter.class, extras);
}
return requestBuilder.build();
}

Here are my proguard-rules.pro
#指定压缩级别
-optimizationpasses 5

#不跳过非公共的库的类成员
-dontskipnonpubliclibraryclassmembers

#混淆时采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

#把混淆类中的方法名也混淆了
-useuniqueclassmembernames

#优化时允许访问并修改有修饰符的类和类的成员
-allowaccessmodification

#将文件来源重命名为“SourceFile”字符串
-renamesourcefileattribute SourceFile
#保留行号
-keepattributes SourceFile,LineNumberTable
#保持泛型
-keepattributes Signature

#保持所有实现 Serializable 接口的类成员
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

-keep class com.hjq.language.** {*;}
-keep,includedescriptorclasses public class com.google.android.ads.nativetemplates { *; }


#fresco
# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
-keep,allowobfuscation @interface com.facebook.soloader.DoNotOptimize

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.common.internal.DoNotStrip *;
}

# Do not strip any method/class that is annotated with @DoNotOptimize
-keep @com.facebook.soloader.DoNotOptimize class *
-keepclassmembers class * {
@com.facebook.soloader.DoNotOptimize *;
}

# Keep native methods
-keepclassmembers class * {
native <methods>;
}

-dontwarn okio.**
-dontwarn com.squareup.okhttp.**
-dontwarn okhttp3.**
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**
-dontwarn com.facebook.infer.**
#fresco end


My Device info:  vivo X6PLUS ,  Android 5.1

However, my another device can load ads successfully, even if the app is proguard.  Its device info: Nexus 6P, Android 8.1.

I am very confused!



Mobile Ads SDK Forum Advisor Prod

unread,
Feb 17, 2020, 12:11:05 AM2/17/20
to jiaxi...@gmail.com, google-adm...@googlegroups.com

Hi there,

 

Thank you for reaching out to us.

 

It seems that ProGuard is accidentally stripping AdMob classes off the final build. With that in mind, could you try adding the following to your ProGuard file?

-keep public class com.google.android.gms.ads.** {

public *;

}

 

-keep public class com.google.ads.** {

public *;

}

 

If the issue persists despite the above, could you then kindly provide the details below (via Reply privately to author) so that I can further investigate the issue?

  • Copy of your sample project (replicating the issue)
  • Steps to replicate the issue

 

Regards,

Ziv Yves Sanchez

Mobile Ads SDK Team



ref:_00D1U1174p._5001UV1DtU:ref

贾鑫

unread,
Feb 17, 2020, 1:54:05 AM2/17/20
to Google Mobile Ads SDK Developers
Thank you for your reply.
Unfortunately, It still doesn't work after I've added the configuration you said.

But,I found a package name 'com.google.android.gms.internal.ads' in my build output mapping.txt file, and then I add following to my ProGuard file, 
-keep public class com.google.android.gms.internal.ads.** {
public *;
}
It worked!The ads loaded successfully.
Is this normal?
In addition, Even if I didnt add above, it works well in my another device: nexus 6p, Android 8.1.0. Is the problem related to equipment?

Thank you again!



在 2020年2月17日星期一 UTC+8下午1:11:05,mobileadssdkforumadvisor写道:

Mobile Ads SDK Forum Advisor Prod

unread,
Feb 17, 2020, 3:59:07 AM2/17/20
to jiaxi...@gmail.com, google-adm...@googlegroups.com

Hi there,

 

Glad to hear that you've got it working!

 

For context, ProGuard aims to optimize and to reduce the file size of applications via removing unnecessary code. It will normally (and accidentally) remove a part of the AdMob SDK's code (due to said code being called only by code reflection). This is why we need to explicitly state which lines of code we want to exclude from the optimization (using the ProGuard file).

 

As for why your project works on another device: different devices will behave differently to optimization methods like ProGuard, due to different underlying architectures. Ultimately, it is still better to have more code explicitly listed inside the ProGuard file instead of having to rely on the inner workings of Android devices.

Reply all
Reply to author
Forward
0 new messages