For Unity 6000+
Problem Description
If you're developing an Android app using Native Media Player and encounter a java.lang.NoClassDefFoundError at runtime (especially on Unity 6.x), it's likely caused by one of the following:
The wrong version of the plugin is being used (
media2instead ofmedia3)Your project has overridden the plugin’s custom
mainTemplate.gradle, causing required dependencies to be excluded
What You Might See
Typical crash logs may look like this:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/exoplayer2/ui/PlayerNotificationManager$NotificationListener;Or:
java.lang.NullPointerException
at com.glitch9.media2ext.Media2.createController(...)Root Cause
There are two common reasons for this crash:
1. Wrong Plugin Version Imported
Unity Asset Store delivers different plugin versions depending on the Unity version used to download the asset.
If the plugin was downloaded using a Unity version below 6000, it will import the legacy
media2version.If you later upgrade the project to Unity 6.x, that old version may still remain — causing incompatibility and missing class errors.
2. Plugin’s mainTemplate.gradle Was Overridden
Native Media Player uses a custom
mainTemplate.gradleto include all required Android dependencies (e.g. ExoPlayer).It does not use EDMU (External Dependency Manager for Unity).
If your project or another third-party plugin (e.g. Firebase Messaging) replaces or modifies the
mainTemplate.gradle, the required ExoPlayer dependencies may be removed, leading to runtime crashes.
✅ Solution
Step 1: Re-download the Plugin Using Unity 6.x
To ensure you get the correct Unity 6.x-compatible version:
Open your project using Unity 6.1.3f or higher
Re-download and re-import Native Media Player from the Unity Asset Store or Package Manager
This will fetch the correct
media3version of the plugin
⚠️ If you downloaded the asset using an older Unity version, Unity may have imported the legacy version — even if your project is now using Unity 6.x.
Step 2: Verify the Correct .aar is Used
The plugin uses a pre-build script (UnityPluginFilter.cs) to automatically select the correct .aar file:
if (NMPConfig.IsUnity6)
{
SetCompatible("com.glitch9.media3.aar", true);
SetCompatible("com.glitch9.media2.aar", false);
}
else
{
SetCompatible("com.glitch9.media2.aar", true);
SetCompatible("com.glitch9.media3.aar", false);
}Make sure this script exists and has not been removed or overridden.
Step 3: Preserve the Plugin’s mainTemplate.gradle
If your project uses a custom mainTemplate.gradle, ensure it includes the necessary dependency blocks from Native Media Player.
⚠️ Common third-party plugins like Firebase Messaging can override or replace
mainTemplate.gradle, wiping out the plugin’s required dependencies.
If you're unsure, compare your current mainTemplate.gradle with the one provided by the plugin and merge them carefully.
Step 4: Clean & Rebuild
Delete
Library/,Build/, andTemp/folders (optional, but helps prevent caching issues)Rebuild the project
Deploy to an Android device and verify the crash is resolved
✅ Summary
Plugin downloaded using Unity 6?
✅ Required
media3.aar selected correctly?
✅ Required
mainTemplate.gradle intact?
✅ Required
EDMU installed?
❌ Not needed
Last updated