You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Admob欧盟同意授权调用loadForm加载表单时内部测试触发崩溃求助

Admob GDPR用户同意表单内部测试崩溃问题

问题描述

  • 需展示GDPR欧盟用户同意授权表单,通过内部应用测试渠道测试时功能无法正常运行,还会触发崩溃
  • 提问者为Admob新手,已在后台新的隐私与消息选项完成配置,配置页截图如下:
    Admob隐私配置页截图

相关代码

public class HomeFragment extends BaseFragment implements MyAdapter.NoteListener, PurchasesUpdatedListener {

    private ConsentInformation consentInformation;
    private ConsentForm consentForm;

    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_home, container, false);
        getConsentStatus();
        return root;
    }  
    
    public void getConsentStatus(){
        ConsentRequestParameters params = new ConsentRequestParameters
                .Builder()
                .setTagForUnderAgeOfConsent(false)
                .build();
        consentInformation= UserMessagingPlatform.getConsentInformation(requireActivity());
        consentInformation.requestConsentInfoUpdate(requireActivity(), params,
                new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
                    @Override
                    public void onConsentInfoUpdateSuccess() {
                        if(consentInformation.isConsentFormAvailable()){
                            try {
                                loadForm();
                            }catch (Exception e){debugToast(e.getMessage());}
                        }
                    }
                }, new ConsentInformation.OnConsentInfoUpdateFailureListener() {
                    @Override
                    public void onConsentInfoUpdateFailure(@NonNull FormError formError) {
                    }
                });
    }
    
    public void loadForm(){
        UserMessagingPlatform.loadConsentForm(
                requireActivity(),
                new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
                    @Override
                    public void onConsentFormLoadSuccess(@NonNull ConsentForm consentForm) {
                        HomeFragment.this.consentForm=consentForm;
                        if(consentInformation.getConsentStatus()==ConsentInformation.ConsentStatus.REQUIRED){
                            consentForm.show(requireActivity(), new ConsentForm.OnConsentFormDismissedListener() {
                                @Override
                                public void onConsentFormDismissed(FormError formError) {
                                    try {
                                        loadForm();
                                    }catch (Exception e){debugToast(e.getMessage());}
                                }
                            });
                        }
                    }
                }, new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
                    @Override
                    public void onConsentFormLoadFailure(@NonNull FormError formError) {
                        try {
                            loadForm();
                        }catch (Exception e){debugToast(e.getMessage());}
                    }
                });
    }
}

崩溃日志

Fatal Exception: java.lang.VerifyError
Verifier rejected class com.navlab.recical.ui.home.HomeFragment: void com.navlab.recical.ui.home.HomeFragment.h1() failed to verify: void com.navlab.recical.ui.home.HomeFragment.h1(): [0x48] cannot access instance field c.c.b.b.e.d.z c.c.b.b.e.d.h.b from object of type Reference: java.lang.Object (declaration of 'com.navlab.recical.ui.home.HomeFragment' appears in /data/app/~~Hq2ou3cL8pLh7LMvC_brXA==/com.navlab.recical-OCMZc1E9XqZrpjokxu49Jg==/base.apk)


解决方案
  1. 修复混淆规则:该报错为类验证错误,从日志里的混淆短类名可判断是UMP SDK相关类被错误混淆导致。将以下规则添加到你的proguard-rules.pro文件:
# 保留UMP同意SDK所有类
-keep class com.google.android.ump.** { *; }
-keep interface com.google.android.ump.** { *; }
# 保留Admob相关类避免兼容问题
-keep class com.google.android.gms.ads.** { *; }
  1. 检查SDK版本兼容性:确保你使用的User Messaging Platform SDK和Admob SDK为官方推荐的配套版本,不要跨大版本混用,也不要使用已废弃的beta版UMP SDK。
  2. 修复递归加载逻辑:现有代码中表单加载失败、表单关闭都会直接调用loadForm(),无重试次数限制,容易触发栈溢出。添加最大重试次数限制,仅在授权状态仍为REQUIRED时才重试加载。
  3. 调整调用时机:不要在onCreateView中直接调用授权请求,改为在onViewCreated生命周期中触发,避免Fragment未完全依附到Activity时调用requireActivity()出现上下文异常。
  4. 本地调试优化:本地调试时可配置测试设备ID,强制触发GDPR表单展示,无需上传到内部测试渠道即可复现验证问题。

内容的提问来源于stack exchange,提问作者judy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 08:36:03