13

I am working on a Libgdx project that uses the Universal Tween Engine. I have followed all of the steps on this page: https://github.com/libgdx/libgdx/wiki/Universal-Tween-Engine to install the Universal Tween Engine library into my project.

After completing all of these steps the project will build and run fine (both Android and Desktop) on my laptop PC, and the animations coming from the tween engine work perfectly.

However on my desktop computer whenever I try to run the desktop application it crashes with NoClassDefFoundException being thrown on the TweenAccessor class which is part of the Universal Tween Engine. The application compiles correctly and I can ctrl-click on the Class that it is saying it cant find and it opens up the source code of that class so I know at least some part of the IDE is finding this class. There is no red underline errors on any of the Library classes in the source code editor. Interestingly on my desktop computer I can run the android application and it does not crash, and the animations work perfectly. Only the Desktop version will not work.

In trying to troubleshoot this I've run accross many things that say to switch to 'Project' view find the jar files, right click them and choose Add as a Library I've had to do this in the past on other projects and it did indeed work for me.

But my problem is the Add as a Library option is missing from the context menu when I right click it on my desktop PC:

enter image description here

I've tried cleaning the project. I even completely uninstall Android Studio and downloaded a new copy and Installed it. Still get the same results after doing this.

What determines whether or not the "Add as a Library" option will show up in the context menu when right clicking on a jar file?

What do I have to do on my desktop PC to get it to properly use the Universal Tween Engine library jar?

EDIT: Relevant sections of gradle.build.

project(":desktop") {
    apply plugin: "java"
    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        compile fileTree(dir: '../libs', include: '*.jar') // This one is not listed but I added anyway
    }
}
//...
project(":android") {
    apply plugin: "android"
    configurations { natives }
    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        compile fileTree(dir: '../libs', include: '*.jar')
    }
}
//...
project(":core") {
    apply plugin: "java"
    dependencies {
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile fileTree(dir: '../libs', include: '*.jar')
    }
}

My Project Structure

project_root_dir/
    android/
    core/
    desktop/
    html/
    ios/
    libs/
        tween-engine-api.jar
        tween-engine-api-sources.jar
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • 2
    What does your build.gradle file look like for the app? Does it have a line similar to `compile fileTree(dir: 'libs', include: ['*.jar'])`? You can also add dependencies through Project Structure (File -> Project Structure, click on your module, click on the Dependencies tab, click on the plus sign -> File dependency) – Vinay Dandekar Dec 20 '15 at 00:12
  • 1
    @VinayDandekar I've added the relavent bits of my gradle.build file. Yes they include those lines. When I look on project structure and dependencies tab both jar files are already listed under `core` and `android` modules. But not listed under desktop. If I try to add them to desktop module I can't because it is having me browse only under the Desktop directory, but they are up one level inside of libs directory that is in project root. – FoamyGuy Dec 20 '15 at 16:31
  • 1
    You are already including all jars in the /libs/ folder. You don't need to add it, because it is already added. `compile fileTree(dir: '../libs', include: '*.jar')` – Knossos Dec 22 '15 at 18:46

4 Answers4

4

I would just add as dependency just this line:

compile files('../libs/tween-engine-api.jar')

That line above should replace this line:

compile fileTree(dir: '../libs', include: '*.jar')

I could imagine that the source code file is breaking something. In general I would avoid to import multiple jars at once, I would always select them by hand.


As an alternative idea did you try the points 6 and 7 from the readme file?

Adding this in your dependency section:

compile "aurelienribon:tweenengine:6.3.3"
compile "aurelienribon:tweenengine:6.3.3:sources"

And add this two maven repositoried to your build.gradle file in the project root:

maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
rekire
  • 47,260
  • 30
  • 167
  • 264
  • I did at one point try targeting the jar files by name like you suggest and that did not solve the problem. But even though it wasn't the issue in this case I do intend to do this way. – FoamyGuy Dec 26 '15 at 03:51
1

I was facing the same problem... i solved it like that: Just add the tween.jar files under libs folder under Project and add this to the build.gradle

project(":core") {
    apply plugin: "java"


    dependencies {
        compile fileTree(dir: '../libs', include: 'tween-engine-api*.jar')
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
        compile "de.tomgrill.gdxfacebook:gdx-facebook-core:1.1.1"
        compile "de.tomgrill.gdxdialogs:gdx-dialogs-core:1.0.0"
        compile "net.dermetfan.libgdx-utils:libgdx-utils-box2d:0.13.2"
        compile "net.dermetfan.libgdx-utils:libgdx-utils:0.13.2"
        compile "org.robovm:robopods-google-mobile-ads-ios:1.6.0"
        compile "org.robovm:robopods-google-analytics-ios:1.6.0"
    }
}
laymelek
  • 418
  • 2
  • 15
  • are you positively sure that you have exactly the same versions of android studio in both computers? – laymelek Dec 21 '15 at 21:19
  • Originally both computers had the same version of Android Studio (which was 1.5) I completely uninstalled AS and downloaded the newest version on my desktop so it now has 1.5.1 and my laptop still has only 1.5. They were both on the same version before I did the uninstall/re-install on my desktop though and was not working on desktop, but was working on laptop. – FoamyGuy Dec 21 '15 at 22:47
1

If you really want to see the "Add as Library" option. Update your android dependencies in build.gradle as follows (by removing '.jar').

project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
    compile project(":core")
    compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
    natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
    compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
    natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
    natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
    natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
    compile fileTree(dir: '../libs', include: '') //removed '*.jar'
}

}

OR ,Otherwise you can add your library without editing your dependencies by

File->Project Structure->Dependencies-> Add->File dependency

SachinS
  • 2,223
  • 1
  • 15
  • 25
  • I have solved the problem, I will post what I had to do soon. I did just try changing the dependency line like yours `compile fileTree(dir: '../libs', include: '')` just now and I still do not have the Add as a Library option. I let it sync gradle, and tried restarting AS and still no 'Add as Library` option present in the context menu. – FoamyGuy Dec 26 '15 at 03:50
  • I did also try using `File->Project Structure->Dependencies-> Add->File dependency`. The thing about that one is it seems to be locked to inside the module directory, it wouldn't let me go up a level which is how the project is structured. I did try putting a copy of the libs folder inside the modules though and adding it in this menu and that did not fix my problem. To solve it I actually had to open up this menu and remove the 2 entries that were in there. – FoamyGuy Dec 26 '15 at 03:54
  • Try replacing all 'compile fileTree(dir: '../libs', include: ''*.jar") ' with 'compile fileTree(dir: '../libs', include: '"') .This solved the issue on my androidStudio.I hope this will work for you. – SachinS Dec 26 '15 at 05:34
0

You can try this one. Universal tween engine in maven repo.

https://stackoverflow.com/a/41426725/3445320

Community
  • 1
  • 1
Abhishek Aryan
  • 19,936
  • 8
  • 46
  • 65