【问题标题】:Android Studio 'Add as Library' missing For Universal Tween Engine on LibgdxLibgdx 上的通用补间引擎缺少 Android Studio“添加为库”
【发布时间】: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 文件都已列在 coreandroid 模块下。但未在桌面下列出。如果我尝试将它们添加到桌面模块,我不能,因为它让我只能在桌面目录下浏览,但它们在项目根目录中的 libs 目录内上一级。
  • 您已经在 /libs/ 文件夹中包含所有 jars。您不需要添加它,因为它已经添加了。 compile fileTree(dir: '../libs', include: '*.jar')

标签: android android-studio module libgdx


【解决方案1】:

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

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/" }

【讨论】:

  • 我曾尝试按照您的建议按名称定位 jar 文件,但这并没有解决问题。但即使在这种情况下这不是问题,我也打算这样做。
【解决方案2】:

我遇到了同样的问题...我是这样解决的:只需在 Project 下的 libs 文件夹下添加 tween.jar 文件并将其添加到 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"
    }
}

【讨论】:

  • 您确定两台计算机上的 android studio 版本完全相同吗?
  • 最初两台电脑的 Android Studio 版本相同(1.5) 我完全卸载了 AS 并在我的桌面上下载了最新版本,所以它现在有 1.5.1 而我的笔记本电脑仍然只有 1.5。在我在桌面上进行卸载/重新安装之前,它们都在同一个版本上,并且不在桌面上工作,而是在笔记本电脑上工作。
【解决方案3】:

如果您真的想看到“添加为库”选项。 按如下方式更新 build.gradle 中的 android 依赖项(通过删除“.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'
}

}

或者,否则你可以在不编辑依赖项的情况下添加你的库

文件->项目结构->依赖->添加->文件依赖

【讨论】:

  • 我已经解决了这个问题,我会尽快发布我必须做的事情。我刚刚尝试像你的compile fileTree(dir: '../libs', include: '') 那样更改依赖行,但我仍然没有添加为库选项。我让它同步 gradle,并尝试重新启动 AS,但上下文菜单中仍然没有“添加为库”选项。
  • 我也尝试过使用File->Project Structure->Dependencies-> Add->File dependency。关于那个的事情是它似乎被锁定在模块目录中,它不会让我上升到项目结构的水平。我确实尝试将 libs 文件夹的副本放在模块中并将其添加到此菜单中,但这并没有解决我的问题。为了解决这个问题,我实际上必须打开这个菜单并删除其中的 2 个条目。
  • 尝试将所有 'compile fileTree(dir: '../libs', include: ''*.jar") ' 替换为 'compile fileTree(dir: '../libs', include: '"') 。这解决了我的 androidStudio 上的问题。我希望这对你有用。
【解决方案4】:

你可以试试这个。 maven repo 中的通用补间引擎。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-15
    • 2013-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    相关资源
    最近更新 更多