Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accepting Android SDK Licences on MacOS with OpenJDK 11

I have just installed Android Studio and imported a project. However, I am unable to build the project because I apparently have not proved my devotion to the Almighty Google accepted the relevant licenses.

> Failed to install the following Android SDK packages as some licences have not been accepted.
     build-tools;28.0.3 Android SDK Build-Tools 28.0.3
     platforms;android-28 Android SDK Platform 28

After some praying to the the all knowing google searches I found that a shell script sdkmanager was installed in an unrelated location and must be run to accept the licenses. Having overcome the initial test of faith problem, I ran the script and encountered the following error.

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
    at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
    at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
    at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)
    at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 5 mor

I found a number of people with the same problem online.

The most popular solution, from this question, suggests finding a particular line in the sdkmanager shell script and adding -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee. This results in the following error.

Error occurred during initialization of boot layer
java.lang.module.FindException: Module java.se.ee not found

After more searches and reading other answers it appears that the above change does not work for more recent versions of Java. Another answer, here, suggests the following.

  1. Manually modify the sdkmanager script
  2. Downgrade to an older version of Java compatible with the modificatiosn made in step 1
  3. Run the shell script and accept the licenses
  4. Upgrade back to the current version of Java
  5. Finally compile the project

This seems like a little bit of overkill just to be able to compile an Android app on my Mac, but I'm willing to try. However I am unable to download Java 8 from the provided link as it requires an oracle account and I am unable to create one...

Does anyone know of a less complicated way to set up and compile an Android Studio project for the first time on Mac with Java 11 in 2019?

like image 669
Increasingly Idiotic Avatar asked Dec 17 '22 15:12

Increasingly Idiotic


1 Answers

I ran into the same issue. Looks like you're using an outdated license accepting script which depends on OpenJDK 8, probably located at ~/Android/Sdk/tools/bin/sdkmanager if you're using linux like me.

A better alternative to switching Java versions (imo) is installing the new android studio command line tools through android studio. Go to search -> sdk manager -> sdk tools and the Android SDK Command-line Tools (latest) option should not be ticked (in my screenshot it is though).

enter image description here

Tick it, hit apply and android studio will walk you through installing the new cli tools in ~/Android/Sdk/cmdline-tools/.

Now simply ~/Android/Sdk/cmdline-tools/latest/bin/sdkmanager --licenses.

like image 116
Louka Ewington-Pitsos Avatar answered Dec 20 '22 05:12

Louka Ewington-Pitsos