Unable to merge dex - gradle 3.0.0 - android

I'm new to Android and I'm trying to work though this tutorial (just the Room database part): here.
When I execute my app I get the following error:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
This issue seemed to show up after I followed this to fix another error (regarding the schema export directory for Room). I've tried to follow this post's advice about fixing this issue by using multiDexEnabled true and doing clean/re-build but it hasn't worked.
Any advice would be appreciated. This is my first post here so if I've done anything wrong please let me know.
Project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
archRoomVersion = "1.0.0-alpha1"
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' } //needed for Room
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
App Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.myname.room_example"
minSdkVersion 21
targetSdkVersion 26
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] // Room schema
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:multidex:1.0.2'
implementation "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
implementation 'com.android.support:support-annotations:27.0.0'
}

Update buildToolsVersion and supportLibVersion to the latest in your code below.
ext {
buildToolsVersion = "25.0.2"
supportLibVersion = "25.3.1"
archRoomVersion = "1.0.0-alpha1"
}
And then Clean and Rebuild Project to see if it works.

I found a solution. Replacing:
"android.arch.persistence.room:runtime:1.0.0-alpha1"
and
"android.arch.persistence.room:compiler:1.0.0-alpha1"
with
"android.arch.persistence.room:runtime:1.0.0"
and
"android.arch.persistence.room:compiler:1.0.0"

Related

i can't install androidx.preference library

i want to install preference library from androidx. when i go to project structure to add this library :
1. i don't have 1.1.0 version. i only have 1.1.0-alpha05 and 1.0.0 versions.
2. when i want to install any version of this library i get :
ERROR: Failed to resolve: androidx.preference:preference:VERSION
** i don't have same problem with other libraries
this is my gradle (app) module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.notebook_v2"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation 'androidx.appcompat:appcompat:1.0.2'
}
and this is gradle(project) module:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Try to implement this
implementation 'androidx.preference:preference:1.1.0'
And maybe you need update build tools

Execution failed for task ':app:processDebugResources'. Gradle Build Failed

Facing Errors on my Gradle build in Android Studio. Where do I need to change the code to fix the issue?
This is my project build.gradle
buildscript {
repositories {
jcenter{ url "http://jcenter.bintray.com/"}
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
maven {
url "https://maven.google.com"
}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
this is my app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.atmajaa.adda"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
resConfigs "auto"
manifestPlaceholders = [onesignal_app_id : "01bab543-cce8-4e36-a755-6bc23fd66b7c",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "REMOTE"]
multiDexEnabled true
dexOptions {
preDexLibraries = false
javaMaxHeapSize "4g"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation('com.mikepenz:fastadapter:2.6.3#aar') {
transitive = true
}
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:cardview-v7:26.0.2'
implementation 'com.android.support:support-v4:26.0.2'
implementation 'com.android.support:animated-vector-drawable:26.0.2'
implementation 'com.android.support:design:26.0.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.synnapps:carouselview:0.1.4'
implementation 'com.mikepenz:fastadapter-commons:2.6.3#aar'
implementation 'com.mikepenz:fastadapter-extensions:2.6.3#aar'
implementation 'com.miguelcatalan:materialsearchview:1.4.0'
implementation 'org.jsoup:jsoup:1.10.3'
implementation 'com.thefinestartist:finestwebview:1.2.7'
implementation 'com.github.chrisbanes:PhotoView:1.3.1'
implementation 'com.fnp:material-preferences:0.1.4'
implementation 'com.thebluealliance:spectrum:0.7.1'
implementation 'com.firebaseui:firebase-ui-auth:2.3.0'
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'com.google.firebase:firebase-invites:17.0.0'
implementation 'com.google.firebase:firebase-ads:18.0.0'
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.onesignal:OneSignal:3.10.9'
implementation 'com.android.support:multidex:1.0.3'
// Required only if Facebook login support is required
implementation('com.facebook.android:facebook-android-sdk:4.22.1')
// Required only if Twitter login support is required
implementation("com.twitter.sdk.android:twitter-core:3.0.0#aar") { transitive = true }
}
apply plugin: 'com.google.gms.google-services'
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:processDebugResources'.
Android resource linking failed
error: invalid config 'auto' for -c option.
In your App-level build.gradle, I can see you've used resConfigs "auto" :
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.atmajaa.adda"
minSdkVersion 16
targetSdkVersion 26
...
resConfigs "auto"
...
}
}
Use the following code instead of auto, as mentioned in this documentation reference link and define/limit your language resources to whichever languages you prefer:
android {
defaultConfig {
...
resConfigs "en"
}
}
Now getting error on this line:

Failed to resolve: com.android.support:design-v7:27.1.1

