更新时间:2023-01-26 12:38:46
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.3
distributionUrl=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
build.gradle
文件中的 sourceSets
中删除 instrumentTest.setRoot('tests')
build.gradle
文件中的所有compile
替换为implementation
GWT Gradle 插件
,查看最新的 build.gradle 的 html 模块.使用 Run Configuration
或在终端上使用 gradle task
运行您的项目.
如果您要创建新项目,请使用最新的 构建.
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.3
distributionUrl=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 version
classpath 'com.android.tools.build:gradle:2.3.3'
Comment/delete google()
from repo list inside root build.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 to 27
instrumentTest.setRoot('tests')
from sourceSets
inside android build.gradle
filecompile
with implementation
inside root build.gradle
fileGWT 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.