Gradle BuildConfig.class build error
Hi all,
I am using few SDK's, but this is more general question. When i try to build using new Gradle system then i get this:
[ERROR] [org.gradle.BuildExceptionReporter] > com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/twitter/sdk/android/core/BuildConfig;
I know, it's classic BuildConfig.class duplicate file error:)
things that do work:
Manualy repack all jar/aar from exported project without not needed classes/files (i did not try it, but i believe)
use DEPRECATED packageBuildConfig = false
I need different, cleaner, correct way to exclude classes or other files from compile/build.
I have already spend two days reading gradle manuals, tuts, posts, examples... google... but nothing works. You can see it in commented code.
I am new to Gradle (14 days) so maybe i am missing some obvious things. I think it should be done like this:
tell gradle somehow that i dont want some classes to unpack from jar/aar to buildfolder example: \twitter-core\build\intermediates\classes\release\com\twitter\sdk\android\core\BuildConfig.class or
if there is no way to exclude files from unpacking from jar/aar to buildfolder then there must be a way to exclude some classes from compiled build while compiling. or
if there is no way to exclude files from compiling then there must be a way to delete not needed files/classes from buildfolder before compiling.
i have tried every examples i can find but they do not work for me:( not needed files are unpacked, not deleted and compiled.
Can you please help me?
main build.gradle:
buildscript {
repositories {
jcenter()
//mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
flatDir {
dirs 'libs'
}
}
}
apply plugin: 'com.android.application'
//apply plugin: 'java'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name: 'appcompat-v7-23.4.0', ext:'aar')
compile(name: 'cardview-v7-23.4.0', ext:'aar')
compile(name: 'common', ext:'aar')
compile(name: 'facebook-android-sdk-4.17.0', ext:'aar')
compile(name: 'facebook-android-wrapper-7.9.0', ext:'aar')
compile(name: 'GoogleAIDL', ext:'aar')
compile(name: 'GooglePlay', ext:'aar')
compile(name: 'play-services-ads-10.2.1', ext:'aar')
{ exclude module: '**/BuildConfig*' }
// { exclude '**/BuildConfig.class' , module '*'}
compile(name: 'play-services-ads-lite-10.2.1', ext:'aar')
....
compile(name: 'play-services-games-10.2.1', ext:'aar')
compile(name: 'support-v4-24.0.0', ext:'aar')
compile project(':fabric')
compile project(':fabric-init')
compile project(':GoogleMobileAdsPlugin')
compile project(':MainLibProj')
compile project(':tweet-composer')
compile project(':twitter-core')
compile project(':twitterkit-deps')
compile project(':twitterkit-wrapper')
}
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
//packageBuildConfig = false
defaultConfig {
targetSdkVersion 25
minSdkVersion 16
applicationId 'com.company.app'
}
sourceSets {
main {
java {
//srcDir "$buildDir\\intermediates\\classes\\debug\\"
//exclude "$buildDir\\intermediates\\classes\\debug\\com\\company\\app\\BuildConfig.class"
exclude "$buildDir/intermediates/classes/debug/com/company/app/BuildConfig*"
//exclude "com/company/app/BuildConfig*"
//exclude '**/BuildConfig.class'
println 'Tesst6'
println "$buildDir"
}
}
}
lintOptions {
abortOnError false
}
signingConfigs { release {
storeFile file('D:/WorkUnity/keys/private.keystore')
storePassword '****'
keyAlias 'private'
keyPassword '****'
} }
buildTypes {
debug {
jniDebuggable true
//buildConfigField("String", "BUILD_TIME", "\"0\"")
//resValue("string", "build_time", "0")
}
release {
//exclude ('**/BuildConfig.class')
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-unity.txt'
signingConfig signingConfigs.release
//buildConfigField("String", "BUILD_TIME", "\"1\"")
//resValue("string", "build_time", "1") //${minutesSinceEpoch}
}
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude '**/thumbs.db'
exclude '**/BuildConfig.class'
}
}
//sourceSets {
//main {
//java {
//srcDir 'src'
//exclude '**/BuildConfig.class'
//}
//}
//}
task removeBuildConfig(dependsOn: "compileReleaseSources") {
println 'Tesst7 - task removeBuildConfig'
file("$buildDir\\intermediates\\classes\\debug\\com\\company\\app\\BuildConfig.class").delete()
doFirst {
//file("$buildDir\\intermediates\\classes\\debug\\com\\company\\app\\BuildConfig.class").delete()
println 'Tesst8 - task removeBuildConfig'
}
}
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/intermediates/classes/release/"
exclude '**/BuildConfig.class'
exclude '**/R.class'
exclude '**/R$*.class'
println 'Tesst1 - task androidReleaseJar'
}
task androidDebugJar(type: Jar, dependsOn: assembleDebug) {
from "$buildDir/intermediates/classes/debug/"
exclude '**/BuildConfig.class'
exclude '**/R.class'
exclude '**/R$*.class'
println 'Tesst2 - task androidDebugJar'
}
task jar(type: Jar) {
from '$buildDir/intermediates/classes/release'
exclude '**/BuildConfig.class'
exclude '**/R.class'
println 'Tesst3 - task jar'
}
//task jarDebug(type: Jar) {
//from 'build/intermediates/classes/debug'
//exclude '**/BuildConfig.class'
//exclude '**/R.class'
//println 'Tesst4'
//}
jar {
exclude("$buildDir\\intermediates\\classes\\debug\\com\\company\\app\\BuildConfig.class")
println 'Tesst10 - jar{}'
}
task cleanTempDir(type: Delete) {
delete file("$buildDir\\intermediates\\classes\\debug\\com\\company\\app\\BuildConfig.class")
//delete fileTree(dir: "tempDir", exclude: "dont_delete.txt")
println 'Tesst11 - task cleanTempDir'
}
one of modules build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
apply plugin: 'android-library'
//apply plugin: 'java'
dependencies {
compile fileTree(dir: 'bin', include: ['*.jar'])
compile fileTree(dir: 'libs', include: ['*.jar'])
}
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
//java.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
java {
//srcDir "$buildDir/intermediates/classes"
srcDir "$buildDir"
//exclude "$buildDir/intermediates/classes/release/com/twitter/sdk/android/core/BuildConfig.class"
exclude "**\\intermediates\\classes\\release\\com\\twitter\\sdk\\android\\core\\BuildConfig.class"
exclude "**\\BuildConfig.class"
println 'Tesst6'
println "$buildDir"
}
}
}
compileSdkVersion 25
buildToolsVersion '25.0.3'
//packageBuildConfig = false
defaultConfig {
targetSdkVersion 22
}
lintOptions {
abortOnError false
}
}
task removeBuildConfig(type: Jar) {
println 'Tesst7 - task removeBuildConfig'
//file("$buildDir/intermediates/classes/debug/**/BuildConfig.class").delete()
doFirst {
//file("$buildDir/intermediates/classes/debug/**/BuildConfig.class").delete()
println 'Tesst8 - task removeBuildConfig'
}
}
task androidReleaseJar(type: Jar, dependsOn: assembleRelease) {
from "$buildDir/intermediates/classes/release/"
exclude '**/BuildConfig.class'
exclude '**/R.class'
exclude '**/R$*.class'
println 'Tesst1 - task androidReleaseJar'
}
task androidDebugJar(type: Jar, dependsOn: assembleDebug) {
from "$buildDir/intermediates/classes/debug/"
exclude '**/BuildConfig.class'
exclude '**/R.class'
exclude '**/R$*.class'
println 'Tesst2 - task androidDebugJar'
}
task jar(type: Jar) {
from '$buildDir/intermediates/classes/release'
exclude '**/BuildConfig.class'
exclude '**/R.class'
println 'Tesst3 - task jar'
}
Answer by Grooze · Oct 10, 2017 at 10:54 AM
@Kodl Try disable tasks generateDebugBuildConfig and generateReleaseBuildConfig by placing this code at the end of mainTemplate.gradle for all your problem projects:
['crashlytics', 'crashlytics-wrapper', 'fabric', 'fabric-init', 'twitter-core'].each { name ->
project(":$name").tasks.whenTaskAdded { task ->
if (task.name == 'generateDebugBuildConfig' || task.name == 'generateReleaseBuildConfig' ) {
task.enabled = false
}
}
}
Thanks for your answer. It seems that in new versions of Unity 2017.1 and updated SD$$anonymous$$s problem is gone. Previously i have resolved it like this for every troubled modules: afterEvaluate { project -> project.tasks.transformClassesAndResourcesWithSyncLibJarsForRelease { doFirst { file("$buildDir/intermediates/classes/release/com/twitter/sdk/android/unity/BuildConfig.class").delete() } } }
But now i have much more interesting problem. I will post question soon:)
Your answer
![](https://koobas.hobune.stream/wayback/20220612121338im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Error when trying to use classes "UnityEditor.PlayerSettings" and "UnityEditor.AspectRatio" 0 Answers
Error when building in WebGL: "UnityEditor.BuildPlayerWindow+BuildMethodException: 2 errors" 0 Answers
WebBuild error,WebBuild Error 0 Answers
BuildFailedException: Burst compiler (1.2.0-preview.12) failed running Windows 0 Answers