Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Kodl · May 09, 2017 at 05:19 AM · build-error

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:

  1. Manualy repack all jar/aar from exported project without not needed classes/files (i did not try it, but i believe)

  2. 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:

  1. 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

  2. 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

  3. 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'
 }
gradle-error.zip (2.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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
     }
 }

}

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kodl · Oct 11, 2017 at 12:28 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

101 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error when trying to use classes "UnityEditor.PlayerSettings" and "UnityEditor.AspectRatio" 0 Answers

Start, update, OnTriggerEnter and awake functions greyed out when updated from unity 2019.2.4 to unity 2020.1 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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges