Android Gradle library build: Include & exclude files from the jar inside the generated aar

落爺英雄遲暮 提交于 2019-12-08 03:28:00

问题


I exporting Android library via building aar with Gradle, and I have requirements for the jar inside the aar: Basically I need the jar to reflect following files structure that already exist in the project (jpeg files should be inside java package alongside .class files):

project_name
           |
           module_name
                     |
                     src
                       |
                       main
                          |
                          java
                             |
                             package_to_include
                                              |
                                              java_files
                                              jpeg_files
                             package_to_exclude

This is the relevant part from build.gradle script:

apply plugin: 'com.android.library'    
android {
    ... 
    sourceSets {
        main {
            java {
                srcDir 'src/main/java'
                exclude 'package_to_exclude/**'
                resources.includes = [ 'package_to_include/*.jpeg' ]
            }
            resources {
                srcDir 'src/../lib'
            }
        }
    }
}

Result: The exclude part works, the include not: In the jar inside package_to_include there are only the java source code files as .class files. The jpeg's not in the jar at all.

By the way I'm not totally familiar with the double astrix (**) operator. Maybe this is the direction for solution?

Thanks,


回答1:


As you suspect the ** is the missing component. Guessing the path to your include is probably missing the src/main/java prefix to the package_to_include.

** means any folder reclusively. So for example:

src/main/java/package_to_include/image.jpg
src/main/res/image.jpg
// both would match
**/image.jpg

Also this line is weird srcDir 'src/../lib' because its the same as srcDir 'lib'



来源:https://stackoverflow.com/questions/33208453/android-gradle-library-build-include-exclude-files-from-the-jar-inside-the-ge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!