googleads / googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
https://developers.google.com/admob/unity
Apache License 2.0
1.34k stars 1.08k forks source link

Error: java.lang.ClassNotFoundException: com.google.unity.ads.UnityApplicationPreferences #3194

Closed micsnz closed 3 months ago

micsnz commented 3 months ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

I am trying to read the user consent choice by following this guide. However, running that code results in this error: Error Unity Cannot get an ApplicationPreferences instance: java.lang.ClassNotFoundException: com.google.unity.ads.UnityApplicationPreferences

I tried adding this rule to proguard and expected the error to go away, but it still appears. -keep class com.google.unity.ads.** { *; }

Steps to reproduce:

After the user is done with the consent flow, I run the code mentioned here.

Relevant Code:

// Example value: "1111111111"
  string purposeConsents = ApplicationPreferences.GetString("IABTCF_PurposeConsents");
  // Purposes are zero-indexed. Index 0 contains information about Purpose 1.
  if (!string.IsNullOrEmpty(purposeConsents))
  {
    char purposeOneString = purposeConsents[0];
    bool hasConsentForPurposeOne = purposeOneString == '1';
  }
NVentimiglia commented 3 months ago

I was unable to verify this behaviour. Using ApplicationPreferences worked for me on Android.

I recommend reinstalling the plugin and making sure gradle dependencies are resolved.