Cannot build with admob plugin: Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

We deleted out all of the old Google Admob files and installed the latest Google AdMob Plugin:


We followed the documentation and including executing Assets > External Dependency Manager > Android Resolver > Resolve but we will get the bellow error when building the APK.

How do we resolve?

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

I just installed AdMob and was getting the same exception (from sdkmanager.bat). It appears to be because Unity is using a different version of the Java SDK than what it should be.

If you look in Unity\2020.1.14f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK ools\bin\sdkmanager.bat (using the Android SDK path from Edit | Preferences | External Tools), the script tries to find the SDK by looking at the JAVA_HOME environment variable first, and if that doesn’t exist, it tries to find it from java.exe. In my case, I had some random Java.exe in the PATH, and Unity was using this instead of the SDK specified in the preferences.

So you have 2 reasonable options:

  1. Set a JAVA_HOME system environment variable to Unity’s Android SDK.
  2. Put Unity’s Android SDK in the PATH earlier than other Javas.

Or you can do what I did:
3. Add the following line to the top of sdkmanager.bat

set JAVA_HOME=%~dp0..\..\..\OpenJDK