Search code examples
androidlibgdxcrashlytics

Crashlytics on Libgdx


I am trying to use Fabric on my current Game Project which is based on Libgdx Framework. I am not sure where should I put instruction codes to which gradle file.

buildscript {
  repositories {
    maven { url 'https://maven.fabric.io/public' }
  }

  dependencies {
    // These docs use an open ended version so that our plugin
    // can be updated quickly in response to Android tooling updates

    // We recommend changing it to the latest version from our changelog:
    // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
    classpath 'io.fabric.tools:gradle:1.+'
  }
}

First of all this buildscript block exists in build gradle of Project, not for android. Since I put these into parent gradle file, android gradle file can not recognize the library.

apply plugin: 'io.fabric'

repositories {
  maven { url 'https://maven.fabric.io/public' }
}



compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {
    transitive = true;
  }

I can only add these code blocks into the whole gradle file again which is shown below.

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-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        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-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"

    }
}

Could you help me to use Fabric into my game properly?


Solution

  • Inject few lines of code in your root build.gradle of LibGDX project.

    buildscript {
        repositories {
            mavenLocal()
            mavenCentral()
            maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
            maven { url 'https://maven.fabric.io/public' }          //<- 1st
            jcenter()
        }
        dependencies {
            classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
            classpath 'com.android.tools.build:gradle:2.2.2'
            classpath 'io.fabric.tools:gradle:1.+'         // <- 2nd       
        }
    }
    
    allprojects {
        apply plugin: "eclipse"
        apply plugin: "idea"
    
        version = '1.0'
        ext {
            appName = "MyGDXTest"
            gdxVersion = '1.9.6'
            roboVMVersion = '2.3.0'
            box2DLightsVersion = '1.4'
            ashleyVersion = '1.7.0'
            aiVersion = '1.8.0'
        }
    
        repositories {
            mavenLocal()
            mavenCentral()
            maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
            maven { url "https://oss.sonatype.org/content/repositories/releases/" }
            maven { url 'https://maven.fabric.io/public' }      // <-- 3rd
        }
    }
    
    project(":android") {
        apply plugin: "android"
        apply plugin: 'io.fabric'                //<-- 4th
    
        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-arm64-v8a"
            natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
            natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
    
            compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') {  //<--5th
                transitive = true;
            }    
        }
    }
    

    Save and sync/refresh your gradle project.

    You can also inject crashlytics dependency(5th block) in app level build.gradle file, by default dependencies tag not present there in LibGDX project.