Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGdx doesn't working after updating Gradle (Android Studio 3.0)

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
like image 941
MAGS94 Avatar asked Oct 26 '17 07:10

MAGS94


2 Answers

Android Studio 3.0 using gradle-4.1 and com.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.6

Currently html module using deprecated jetty plugin which is removed in Gradle 4.1 version.

However using Terminal you can run desktop module, I've not tested on windows but on Mac it's working fine.

./gradlew desktop:run

For now you can use lower version of Gradle and Andoid-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.3

    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    
  • Downgrade Android-gradle-plugin version from 3.0.0 to 2.3.3

    Open root build.gradle file and find artifact in buildscript and change version

    classpath 'com.android.tools.build:gradle:2.3.3'
    
  • Comment/delete google() from repo list inside root build.gradle file

--------------------------------------------------------------------------------

EDIT : Update LibGDX project to Gradle 4.6 - AS USER

  1. Upgrade Gradle to 4.6 :

    distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
    
  2. Add Google's Maven repo in project repositories list as well as in buildScript repo list in root build.gradle file.

    repositories {
        //.. 
        google()
        jcenter()         // Required for org.jetbrains.trove4j:trove4j library
    }
    
  3. Update Android Gradle Plugin :

    classpath 'com.android.tools.build:gradle:3.1.3'

    Known issues with the Android Gradle Plugin

    Configuration on demand with Gradle 4.6 and above:

    If you're using Android Gradle Plugin 3.0.x or 3.1.x with Gradle 4.6 and above, you should disable configuration on demand to avoid some unpredictable build errors. (If you are using Android Gradle Plugin 3.2.0 or higher, you do not need to take any action to disable configuration on demand.)

    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.

  4. Update Android buildToolsVersion to 27.0.3 and SdkVersion to 27

  5. Remove instrumentTest.setRoot('tests') from sourceSets inside android build.gradle file
  6. replace all compile with implementation inside root build.gradle file
  7. New GWT Gradle Plugin added in html module, check latest build.gradle of html module.

Run your project with Run Configuration or On Terminal using gradle task.


If you're going to create new project use gdx-setup.jar of latest build.

like image 62
Abhishek Aryan Avatar answered Oct 14 '22 00:10

Abhishek Aryan


I temporarily solve this by forcing plugin to use 2.3.3 and gradle wrapper properties file reverted to 3.3

distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

and build.gradle

dependencies {
   classpath 'com.android.tools.build:gradle:2.3.3'
}

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!

like image 25
Jason Chong Avatar answered Oct 13 '22 23:10

Jason Chong