Libgdx 上的通用补间引擎缺少 Android Studio 'Add as Library'

标签 android android-studio module libgdx

我正在开发一个使用通用补间引擎的 Libgdx 项目。我已遵循此页面上的所有步骤:https://github.com/libgdx/libgdx/wiki/Universal-Tween-Engine将 Universal Tween Engine 库安装到我的项目中。

完成所有这些步骤后,该项目将在我的笔记本电脑上正常构建和运行(Android 和桌面),并且来自补间引擎的动画完美运行。

但是,在我的台式计算机上,每当我尝试运行桌面应用程序时,它都会崩溃,并在作为通用补间引擎一部分的 TweenAccessor 类上抛出 NoClassDefFoundException。应用程序编译正确,我可以按住 Ctrl 键并单击它说找不到的类,它会打开该类的源代码,因此我知道至少 IDE 的某些部分正在查找该类。源代码编辑器中的任何库类都没有红色下划线错误。有趣的是,在我的台式电脑上,我可以运行 android 应用程序,它不会崩溃,而且动画效果很好。只有桌面版无法使用。

在尝试解决此问题时,我遇到了很多事情,说要切换到“项目” View 找到 jar 文件,右键单击它们并选择 Add as a Library 我不得不这样做过去在其他项目上这样做,它确实对我有用。

但我的问题是,当我在桌面 PC 上右键单击它时,上下文菜单中缺少 Add as a Library 选项:

enter image description here

我试过清理项目。我什至完全卸载了 Android Studio 并下载了一个新副本并安装了它。这样做后仍然得到相同的结果。

当右键单击 jar 文件时,是什么决定了“添加为库”选项是否会显示在上下文菜单中?

我必须在台式 PC 上做什么才能正确使用通用 Tween 引擎库 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

最佳答案

我只想添加这一行作为依赖:

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

上面那行应该替换这一行:

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

我可以想象源代码文件破坏了某些东西。一般来说,我会避免一次导入多个 jar,我总是手动选择它们。


作为替代方案,您是否尝试了 readme file 中的第 6 点和第 7 点? ?

在你的依赖部分添加这个:

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

并将这两个 maven 存储库添加到项目根目录中的 build.gradle 文件中:

maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }

关于Libgdx 上的通用补间引擎缺少 Android Studio 'Add as Library',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34358431/

相关文章:

android - 使用 FFmpeg Android 错误更改音频音量

android - 无法在 GridView 上显示图像

android - Android OpenCV安装

android - 在Android中创建图像类型TextView

java - 未知类 : 'button' & invalid method decleration; return type required for findViewById

linux - 正确导出 Linux 头文件、模块

java - 改变方向 Android 设备

android-studio - Kotlin Multiplatform Mobile 找不到 klib 包

javascript - Mongoose:将 find() 结果移动到文件中的数组

javascript - Angular : How to create internal utils but do not export with module