LibGdx doesn#39;t working after updating Gradle (Android Studio 3.0)(更新 Gradle (Android Studio 3.0) 后 LibGdx 无法正常工作)
问题描述
我最近按照此链接中的说明将 android studio 和 gradle 更新到了 3.0.0 版 https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
执行此 libgdx 桌面项目后不起作用.
它给了我这个错误
java.lang.NoClassDefFoundError: com/badlogic/gdx/ApplicationListener在 java.lang.Class.getDeclaredMethods0(本机方法)在 java.lang.Class.privateGetDeclaredMethods(Class.java:2701)在 java.lang.Class.privateGetMethodRecursive(Class.java:3048)在 java.lang.Class.getMethod0(Class.java:3018)在 java.lang.Class.getMethod(Class.java:1784)在 sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)在 sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)引起:java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener在 java.net.URLClassLoader.findClass(URLClassLoader.java:381)在 java.lang.ClassLoader.loadClass(ClassLoader.java:424)在 sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)在 java.lang.ClassLoader.loadClass(ClassLoader.java:357)... 7 更多错误:发生 JNI 错误,请检查您的安装并重试线程主"中的异常
这里是 build.gradle 文件
buildscript {存储库{mavenLocal()mavenCentral()maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }中心()谷歌()}依赖{类路径'com.android.tools.build:gradle:3.0.0'}
我只将 google()
添加到存储库并将 gradle 版本编辑为 3.0.0
在 gradle-wrapper.properties
我添加了这一行
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
Android Studio 3.0
使用 gradle-4.1
和 com.android.tools.build:gradle:3.0.0
Gradle 4.1
在 LibGDX 中尚不支持,有一个 问题 相同,现在 升级 为 Gradle 4.6p>
目前 html 模块 使用已在 Gradle 4.1
版本中删除的已弃用 jetty
插件.
但是使用终端可以运行桌面模块,我没有在 windows 上测试过,但在 Mac 上它工作正常.
./gradlew desktop:run
<小时>
目前您可以在 Android Studio 3.0 中使用较低版本的 Gradle
和 Andoid-gradle-plugin
并等待问题修复.
将 Gradle 版本从 4.1 降级到 3.3
在你的项目中找到 gradle 文件夹,打开
gradle-wrapper.properties
并将distributionUrl更改为3.3distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
将 Android-gradle-plugin 版本从 3.0.0 降级到 2.3.3
打开根
build.gradle
文件并在 buildscript 中找到工件并换个版本类路径 'com.android.tools.build:gradle:2.3.3'
从根
build.gradle
文件中的 repo 列表中注释/删除google()
---------------------------------------------------------------------------------
编辑:将 LibGDX 项目更新为 Gradle 4.6 - 作为用户
将 Gradle 升级到 4.6:
distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip
在项目存储库列表以及根
build.gradle
文件的 buildScript 存储库列表中添加 Google 的 Maven 存储库.存储库{//..谷歌()jcenter()//org.jetbrains.trove4j:trove4j 库需要}
更新 Android Gradle 插件:
类路径'com.android.tools.build:gradle:3.1.3'
Android Gradle 插件的已知问题
<块引用>使用 Gradle 4.6 及更高版本按需配置:
如果您将 Android Gradle 插件 3.0.x 或 3.1.x 与 Gradle 4.6 一起使用及以上,您应该禁用按需配置以避免一些不可预测的构建错误.(如果您使用的是 Android Gradle 插件3.2.0 或更高版本,您无需执行任何操作即可禁用按需配置.)
在
gradle.properties
文件中禁用按需配置,如下所示:org.gradle.configureondemand=false
要在 Android Studio 设置中禁用按需配置,请选择文件 > 设置(Mac 上为 Android Studio > 首选项),选择左侧窗格中的编译器类别,然后清除按需配置复选框.
在 Android Studio 3.2 Beta 1 及更高版本中,已删除启用按需配置的选项.
将 Android buildToolsVersion 更新为
27.0.3
并将 SdkVersion 更新为27
- 从 android
build.gradle
文件中的sourceSets
中删除instrumentTest.setRoot('tests')
- 将根
build.gradle
文件中的所有compile
替换为implementation
- 在 html 模块中添加了新的
GWT Gradle 插件
,查看最新的 build.gradle 的 html 模块.
使用 Run Configuration
或在终端上使用 gradle task
运行您的项目.
如果您要创建新项目,请使用最新的 gdx-setup.jarnofollow noreferrer">构建.
I have recently updated android studio and gradle to the version 3.0.0 following instructions in this link https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html
After doing this libgdx desktop project doesn't work.
It give me this error
java.lang.NoClassDefFoundError: com/badlogic/gdx/ApplicationListener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main"
Here is build.gradle file
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
I only added google()
to repositories and edit gradle version to 3.0.0
In gradle-wrapper.properties
I added this line
distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip
Android Studio 3.0
using gradle-4.1
and com.android.tools.build:gradle:3.0.0
Gradle 4.1
is not supported yet in LibGDX, there is an issue for the same, which is now upgraded for Gradle 4.6
Currently html module using deprecated jetty
plugin which is removed in Gradle 4.1
version.
However using Terminal you can run desktop module, I've not tested on windows but on Mac it's working fine.
./gradlew desktop:run
For now you can use lower version of Gradle
and Andoid-gradle-plugin
in Android Studio 3.0 and wait for issue to be fixed.
Downgrade Gradle version from 4.1 to 3.3
Find gradle folder inside your project, Open
gradle-wrapper.properties
and change distributionUrl for 3.3distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
Downgrade Android-gradle-plugin version from 3.0.0 to 2.3.3
Open root
build.gradle
file and find artifact in buildscript and change versionclasspath 'com.android.tools.build:gradle:2.3.3'
Comment/delete
google()
from repo list inside rootbuild.gradle
file
--------------------------------------------------------------------------------
EDIT : Update LibGDX project to Gradle 4.6 - AS USER
Upgrade Gradle to 4.6 :
distributionUrl=https://services.gradle.org/distributions/gradle-4.6-all.zip
Add Google's Maven repo in project repositories list as well as in buildScript repo list in root
build.gradle
file.repositories { //.. google() jcenter() // Required for org.jetbrains.trove4j:trove4j library }
Update Android Gradle Plugin :
classpath 'com.android.tools.build:gradle:3.1.3'
Known issues with the Android Gradle Plugin
Configuration on demand with Gradle 4.6 and above:
If you're using Android Gradle Plugin 3.0.x or 3.1.x with Gradle 4.6 and above, you should disable configuration on demand to avoid some unpredictable build errors. (If you are using Android Gradle Plugin 3.2.0 or higher, you do not need to take any action to disable configuration on demand.)
Disable configuration on demand in your
gradle.properties
file as shown below:org.gradle.configureondemand=false
To disable configuration on demand in the Android Studio settings, choose File > Settings (Android Studio > Preferences on Mac), select the Compiler category in the left pane, and clear the Configure on demand checkbox.
In Android Studio 3.2 Beta 1 and higher, the options for enabling configuration on demand have been removed.
Update Android buildToolsVersion to
27.0.3
and SdkVersion to27
- Remove
instrumentTest.setRoot('tests')
fromsourceSets
inside androidbuild.gradle
file - replace all
compile
withimplementation
inside rootbuild.gradle
file - New
GWT Gradle Plugin
added in html module, check latest build.gradle of html module.
Run your project with Run Configuration
or On Terminal using gradle task
.
If you're going to create new project use gdx-setup.jar
of latest build.
这篇关于更新 Gradle (Android Studio 3.0) 后 LibGdx 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更新 Gradle (Android Studio 3.0) 后 LibGdx 无法正常工作
基础教程推荐
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01