Error:duplicate files during packaging of APK Android Studio Error
Well you are missing the flow of build gradle.
As you are trying to use 2 android {..}
snippet it is not detecting the 2nd one. As a result your exclusion of duplicate meta files are not working.
Possible solution:
Just change the order of your build gradle like below:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:+'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.mcxiaoke.volley:library:1.0.15'
compile 'com.google.code.gson:gson:2.2.4'
compile "org.apache.httpcomponents:httpcore:4.4.1"
compile "org.apache.httpcomponents:httpmime:4.3.6"
}
If it still didn't work then check out the following:
Is it your library build gradle?
I excluded my duplicate meta files from my main projects build gradle. So make sure to exclude the meta files from build gradle of app module rather than library module.
Why this error happen Duplicate files during packaging of APK?How to fix this error?
Replace your gradle with this
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "your_package_name"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENCE'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
<!--Jar's Goes Here-->
}
Still getting the error means replace packagingOptions
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
Error :: duplicate files during packaging of APK
I think the string comparison is case sensitive. try with exclude 'META-INF/notice.txt'
Error : Gradle: Duplicate files during packaging of APK
Add below lines in the packagingOptions and dependencies.
packagingOptions {
exclude 'META-INF/DEPENDENCIES.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/dependencies.txt'
exclude 'META-INF/LGPL2.1'
}
And in dependencies use as below.
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:cardview-v7:23.2.0'
compile 'com.android.support:recyclerview-v7:23.2.0'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
exclude module: 'spring-core'
}
compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
compile 'org.apache.commons:commons-io:1.3.2'
compile 'joda-time:joda-time:2.3'
compile 'com.fasterxml.jackson.core:jackson-databind:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.7.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.2'
compile 'com.google.code.gson:gson:2.6.2'
}
I think this will solve your issues.
Duplicate files during packaging of APK or UnsatisfiedLinkError Android
I think I found the solution, however, I do not quite understand it.
The build.gradle
files of both modules mylibrary and tess-two contained a definition for
android.sourceSets.main.jniLibs.srcDirs = ['libs']
Commenting this definition in tess-two resulted in libtess.so
and liblept.so
being copied to the apk only once.
If someone understands this solution please leave a comment or answer.
Edit:
In the meantime I found a better solution:
I added the following code to my main applications gradle.build file:
packagingOptions { // otherwise libtess.so and liblept.so are copied to apk twice resulting in an error
pickFirst('lib/*/liblept.so')
pickFirst('lib/*/libtess.so')
}
Error: duplicate files during packaging of APK after add Realm dependence to gradle
Move your android
closure to be after the dependencies
closure:
apply plugin: 'com.android.library'
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.squareup.okhttp:okhttp:2.3.0'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'io.realm:realm-android:0.87.2'
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
}
The LogCat show this error Gradle DSL method not found: 'packagingOptions()'
Then you do not have packagingOptions
inside android
.
Related Topics
Validate Username and Email Crashed and Cannot Insert to Firebase Database
Disable Orange Outline Highlight on Focus
Where to Find Info on Android's "Service Call" Shell Command
How to Sign an APK with More Than One Certificate
How to Force Stop My Android Application Programmatically
Can't Get Values Out of Ondatachange Method
Eclipse Reports Rendering Library More Recent Than Adt Plug-In
Completely Transparent Status Bar and Navigation Bar on Lollipop
Get Certificate Fingerprint from Android App
How to Determine Which Dependency Causes Google Play Openssl Warning
How to Create Custom UI for Android Mediacontroller
Get Cursor Position in Android in Edit Text
Flutter Projects & Android X Migration Issues
Android Studio - How to Make an Avd with Arm Instead of Haxm
Clicking Hamburger Icon on Toolbar Does Not Open Navigation Drawer