Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are gradle build packagingOptions needed?

In my gradle file, I have the following:

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

According to the documentation:

/**
 * Adds an excluded paths.
 * @param path the path, as packaged in the APK
 */

What does this mean? Could someone give me a real life example of why these exclusions would need to be made?

like image 456
Daiwik Daarun Avatar asked Feb 15 '16 19:02

Daiwik Daarun


People also ask

What is Packagingoptions in Android Studio?

merges. The list of patterns where all occurrences are concatenated and packaged in the APK.

Why do we need build Gradle?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.

Why does Gradle build fail?

When Gradle is unable to communicate with the Gradle daemon process, the build will immediately fail with a message similar to this: $ gradle help Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details FAILURE: Build failed with an exception.

What all things need to define in build Gradle file?

applicationId– This is used for identifying unique id for publishing of the app. minSdkVersion– This defines the minimum API level required to run the application. targetSdkVersion– This defines the API level used to test the app. versionCode– This defines the version code of the app.


1 Answers

If you were to change the extension of a few aar files to zip and open them eventually you will have two aar files with files that with the same path.

SomeDependency-A.aar
-META-INF/LICENSE
...

SomeDependency-B.aar
-META-INF/LICENSE
...

When the aar dependencies are merged it fails because it tries to add the file LICENSE and it already exists.

We resolve this by excluding the duplicated files

android {
    packagingOptions {
        exclude 'META-INF/LICENSE'
    }
}
like image 190
JBirdVegas Avatar answered Oct 05 '22 08:10

JBirdVegas