Reputation: 1812
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'
}
Upvotes: 1
Views: 1408
Reputation: 21
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
}
}
}
Upvotes: 1
Reputation: 1812
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'
Upvotes: 2