【发布时间】:2015-12-18 15:00:39
【问题描述】:
我正在开发一个使用通用补间引擎的 Libgdx 项目。我已按照此页面上的所有步骤操作:https://github.com/libgdx/libgdx/wiki/Universal-Tween-Engine 将 Universal Tween Engine 库安装到我的项目中。
完成所有这些步骤后,项目将在我的笔记本电脑上构建和运行(Android 和桌面),并且来自补间引擎的动画完美运行。
但是,在我的台式计算机上,每当我尝试运行桌面应用程序时,它都会崩溃,并在 TweenAccessor 类上引发 NoClassDefFoundException,该类是通用补间引擎的一部分。应用程序编译正确,我可以按住 ctrl 单击它说它找不到的类,它会打开该类的源代码,所以我知道至少 IDE 的某些部分正在找到这个类。源代码编辑器中的任何库类都没有红色下划线错误。有趣的是,在我的台式计算机上,我可以运行 android 应用程序并且它不会崩溃,并且动画效果很好。只有桌面版本不起作用。
在尝试解决这个问题时,我遇到了很多事情,说要切换到“项目”视图,找到 jar 文件,右键单击它们并选择 Add as a Library 我过去在其他项目中必须这样做它确实对我有用。
但我的问题是,当我在桌面 PC 上右键单击上下文菜单时,上下文菜单中缺少 Add as a Library 选项:
我已尝试清理项目。我什至完全卸载了 Android Studio 并下载了一个新副本并安装了它。这样做后仍然得到相同的结果。
在右键单击 jar 文件时,是什么决定了“添加为库”选项是否会显示在上下文菜单中?
我必须在我的台式电脑上做什么才能正确使用通用补间引擎库 jar?
编辑: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')
}
}
我的项目结构
project_root_dir/
android/
core/
desktop/
html/
ios/
libs/
tween-engine-api.jar
tween-engine-api-sources.jar
【问题讨论】:
-
应用程序的 build.gradle 文件是什么样的?它是否有类似于
compile fileTree(dir: 'libs', include: ['*.jar'])的行?也可以通过项目结构添加依赖(文件->项目结构,点击你的模块,点击依赖选项卡,点击加号->文件依赖) -
@VinayDandekar 我已经添加了我的 gradle.build 文件的相关位。是的,它们包括这些行。当我查看项目结构和依赖项选项卡时,两个 jar 文件都已列在
core和android模块下。但未在桌面下列出。如果我尝试将它们添加到桌面模块,我不能,因为它让我只能在桌面目录下浏览,但它们在项目根目录中的 libs 目录内上一级。 -
您已经在 /libs/ 文件夹中包含所有 jars。您不需要添加它,因为它已经添加了。
compile fileTree(dir: '../libs', include: '*.jar')
标签: android android-studio module libgdx