How To Exclude Specific Resources from an AAR Depedency?

前端 未结 4 1388
清歌不尽
清歌不尽 2020-12-03 01:04

Is there a reasonably simple way for a module\'s build.gradle file to indicate that certain files from a dependency should be excluded? I am specifically intere

4条回答
  •  不知归路
    2020-12-03 01:31

    EDIT:

    Wrote advanced gradle task for you:

    final List exclusions = [];
    
    Dependency.metaClass.exclude = { String[] currentExclusions ->
        currentExclusions.each {
            exclusions.add("${getGroup()}/${getName()}/${getVersion()}/${it}")
        }
        return thisObject
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        compile ('com.android.support:appcompat-v7:20.+')
        debugCompile ('com.squareup.leakcanary:leakcanary-android:1.3.1')
                .exclude("res/values-v21/values-v21.xml")
        releaseCompile ('com.squareup.leakcanary:leakcanary-android-no-op:1.3.1')
    }
    
    tasks.create("excludeTask") << {
        exclusions.each {
            File file = file("${buildDir}/intermediates/exploded-aar/${it}")
            println("Excluding file " + file)
            if (file.exists()) {
                file.delete();
            }
        }
    }
    
    tasks.whenTaskAdded({
        if (it.name.matches(/^process.*Resources$/)) {
            it.dependsOn excludeTask
        }
    })
    

    Now you can use method .exclude() on each dependency, providing into list of paths, you want to exclude from specified dependency. Also, you can stack the .exclude() method calls.

提交回复
热议问题