Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio 'Add as Library' missing For Universal Tween Engine on Libgdx

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
like image 625
FoamyGuy Avatar asked Dec 18 '15 15:12

FoamyGuy


1 Answers

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/" }
like image 123
rekire Avatar answered Oct 15 '22 06:10

rekire