Android studio Unable to merge dex only on rebuild - java

I have an android project created with android studio 2.3.
Now I have upgraded to android studio 3 and I have the following error.
When I ran my app it compiles normally and is installed in my device. It works fine. Any changes I make to the code are visible in the device.
But when I try to rebuild i get the following error:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
this happens only on rebuild. I have tried to clean and rebuild and also i have done invalidate cache/Restart.
What is the problem?
EDIT:
My app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "gr.myapp1"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile project(':CoreServices-3.14.5')
compile project(':maflogoncore-1.214.5')
//compile project(':maflogonui-1.214.5')
compile project(':mafsettingscreen-1.214.5')
compile project(':mafuicomponents-1.214.5')
compile project(':MobilePlace-3.14.5')
compile project(':ODataOnline-3.14.5')
compile project(':Request-3.14.5')
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:support-vector-drawable:25.3.1'
compile 'com.google.android.gms:play-services:11.0.2'
compile 'com.google.maps.android:android-maps-utils:0.4'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
}
//firebase
apply plugin: 'com.google.gms.google-services'
my project gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
//firebase
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Eventually i had to enable multidex although i had minimumVersion: 21
Maybe because when i created the project i had it set to 19 and i changed it to 21.
I haven't found why it worked all this time without multidex and now that i upgraded to Android studio 3 it requires it.

Related

Unable to Merge Dex Android Studio 3.0 after update

updated my project to gradle 3 and generated this error
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
in another questions says "libraries having transitive dependency " but i don't find the library with this transitive dependency
in gradle 2.3 don't show this error
build.gradle app
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
compileOptions.encoding = 'UTF-8'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.my.my"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
jni.srcDirs = ["libs"]
}
}
packagingOptions {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':dd-plist')
compile project(':Emojicon')
compile project(':CameraModule')
compile project(':ScapeUtils')
compile project(':circleimageview')
compile project(':FFMPG')
compile project(':PdfViewer')
compile project(':LibLinphone')
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.github.bumptech.glide:glide:3.6.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.ornolfr:rating-view:0.1.1#aar'
compile 'cat.ereza:customactivityoncrash:1.5.0'
compile 'com.writingminds:FFmpegAndroid:0.3.2'
compile 'com.google.firebase:firebase-messaging:11.0.4'
compile "com.android.support:appcompat-v7:26.1.0"
compile 'com.android.support:recyclerview-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'org.apache.commons:commons-io:1.3.2'
}
apply plugin: 'com.google.gms.google-services'
build.gradle project
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.0.0'
}
I am battling also with this or similar problem. I have set to use the old gradle version manually. From File/Project structure/projet I have put gradle version 3.4.1 and plugin version 2.3.3
I have also added multiDexEnabled true in app/build.gradle inside defaultConfig Hth

plugin with id 'com.android.application' not found. android studio jni sample

I am trying to follow the android-studio-jni tutorial from the following link:
https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#2
The simple android app works fine but as soon as I change the classpath to the gradle-experimental as suggested in the tutorial, i get the above mentioned error. I did look at other SO questions related to this but none of them solved my issue.
These are the only changes I made(as done in the tutorial example):
In build.gradle (Module:app) file:
`proguardFiles getDefaultProguardFile('proguard-android.txt'),` `'proguard-rules.pro'`
replaced with :
proguardFiles.add(file('proguard-android.txt'))
In Gradle-wrapper.properties (Gradle Version):
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
replaced with
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
In build.gradle (Project:Samples) file:
classpath 'com.android.tools.build:gradle:2.3.3'
replaced with
classpath 'com.android.tools.build:gradle-experimental:0.9.3’

Update:
As suggested by #Hetfieldan24 , my mistake was not having the correct plugin type.
Once I modified it, I am now getting the following error:
Error:(3, 0) Could not find method android() for arguments [build_90xijo5xugofjl1c4u81bbnlj$_run_closure1#e9e4277] on project ':app' of type org.gradle.api.Project.
Files:
build.gradle (Module:app)
apply plugin: 'com.android.model.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.polyyai.user.samplejniapp1"
minSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles.add(file('proguard-android.txt'))
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'com.android.support:design:26.+'
testCompile 'junit:junit:4.12'
}
build.gradle (Project:Samples)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle-experimental:0.9.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle-wrapper.properties (Gradle Version)
#Sat Aug 19 17:05:08 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Any help is appreciated.
Thanks

Android Studio: duplicate entry: android/support/annotation/DrawableRes.class

