How to exclude a file from an .AAR Android library archive with gradle

前端 未结 2 678
一整个雨季
一整个雨季 2021-01-04 05:05

I am trying to create an AAR file for a library Android project using Android Studio and gradle.

I want to exclude from this archive specific folders and files but

2条回答
  •  忘掉有多难
    2021-01-04 05:27

    I can't try it right now, but this would probably be my approach:

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            aidl.srcDirs = ['src']
            resources.srcDirs = ['src']           
            renderscript.srcDirs = ['src']
            java.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    
        flavor1 {
            java.srcDirs = ['src/main/java', 'src/flavor1/java']         
            res.srcDirs = ['src/flavor1/res'] //this differs from your structure
            assets.srcDirs = []
        }
    
        flavor2 {
            java.srcDirs = ['src/main/java', 'src/flavor2/java']
            res.srcDirs = ['src/flavor2/res'] //this differs from your structure
            assets.srcDirs = ['src/main/res/raw']
        }
    }
    

    Again, I couldn't try it, so this could be complete nonsense. The idea was to not exclude stuff, but only include the files/dirs you do want in you flavor. This may will lead to duplication of files/folders per flavor!

    As sources I would recommend: Gralde Plugin User Guide, the answer from Xavier Ducrohet and also this Gradle + Android, want to overwrite /assets with custom folder in buildFlavor.

提交回复
热议问题