What is the best way to add LibGDX to an existing Android Studio project?
Because Android Studio already has Gradle built in, I was assuming that I could change some code in the build.gradle file to add LibGDX to my existing project. The only gradle instructions I found on LibGDX was the automated tool for making a new project with LibGDX already baked in.
All idea of libgdx is writing one code for all platforms. So Android specific code should be added in properly way and if you will just add libgdx dependencies to your project it will not help you a lot. You will be able to use only very small part of libgdx features. If you want to do it in any case here is a example of build.gradle
which adds libgdx dependencies to regular Java project, compare it with your build.gradle
and add needed lines to ext
, repositories
and dependencies
sections.
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "java"
apply plugin: "maven"
sourceCompatibility = 1.6
targetCompatibility = 1.6
version = '0.1'
group = 'com.gdx.bream'
ext {
appName = 'bream'
gdxVersion = '1.3.1'
}
repositories {
mavenCentral()
mavenLocal()
maven { url 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/' }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
sourceSets {
main {
java { srcDirs = ['src']}
resources {
srcDirs = ['src']
}
}
}
task sourcesJar(type:Jar){
from sourceSets.main.allSource
classifier = 'sources'
}
artifacts { archives sourcesJar }
dependencies { compile "com.badlogicgames.gdx:gdx:$gdxVersion" }
P.S If you want create game only for Android and looking for engine which can be easily integrated to existing project, take a look at AndEngine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With