Skip to content

Instantly share code, notes, and snippets.

@oginorasta
Created February 17, 2014 18:58
Show Gist options
  • Save oginorasta/9056733 to your computer and use it in GitHub Desktop.
Save oginorasta/9056733 to your computer and use it in GitHub Desktop.
Using libgdx with Intellij (Android Studio) and Gradle
android {
compileSdkVersion compileSdkVersionVal
buildToolsVersion buildToolsVersionVal
defaultConfig {
minSdkVersion minSdkVersionVal
targetSdkVersion targetSdkVersionVal
versionCode versionCodeVal
versionName versionNameVal
packageName packageNameVal
testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
sourceSets {
main {
assets.srcDirs = ['assets']
}
}
}
// needed to add JNI shared libraries to APK when compiling on CLI
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
println pkgTask
pkgTask.jniFolders = new HashSet<File>()
pkgTask.jniFolders.add(new File(projectDir, 'libs'))
}
/**
* Executed once at the beginning of any use of the gradle command with this build file.
takes the native dependencies of the natives configuration, and extracts them to the proper libs/ folders
so they get packed with the APK.
*/
task copyAndroidNatives() {
file("libs/armeabi/").mkdirs();
file("libs/armeabi-v7a/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
apply plugin: "java"
sourceCompatibility = 1.7
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'com.android.tools.build:gradle:0.8.+' }
}
allprojects {
apply plugin: "idea"
ext.compileSdkVersionVal = 18
ext.buildToolsVersionVal = "19.0.1"
ext.minSdkVersionVal = 14
ext.targetSdkVersionVal = 18
ext.versionCodeVal = 1
ext.versionNameVal = "0.0.0.1" /*compare with @string/app_version*/
ext.packageNameVal = 'com.smartsoftware.libgdx'
ext.gdxVersion = "0.9.9" // Use "1.0-SNAPSHOT" for nightly build
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
mavenLocal();
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.10'
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
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"
compile 'de.greenrobot:eventbus:2.2.0'
instrumentTestCompile files('libs/espresso-1.1-bundled.jar')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment