Unity 5.6 custom gradle configuration with Fabric
Asked Answered
K

2

1

I would like to configure Fabric dependencies for Unity Android build using gradle. I'm now exporting the project and using Android Studio to get rid of the errors and then prepare a custom working "mainTemplate.gradle" so I can build directly from Unity 5.6. Here are the configured dependencies as Unity suggested:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // other dependencies
    compile project(':answers')
    compile project(':beta')
    compile project(':crashlytics')
    compile project(':crashlytics-wrapper')
    compile project(':fabric')
    compile project(':fabric-init')
}

Each of the Fabric folders is treated as a library that has its own gradle config. Here are the errors I'm getting (due to a file used in same namespace of two "libraries"):

Uncaught translation error: java.lang.IllegalArgumentException: already added: Lio/fabric/unity/crashlytics/android/BuildConfig;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Lio/fabric/unity/android/BuildConfig;

I tried adding the following but it did not work:

android {
    dexOptions {
        preDexLibraries = false
    }

I also tried without success:

task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
            from "$buildDir/intermediates/classes/release/"
            exclude '**/BuildConfig.class'
        }
Kokaras answered 17/4, 2017 at 13:11 Comment(0)
K
2

Here is how I solved this issue: By default each fabric folder is treated as a project however only "fabric" needs to be handled as one since it contains a "res" folder and an "AndroidManifest.xml" file with required meta data values. So I just kept only "fabric" as a project and changed the other dependencies to be handled as simple *.jar files.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile fileTree(dir: 'fabric-init/libs', include: ['*.jar'])
    compile fileTree(dir: 'crashlytics-wrapper/libs', include: ['*.jar'])
    compile fileTree(dir: 'crashlytics/libs', include: ['*.jar'])
    compile fileTree(dir: 'beta/libs', include: ['*.jar'])
    compile fileTree(dir: 'answers/libs', include: ['*.jar'])
    compile project(':fabric')
}

and in Settings.gradle I keep only one project reference:

//include 'answers'
//include 'beta'
//include 'crashlytics'
//include 'crashlytics-wrapper'
include 'fabric'
//include 'fabric-init'
Kokaras answered 23/4, 2017 at 17:2 Comment(1)
you can also use deprecated method: android { packageBuildConfig = falseKokaras
P
1

You can disable generation of BuildConfig java class by changes in only one file (without Fabric modifications). Place this at end of Plugins/Android/mainTemplate.gradle for all your problem projects:

['crashlytics', 'crashlytics-wrapper', 'fabric', 'fabric-init'].each { name ->
project(":$name").tasks.whenTaskAdded { task ->
    if (task.name == 'generateDebugBuildConfig' || task.name == 'generateReleaseBuildConfig' ) {
        task.enabled = false
    }
}

}

Peridot answered 10/10, 2017 at 11:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.