MFlisar / GDPRDialog

GDPR fragment dialog implementation
Apache License 2.0
211 stars 53 forks source link

Cannot open dialog because of BootstrapMethodError #86

Closed KeizerDev closed 5 years ago

KeizerDev commented 5 years ago

I have a feeling it has to be something with the view inflater, I tried to change the GDPR.getInstance().checkIfNeedsToBeShown(this, mSetup); part to GDPR.getInstance().checkIfNeedsToBeShown(SplashActivity.this, mSetup); and similar ways but it still doesn't work.

Here is my stacktrace:

    java.lang.BootstrapMethodError: Exception from call site #1 bootstrap method
        at com.michaelflisar.gdprdialog.GDPRDialog.initView(GDPRDialog.java:150)
        at com.michaelflisar.gdprdialog.GDPRDialog.onCreateView(GDPRDialog.java:73)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460)
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802)
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273)
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229)
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620)
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178)
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1470)
        at android.app.Activity.performStart(Activity.java:7170)
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3061)
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180)
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165)
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:6863)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
     Caused by: java.lang.ClassCastException: Bootstrap method returned null
        at com.michaelflisar.gdprdialog.GDPRDialog.initView(GDPRDialog.java:150) 
        at com.michaelflisar.gdprdialog.GDPRDialog.onCreateView(GDPRDialog.java:73) 
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2439) 
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1460) 
        at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784) 
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852) 
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:802) 
        at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625) 
        at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411) 
        at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366) 
        at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273) 
        at androidx.fragment.app.FragmentManagerImpl.dispatchStateChange(FragmentManager.java:3273) 
        at androidx.fragment.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:3229) 
        at androidx.fragment.app.FragmentController.dispatchActivityCreated(FragmentController.java:201) 
        at androidx.fragment.app.FragmentActivity.onStart(FragmentActivity.java:620) 
        at androidx.appcompat.app.AppCompatActivity.onStart(AppCompatActivity.java:178) 
        at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1470) 
        at android.app.Activity.performStart(Activity.java:7170) 
        at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3061) 
        at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:180) 
        at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:165) 
        at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:142) 
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1906) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:193) 
        at android.app.ActivityThread.main(ActivityThread.java:6863) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 

I have registered the dialog in my Application class like this:

        GDPR.getInstance()
                .init(this)
                .initLogger(new GDPR.ILogger() {
                    @Override
                    public void debug(String tag, String msg) {
                        Log.d(String.format("GDPRDemo [%s]", tag), msg);
                    }

                    @Override
                    public void error(String tag, String msg, Throwable tr) {
                        Log.e(String.format("GDPRDemo [%s]", tag), msg, tr);
                    }
                });

I open my SplashActivity as first activity and it crashes instantly, my code looks like this

public class SplashActivity extends AppCompatActivity implements GDPR.IGDPRCallback {
    private GDPRSetup mSetup = new GDPRSetup(GDPRDefinitions.ADMOB, GDPRDefinitions.INMOBI);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        GDPR.getInstance().checkIfNeedsToBeShown(this, mSetup);
    }

    @Override
    public void onConsentNeedsToBeRequested(GDPRPreperationData data) {
        GDPR.getInstance().showDialog(this, mSetup, data.getLocation());
    }

    @Override
    public void onConsentInfoUpdate(GDPRConsentState consentState, boolean isNewState) {

    }
}

I use androidx with the following settings in my gradle.properties:

android.useAndroidX=true
android.enableJetifier=true

I use version 1.4.1 of your library and I am compiling my app using Android version 29

MFlisar commented 5 years ago

Try add following to your project:

https://github.com/MFlisar/GDPRDialog/blob/34461030fa4bbade943973c17d2632997a7c4c00/app/build.gradle#L15-L18

Does this help?

KeizerDev commented 5 years ago

It is randomly fixed, I don't know how exactly. I had:

    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

Already in my build.gradle. After your comment I just added that and uncomment everything again to test and it was working, the only thing I actually did before and after the uncomment is changed the java language version in my Android Studio to support lambda's. I tried the version from your build.gradle and mine but they work both now. Thanks anyways for your help!