Kindly need your expertise. This error came up when I add compile 'com.android.support:design:23.2.1' in my gradle.
Error:Execution failed for task
':myApp:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry:
android/support/annotation/DrawableRes.class
Here is my gradle dependencies file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "com.iws.iwsapp"
minSdkVersion 16
targetSdkVersion 22
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':facebookSDK')
compile project(':library')
compile 'com.android.support:appcompat-v7:23.2.1'
compile files('libs/android-query-full.0.26.7.jar')
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile files('libs/mint-5.0.0.jar')
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.android.gms:play-services-identity:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
compile files('libs/android-support-v13.jar')
compile 'com.android.support:design:23.2.1'
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
Appreciate the help. Thank you.
It seems that you have duplicate support/annotation/DrawableRes.class. Make sure all your lib project:
facebookSDK
library
and all jar libraries under libs directory didn't include the android.support.anotation package.
If you are sure you didn't use annotation package, you can exclude annotation in your app build.gradle file like this.
android{
...
configurations {
all*.exclude group: 'com.android.support', module: 'support-annotations'
}
}

android error : Gradle sync failed: Gradle DSL method not found: 'classpath()'

hi i'm newbie with Android studio, after updating from android studio 1.4 to 2.1, I am getting the following build error when I try and sync my project:
Gradle sync failed: Gradle DSL method not found: 'classpath()'
and Here is the build.gradle:
apply plugin:'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "android.arisa.---------"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
//multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
exclude module: 'support-v4'
}
compile('com.afollestad.material-dialogs:core:0.8.1.0#aar') {
transitive = true
}
compile('com.afollestad.material-dialogs:commons:0.8.1.0#aar') {
transitive = true
}
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
//compile 'com.android.support:multidex'
//compile 'com.mcxiaoke.volley:library-aar:1.0.0'
//compile 'com.mcxiaoke.volley:library:1.+'
compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/.idea/libraries/jsoup-1.8.3.jar')
compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/jsoup-1.8.3.jar')
compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/libraries/jsoup-1.8.3.jar')
compile 'com.google.android.gms:play-services:8.3.0'
}
repositories {
jcenter()
}
//repositories {
// maven { url "https://jitpack.io" }
//}
and the gradle-wrapper.properties is:
#Sat Apr 30 11:59:41 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
How can i correct this?(please help me)
edit: After editing grade, my android gradle is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "android.arisa.kalahroodfinal"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
exclude module: 'support-v4'
}
compile('com.afollestad.material-dialogs:core:0.8.1.0#aar') {
transitive = true
}
compile('com.afollestad.material-dialogs:commons:0.8.1.0#aar') {
transitive = true
}
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/.idea/libraries/jsoup-1.8.3.jar')
compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/jsoup-1.8.3.jar')
compile files('/Users/Bmaster/AndroidStudioProjects/KalahroodFinal/libraries/jsoup-1.8.3.jar')
compile 'com.google.android.gms:play-services:8.3.0'
}
but i have new error:
Error:(43, 13) Failed to resolve: com.afollestad.material-dialogs:commons:0.8.1.0
Error:(40, 13) Failed to resolve: com.afollestad.material-dialogs:core:0.8.1.0
Try to remove the classpath 'com.android.tools.build:gradle:2.1.0' string.
I also would recommend you to create new project in Android studio 2.1 and compare the gradle files generated by IDE with yours.
You are using
classpath 'com.android.tools.build:gradle:2.1.0'
in the wrong block.
More it in the top-level build.gradle file (in the root of your project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
To solve the issue with the library material dialog you have to add the repository from which download the dependencies:
In your top-level build.gradle file add the jitpack repo:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}

Duplicate Files Copied-Bouncy Castle(bcpkix-jdk15on-1.48.jar)-How can I resolve that?

So I'm getting this annoying message(full message at the bottom at the message),and I have no idea which libraries include those bouncycastle files (I didn't include them myself directly),I'm guessing that two of them include different versions of the same files? :P
How can I know which packages/libraries included those? How can I solve the issue?
Here are the build.grade files:
App level:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "dor.only.dorking.android.profilemanager"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
apply plugin: 'com.google.gms.google-services'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.android.support:design:23.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.android.gms:play-services-auth:8.3.0'
compile 'com.google.api-client:google-api-client:1.19.1'
compile 'com.google.apis:google-api-services-plus:v1-rev375-1.21.0'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.google.gms:google-services:2.1.0-beta3'
}
Project level:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.google.gms:google-services:2.1.0-beta3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
And this is the error message (Gradle's output, I am using Android Studio):
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/BCKEY.DSA
File1: C:\Program Files\Android\Android Studio\gradle\m2repository\org\bouncycastle\bcpkix-jdk15on\1.48\bcpkix-jdk15on-1.48.jar
File2: C:\Program Files\Android\Android Studio\gradle\m2repository\org\bouncycastle\bcprov-jdk15on\1.48\bcprov-jdk15on-1.48.jar

Categories