How to exclude .jar file from .aar file

Viewed 1516

Is there a way to exclude .jar file from .aar file. My project is not running as I have one module that contains a .aar file in which Gson.jar is used as a library and I need it in my main app as well so I need to implement Gson dependency also. When I tried to run my project I got multidex error:

Execution failed for task ':app:transformClassesWithBundleMultiDexListForDevelopmentBuildDebug'.

com.android.build.api.transform.TransformException: Error while generating the main dex list.

Please help me to solve this issue. Thanks

2 Answers

You can have exculde in the targets just like this

 sourceSets.main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
        java {
            exclude '**/VanillaARMv*'
            exclude '**/VanillaX86*'
        }
        resources {
            exclude '**/VanillaARMv*'
            exclude '**/VanillaX86*'
        }
        aidl {
            exclude '**/VanillaARMv*'
            exclude '**/VanillaX86*'
        }
        renderscript {
            exclude '**/VanillaARMv*'
            exclude '**/VanillaX86*'
        }

    }

Here i am excluding whatever i have in VanillaARMv* and in VanillaX86* folders from the target build.

Related