I am using Android Studio 3.1.3. Gradle build sync failed. I used following method but there is no use of it. If there is any solution please tell me
maven { url "https://maven.google.com" }
Invalidate restart & caches
multiDexEnabled true
Adding mavenLocal() and mavenCentral()
This is module level build.gradle file:
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.developers.a_g.designapp"
minSdkVersion 15
targetSdkVersion 27
buildToolsVersion '27.1.1'
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree( dir: 'libs',include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design-v7:27.1.1'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.szagurskii:patternedtextwatcher:0.5.0'
implementation 'com.github.d-max:spots-dialog:0.7#aar'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
}
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.developers.a_g.designapp"
minSdkVersion 15
targetSdkVersion 27
buildToolsVersion '27.1.1'
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree( dir: 'libs',include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:design-v7:27.1.1'
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.szagurskii:patternedtextwatcher:0.5.0'
implementation 'com.github.d-max:spots-dialog:0.7#aar'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
}
This is project level build.gradle file:
buildscript {
repositories {
jcenter()
google()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
First make sure that you using:
targetSdkVersion 27
compileSdkVersion 27
buildToolsVersion '27.0.3'
And your gradle be like:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
//..
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
//..
}
}
And also update design implementation like below:
implementation 'com.android.support:design:27.1.1'
You get this error because com.android.support:design-v7 does not exist it exist without -v7, also you can check support libraries in this link any time to make sure you are using the correct library.
You should add google() repository to your dependencies
allprojects {
repositories {
google()
jcenter()
}
}
Don't
implementation 'com.android.support:design-v7:27.1.1'
buildToolsVersion '27.1.1'
Do
implementation 'com.android.support:design:27.1.1'
buildToolsVersion '27.0.3'
Make sure, you added below
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com/' }
}
}
Then Clean-Rebuild-Build.
Add the maven URL in all projects section as well and sync the gradle or try removing one by one external libraries and sync the gradle hope it helps
allprojects { repositories { google() jcenter()maven :"http://www.google.com" } }
this is the correct form
implementation 'com.android.support:design:27.1.1'
Upgrade to Android Studio 3.3 destroyed all my projects.
This was one of the problems today I ran into. And after wasting too much time to find a solution, here is the working gradle. By the time I fixed this, I had forgotten what actually I was working on. I really wonder why Google always ship their Android Studio with broken gradle files. Seems like Google engineers even themselves don't know how to write proper gradle, and nobody QAs Android Studio before its final release.
Module level gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.journaldev.okhttp"
minSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
}
And the project level gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com/' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Dex Error while building the project

I am getting the following error when I try to build my project. This error occurs when I was trying to add JavaMail api in my project.
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
This is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.persi.eatery"
minSdkVersion 21
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'
}
}
productFlavors {
}
packagingOptions {
exclude 'META-INF/mailcap.default'
exclude 'META-INF/mimetypes.default'
}
defaultConfig {
multiDexEnabled true
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:design:26.1.0'
implementation 'com.google.firebase:firebase-database:11.8.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
implementation 'com.sun.mail:android-mail:1.6.1'
implementation 'com.sun.mail:android-activation:1.6.1'
implementation project(':library')
}
apply plugin: 'com.google.gms.google-services'
My library gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 8
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Project gradle file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url "https://maven.java.net/content/groups/public/"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:3.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
P.S I have already tried Clean project followed by rebuild project as suggested in other answers but its still not working.Thanks in advance
Unable to merge dex
You have a dependencies conflict. Try to see your dependencies via command ./gradlew app:dependencies (Details here ). And you will see the next situation:
As you can see android-mail depends on android-activation. I think you don't need to use the line implementation 'com.sun.mail:android-activation:1.6.1'
P.S. For debugging builds you can use the next flag "--stacktrace". Then you can see more information about your issue.

How to use Android Kotlin Dagger 2 and Firebase Auth in Data module?

I'm trying to set up an app where data module is a library and presentation layer is the actual android app. Ideally I want the firebase dependency to just live in the data module however apply plugin: 'com.google.gms.google-services' can only be called from the presentation module.
Putting dagger 2 and firebase dependency together gives me the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':presentation:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Removing the firebase auth dependency or dagger 2 dependency resolves this issue. How can I use both of these libraries together in the data module?
My build.gradle for data
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
defaultConfig {
minSdkVersion 19
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "android.arch.lifecycle:extensions:1.0.0-alpha9-1"
compile 'com.google.dagger:dagger:2.11'
kapt 'com.google.dagger:dagger-compiler:2.11'
compile 'com.google.firebase:firebase-auth:11.4.2'
}
And build.gradle for presentation:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
def configs = rootProject.extensions.getByName("ext")
compileSdkVersion configs["compileSdkVersion"]
buildToolsVersion configs["buildToolsVersion"]
defaultConfig {
applicationId configs["androidApplicationId"]
minSdkVersion configs["minSdkVersion"]
targetSdkVersion configs["targetSdkVersion"]
versionCode configs["versionCode"]
versionName configs["versionName"]
testInstrumentationRunner configs["testInstrumentationRunner"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '26.0.2'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':data')
implementation "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation "junit:junit:$rootProject.junitVersion"
androidTestImplementation("com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion", {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
apply plugin: 'com.google.gms.google-services'
Here is the top level build file (if needed)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta7'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
ext {
//Android
androidApplicationId = 'com.test.myapp'
minSdkVersion = 19
targetSdkVersion = 26
versionCode = 1
versionName = "1.0"
compileSdkVersion = 26
buildToolsVersion = "26.0.2"
//Libraries
supportLibraryVersion = '26.1.0'
//Testing
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
junitVersion = "4.12"
espressoVersion = "3.0.1"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
It seems like the problem was with the google-services version. The issue resolved for me after I updated the play services version:
classpath 'com.google.gms:google-services:3.1.1'
from 3.1.0

Categories

Resources