I have recently updated android studio and gradle to the version 3.0.0 following instructions in this link https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
After doing this libgdx desktop project doesn't work.
It give me this error
java.lang.NoClassDefFoundError: com/badlogic/gdx/ApplicationListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
Here is build.gradle file
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
I only added google()
to repositories and edit gradle version to 3.0.0
In gradle-wrapper.properties
I added this line
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
worked with windows , in terminal you can go to the project folder and run desktop module using command .
Android Studio
3.0
usinggradle-4.1
andcom.android.tools.build:gradle:3.0.0
Gradle 4.1
is not supported yet in LibGDX, there is an issue for the same, which is now upgraded for Gradle 4.6Currently html module using deprecated
jetty
plugin which is removed inGradle 4.1
version.However using Terminal you can run desktop module, I've not tested on windows but on Mac it's working fine.
For now you can use lower version of
Gradle
andAndoid-gradle-plugin
in Android Studio 3.0 and wait for issue to be fixed.Downgrade Gradle version from 4.1 to 3.3
Find gradle folder inside your project, Open
gradle-wrapper.properties
and change distributionUrl for 3.3Downgrade Android-gradle-plugin version from 3.0.0 to 2.3.3
Open root
build.gradle
file and find artifact in buildscript and change versionComment/delete
google()
from repo list inside rootbuild.gradle
file--------------------------------------------------------------------------------
EDIT : Update LibGDX project to Gradle 4.6 - AS USER
Upgrade Gradle to 4.6 :
Add Google's Maven repo in project repositories list as well as in buildScript repo list in root
build.gradle
file.Update Android Gradle Plugin :
classpath 'com.android.tools.build:gradle:3.1.3'
Known issues with the Android Gradle Plugin
Disable configuration on demand in your
gradle.properties
file as shown below:org.gradle.configureondemand=false
To disable configuration on demand in the Android Studio settings, choose File > Settings (Android Studio > Preferences on Mac), select the Compiler category in the left pane, and clear the Configure on demand checkbox.
In Android Studio 3.2 Beta 1 and higher, the options for enabling configuration on demand have been removed.
Update Android buildToolsVersion to
27.0.3
and SdkVersion to27
instrumentTest.setRoot('tests')
fromsourceSets
inside androidbuild.gradle
filecompile
withimplementation
inside rootbuild.gradle
fileGWT Gradle Plugin
added in html module, check latest build.gradle of html module.Run your project with
Run Configuration
or On Terminal usinggradle task
.If you're going to create new project use
gdx-setup.jar
of latest build.Edit configurations -> Desktop -> In before launch change "Build" to "Build project". (use the + and - buttons).
I temporarily solve this by forcing plugin to use 2.3.3 and gradle wrapper properties file reverted to 3.3
and build.gradle
comment out the google() from repositories and tell android studio 3.0 to stop reminding you to upgrade gradle plugin to 3.0.0 for your current project.
Edit: To the person above who plagiarised my answer, shame on you!