简体   繁体   English

"Gradle android 优化打包选项"

[英]Gradle android optimize packagingOptions

I have that project structure:我有那个项目结构:

-gradle root
           |-clients
                    |-client 1
                    |-client 2
                        ... 
                    |-client N
           |-libs
                    |-android lib 1
                    |-android lib 2
                        ...
                    |-android lib N
                    |-java lib 1
                    |-java lib 2
                        ...     
                    |-java lib N

In each client build file I have the packagingOptions to exclude options.在每个客户端构建文件中,我都有packagingOptions来排除选项。 Something like that:像这样的东西:

packagingOptions {
    exclude 'META-INF/DEPENDENCIES.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
}

How could I optimize that block and move it for example in my root gradle build file?如何优化该块并将其移动到我的根 gradle 构建文件中? I don't really want to copy paste it across all clients.我真的不想在所有客户端上复制粘贴它。

Found solution.找到解决方案。 Credits: https://github.com/frankdu/android-gradle-dagger-tutorial学分: https : //github.com/frankdu/android-gradle-dagger-tutorial

I've created separate build file and moved that settings there.我创建了单独的构建文件并将该设置移到那里。 File android_common.gradle文件android_common.gradle

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
    }
}

Then in each client put that line:然后在每个客户端中放置该行:

apply from: "${rootDir}/android_common.gradle"

And finally excluded packagingOptions from my clients build files.最后从我的客户构建文件中排除了packagingOptions In additional I've moved another common configurations there.此外,我在那里移动了另一个常见配置。 Looks clean, simple and nice after that.之后看起来干净,简单,漂亮。

For the record, most of your package options are already the default.作为记录,您的大多数包选项已经是默认值。

See PackagingOptions Gradle documentation请参阅PackagingOptions Gradle 文档

Pick first: none
Merge: /META-INF/services/**
Exclude:
/META-INF/LICENSE
/META-INF/LICENSE.txt
/META-INF/NOTICE
/META-INF/NOTICE.txt
/LICENSE
/LICENSE.txt
/NOTICE
/NOTICE.txt
/META-INF/*.DSA (all DSA signature files)
/META-INF/*.EC (all EC signature files)
/META-INF/*.SF (all signature files)
/META-INF/*.RSA (all RSA signature files)
/META-INF/maven/** (all files in the maven meta inf directory)
/META-INF/proguard/* (all files in the proguard meta inf directory)
**/.svn/** (all .svn directory contents)
**/CVS/** (all CVS directory contents)
**/SCCS/** (all SCCS directory contents)
**/.* (all UNIX hidden files)
**/.*/** (all contents of UNIX hidden directories)
**/*~ (temporary files)
**/thumbs.db
**/picasa.ini
**/protobuf.meta
**/about.html
**/package.html
**/overview.html
**/_*
**/_*/**

For those who cant find fresh documentation link for PackagingOptions .对于那些找不到PackagingOptions的新文档链接的人。

This must be comment to LanDenLabs answer but I cant post a comment without 50 rep :(这必须是对 LanDenLabs 答案的评论,但我不能在没有 50 个代表的情况下发表评论 :(

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM