[Bug] Next-Gen SDK: java.lang.Error crash on InterstitialAd.load() in production (Android)
### [REQUIRED] Step 1: Describe your environment
* Unity version: Unity 6.3
* Google Mobile Ads Unity plugin version: v11.1.0 & v11.2.0
* Plugin installation method: .unitypackage import (with External Dependency Manager)
* Platform: Android
* Platform OS version: Multiple Android versions (Live Production Issue)
* Any specific devices issue occurs on: Various Android devices
* Mediation ad networks used, and their versions: None
### [REQUIRED] Step 2: Describe the problem
#### Steps to reproduce:
I am experiencing a critical production crash when attempting to load an Interstitial Ad using the new **Next-Gen Android SDK**. The crash originates deep within the native Android SDK (`ads_mobile_sdk.ie1.a` and `ads_mobile_sdk.jg1.a`, depending on R8 obfuscation) during the `UnityInterstitialAd.lambda$load$0` execution.
Reverting the AdMob settings back to the "Standard" SDK completely resolves the issue. Updating from GMA v11.1.0 to v11.2.0 did **not** resolve the issue, confirming this is an ongoing native bug in the Next-Gen architecture.
1. Import Google Mobile Ads Unity Plugin v11.2.0.
2. Enable the **Next-Gen** Android SDK in `Assets > Google Mobile Ads > Settings`.
3. Force Resolve Android dependencies.
4. Call `InterstitialAd.Load()` from the Unity C# script.
5. Observe the fatal `java.lang.Error` crash on the Android UI thread.
#### Relevant Code:
```csharp
public void Initialize()
{
// Note: Ensuring ad events run on the main thread does NOT prevent this crash,
// as the crash occurs synchronously during the JNI load invocation, not during an async callback.
MobileAds.RaiseAdEventsOnUnityMainThread = true;
MobileAds.Initialize(initStatus => LoadInterstitial());
}
private void LoadInterstitial()
{
string adUnitId = "ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx";
AdRequest request = new AdRequest();
// The crash triggers the moment this Load method is invoked.
InterstitialAd.Load(adUnitId, request, (InterstitialAd ad, LoadAdError error) =>
{
if (error != null || ad == null) return;
// Code never reaches here.
});
}
```
#### Crash Logs (from Play Console):
*Stack Trace (v11.2.0 / jg1.a obfuscation):*
```text
Exception java.lang.Error:
at ads_mobile_sdk.jg1.a (SourceFile:138)
at com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAd$Companion.load (SourceFile:13)
at com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAd.load (Unknown Source:2)
at com.google.unity.ads.nextgen.AdWrapper.load (AdWrapper.java:32)
at com.google.unity.ads.nextgen.UnityInterstitialAd.lambda$load$0 (UnityInterstitialAd.java:58)
at android.os.Handler.handleCallback (Handler.java:958)
at android.os.Handler.dispatchMessage (Handler.java:99)
at android.os.Looper.loopOnce (Looper.java:222)
at android.os.Looper.loop (Looper.java:314)
at android.app.ActivityThread.main (ActivityThread.java:8671)
at java.lang.reflect.Method.invoke
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:565)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1081)
```
---
### 🔍 Deep Technical Analysis & Execution Path
To assist the engineering team, here is a breakdown of the architectural failure point based on the stack trace:
**1. The JNI Handoff is Successful**
The C# command successfully crosses the JNI boundary. The native Java wrapper receives it at `com.google.unity.ads.nextgen.AdWrapper.load (AdWrapper.java:32)` and delegates it to a lambda function at `UnityInterstitialAd.lambda$load$0`.
**2. Synchronous UI Thread Crash**
Looking at the bottom of the stack trace (`ActivityThread.main` -> `Looper.loop` -> `Handler.dispatchMessage`), this code is being executed synchronously on the core **Android UI Thread**, not a background worker thread.
Because this is a synchronous failure on the native UI thread, Unity's `MobileAds.RaiseAdEventsOnUnityMainThread = true` configuration cannot catch or mitigate it. The crash happens *before* the SDK can ever generate an async callback.
**3. The Point of Failure: Kotlin Lazy Initialization**
The exact failure occurs at:
```text
at kotlin.SynchronizedLazyImpl.getValue (LazyJVM.kt:74)
at ads_mobile_sdk.jg1.a (SourceFile:138)
```
When `InterstitialAd.load` is called, the obfuscated internal Next-Gen library attempts to instantiate a required object using a Kotlin `SynchronizedLazyImpl`. This lazy initialization fails catastrophically, throwing a `java.lang.Error` (not an `Exception`).
Because it throws an `Error`, it bypasses standard exception handling and instantly terminates the application. This indicates a severe internal state issue, missing dependency, or memory fault directly inside the compiled Next-Gen AAR files.
1 条评论