39

Whenever i add implemntation 'com.google.android.material:material:1.0.0-alpha1' when i try to build my project Android Studio says:

Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy Message{kind=ERROR, text=Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy, sources=[Unknown source file], tool name=Optional.of(D8)}

This is my gradle script:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "it.smart.bab3"
        minSdkVersion 21
        targetSdkVersion 'p'
        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:28.0.0-alpha1'
    implementation 'com.google.android.material:material:1.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    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:design:28.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
}

I'm new ith this type of errors, and i didn't find anithing with this error. Thanks

Smart
  • 445
  • 1
  • 5
  • 12

14 Answers14

53

I've been struggling all day with this issue too. Finally I managed to compile and run the project successfully.

First of all, get rid of this:

implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'

Add the following in your gradle.properties file:

android.useAndroidX = true
android.enableJetifier = false

And finally, sync the project and then compile.

If it doesn't work, clean the project and then rebuild.

PS: I can't get targetSdkVersion 'p' to work. My build.gradle file end up as follows:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "com.github.alvarosct02.demo"
        minSdkVersion 19
        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'])

    implementation 'com.google.android.material:material:1.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'

    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'

}

Hope it works for you too.

  • While this initially seemed to work for me, it is now throwing the same error after I added Room to the project. – gadgetroid May 12 '18 at 11:43
  • remember that to use appcompatactivity and other stuff check out this page:-https://developer.android.com/topic/libraries/support-library/refactor – jeevan s May 17 '18 at 05:19
  • 1
    Need not add 'android.useAndroidX = true' or 'android.enableJetifier = false'. Just make sure you are using the AndroidX support libs and not v4 or v7 support libs. Refer https://developer.android.com/topic/libraries/support-library/refactor – Ranjeet May 17 '18 at 08:40
  • Hi guys! I'm facing the same problem, I tried the above solution but it did not work. Android studio 3.1.3 Gradle file: – GFPF Jun 19 '18 at 23:35
  • @Alvaro, from the docs "Important: In the current Android Studio 3.2 Canary version, there is a known issue that causes the android.useAndroidX flag to not be set when you use the Create New Project wizard. For now, you need to set the flag manually in your gradle.properties file. If you want to start using AndroidX libraries immediately and don't need to convert existing third-party libraries, you can set the android.useAndroidX flag to true and the android.enableJetifier flag to false." Link - https://developer.android.com/studio/preview/features/ Please include this in answer. – Debanjan Jun 20 '18 at 08:21
  • @Debanjan You mean the Link? The change of the flags is part of the answer – Alvaro Santa Cruz Jul 04 '18 at 16:27
  • @alvaro yes. I was referring to the link. That would be great. – Debanjan Jul 04 '18 at 17:13
  • You suggest to add android.useAndroidX = true and android.enableJetifier = false but in your build gradle there are no lines like this. Where should I put these? I'm getting: Could not set unknown property 'useAndroidX' for object of type com.android.build.gradle.AppExtension. – SMGhost Aug 01 '18 at 21:08
  • 2
    @SMGhost In the gradle.properties file. Don't try to do it on the build.gradle – Alvaro Santa Cruz Aug 01 '18 at 22:01
  • when i use firebase sdk with this it shows same error, not worked this solution – Anant Shah Aug 15 '18 at 13:19
  • @Debanjan if I don't want to use androdx only use v4 v7 library then? – Er.nishka Jul 17 '19 at 05:26
  • @Er.nishka If you don’t want to switch over to the new androidx and com.google.android.material packages yet, you can use Material Components via the com.android.support:design:28.0.0 dependency. Note: You should not use the com.android.support and com.google.android.material dependencies in your app at the same time. Refer https://material.io/develop/android/docs/getting-started/ – Debanjan Jul 19 '19 at 11:59
  • @Debanjan thank you but I am also not using material dependencies – Er.nishka Jul 22 '19 at 06:38
  • @Er.nishka if you're facing this issue, even when you're not using material dependencies, then probably some of your dependency is transitively doing it. Check for transitive dependencies, using gradle, if that doesn't solve, post a separate question. – Debanjan Jul 22 '19 at 07:02
  • @Er.nishka Did you find the answer? How to target 28 and not use androidx. – Aman Verma Oct 28 '19 at 12:28
20

I wasted 2 days looking for a solution. Anyone who's still looking for a solution can follow the steps below:

  1. Update your Android Studio to the latest version.

  2. Update your compileSdkVersion and targetSdkVersion to 28.

    android {
    
        compileSdkVersion 28
    
        defaultConfig {
            applicationId "com.your.appid"
            minSdkVersion 19
            targetSdkVersion 28
            versionCode 50
            versionName "1.50"
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
            multiDexEnabled true
            setProperty("archivesBaseName", "your-app-$versionName")
            resConfigs "en"
         }
    }
    
  3. Go to your project structure and change your gradle version to 4.10.

  4. Add this dependency first:

    implementation 'com.google.android.material:material:1.0.0'
    
  5. Now remove all the support library dependencies:

    implementation "com.android.support:design:$SUPPORT_LIBRARY_VERSION"
    implementation "com.android.support:support-v4:$SUPPORT_LIBRARY_VERSION"
    implementation "com.android.support:appcompat-v7:$SUPPORT_LIBRARY_VERSION"
    implementation "com.android.support:recyclerview-v7:$SUPPORT_LIBRARY_VERSION"
    implementation "com.android.support:cardview-v7:$SUPPORT_LIBRARY_VERSION"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:multidex:1.0.3'
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    androidTestImplementation('com.android.support.test.espresso:espresso- 
       core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    exclude group: 'com.google.code.findbugs', module: 'jsr305'
    })
    
  6. Now paste the following into your gradle.properties file:

    android.useAndroidX = true
    android.enableJetifier = true
    
  7. In your project level build.gradle file:

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.1.0'
    };
    

For those who are using Butterknife add below lines in your project level build.gradle file:

allprojects {
    repositories {
    google()
    jcenter()
    maven { url "https://jitpack.io" }
    maven { url "https://dl.bintray.com/drummer-aidan/maven/" }
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
  }
}

And in your module build.gradle file add below dependencies:

 implementation "com.jakewharton:butterknife:9.0.0-SNAPSHOT"
 annotationProcessor "com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT"
  1. Now Goto Build > Rebuild Project then you might be getting a lot of errors.
  1. Now refer this link.

    It has the list of all the old (android.support) vs new (androidx.*) dependencies.

    Replace all your old imports with the new ones
    (Use replaceAll feature of android studio [ctrl + shift + R] which will save you some time).
  1. Finally After refactoring all the old libraries with the new ones:
    Rebuild the project again and hopefully it should work.

Note: You can also use Refactor > Migrate to androidx in android studio but it didn't work for me.

Ashu Tyagi
  • 1,400
  • 13
  • 25
  • Ignore this answer. Android Studio v3.2+ resolves the problem without rolling back to Support libraries that are abandoned. Use the "Migrate to AndroidX" feature under the Refactor menu and save yourself some headache! – Always Lucky Oct 08 '18 at 16:18
  • 1
    @AlwaysLucky I did try that but it didn't work for me. I mentioned it already in my answer. Anyways if it is working now that is even better. – Ashu Tyagi Oct 09 '18 at 08:49
  • 1
    So sorry, I commented on the wrong answer. I meant to comment on the accepted answer. What a noob mistake, haha. I appreciate the time and effort you put into the detail of your answer. I spent so many hours on this issue and all I did to resolve it was update to the AS 3.2 beta, so I was attempting to save others the time I wasted on this issue. – Always Lucky Oct 13 '18 at 17:14
  • just remember to clean the project at the end – has19 Nov 16 '18 at 18:22
  • @AshuTyagi please see https://meta.stackoverflow.com/questions/355274/change-quote-formatting-to-show-double-quote-marks/355299#355299 regarding the use of blockquotes.... – piet.t Jan 31 '19 at 09:35
  • I had to remove ButterKnife altogether to use AndroidX. Your Maven Settings and refactoring-->use AndroidX, indeed did not work. – Abhinav Saxena Feb 18 '19 at 10:47
6

I started getting this error after upgrading the ButterKnife to the version 8.8.1.

So, I run the command gradle -q dependencies to generate a dependency report, after that you should see where D8 is coming from. In my case from the "ButterKnife" library:

+--- com.jakewharton:butterknife:8.8.1
|    |    \--- com.android.support:support-compat:d8

Also you can see your android dependencies by going to your Android Studio Gradle view (In Android Studio tool bar navigate to "View/Tool Windows/Gradle"), and selecting the target "androidDependencies" under "My-Project-Name/Tasks/android" (Double click to run or Right click and run).

To solve this problem I added this piece of code exclude module: 'support-compat' to my "app/build.gradle" as below:

implementation ('com.jakewharton:butterknife:8.8.1') { 
     exclude module: 'support-compat' 
} 
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

Hope it works for someone else :] Cheers!

GFPF
  • 959
  • 14
  • 19
  • The appropriate way to handle this is to upgrade your Android Gradle plugin to at least version `3.2.0-alpha14` then make sure you have `android.enableJetifier=true` in your `gradle.properties` file. – Victor Rendina Sep 23 '18 at 14:46
  • Doing the exclude, gives me the following: Could not find method com.jakewharton:butterknife:8.8.1() for arguments [build_aay4rtv2iznrl6v18va02zedg$_run_closure2$_closure6@10afe254] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. – IainCunningham Sep 24 '18 at 13:05
5

Android Studio v3.2+ resolves this issue. It also adds a "Migrate to AndroidX" item under the Refactor menu. No work-around or rollback required.

Update Android Studio from the beta channel to use 3.2+ or wait until a stable version is released.

EDIT: Android Studio v3.2 is now in the stable channel. It is important you no longer use the support libraries and migrate to AndroidX libraries because support for the old support libraries has ended.

Always Lucky
  • 334
  • 3
  • 7
  • Updating to the latest Android Studio version and running Migrate to Android X solved the problem for me. – tmath Nov 29 '18 at 01:11
1

If you are including a library that has a transitive dependency on the Android support library you also have to use the jetifier feature that is part of the Android Gradle plugin version 3.2.0-alpha14 or higher. You can determine if you have a library that depends on the support library by running your Gradle dependencies task.

From the Android Developer's blog post (https://android-developers.googleblog.com/2018/05/hello-world-androidx.html):

If you depend on a library that references the older Support Library, Android Studio will update that library to reference androidx instead via dependency translation. Dependency translation is automatically applied by the Android Gradle Plugin 3.2.0-alpha14, which rewrites bytecode and resources of JAR and AAR dependencies (and transitive dependencies) to reference the new androidx-packaged classes and artifacts. We will also provide a standalone translation tool as a JAR.

In your gradle.properties file make sure that you have:

android.enableJetifier=true android.useAndroidX=true

I had this issue with Leak Canary on a small project and it was solved by upgrading the Android Gradle plugin to the appropriate version. https://github.com/square/leakcanary/issues/1103

Victor Rendina
  • 1,130
  • 12
  • 19
1

Go to app/build.gradle, in dependencies, remove this line:

implementation "com.android.support:appcompat-v7
Estevão Lucas
  • 4,440
  • 34
  • 37
0

Try to add

android.enableD8 = false

to gradle.properties file.

  • 1
    The error is now `com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex` for me. – Wei May 11 '18 at 15:22
  • `android.enableD8 = false` is deprecated. D8 is disabled by default. You can only use `android.enableD8 = true` to enable it. – gadgetroid May 12 '18 at 11:49
  • 1
    It is deprecated, but it also makes the build succeed for me - so setting to false has some side-effect not covered by the default. – Fisk Debug May 15 '18 at 08:36
0

Use this

   apply plugin: 'com.android.application'
   apply plugin: 'kotlin-android'

   android {
   compileSdkVersion 28
   defaultConfig {
       applicationId "ir.uncode.newdesign"
       minSdkVersion 16
       targetSdkVersion 27
       versionCode 1
       versionName "1.0"
       testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
   }
   buildTypes {
       release {
           minifyEnabled false
           proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguardrules.pro'
       }
    }
    }

   dependencies {
   implementation fileTree(dir: 'libs', include: ['*.jar'])
   implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
   implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
   implementation 'com.android.support:design:28.0.0-alpha3'
   implementation 'com.android.support.constraint:constraint-layout:1.1.1'
   implementation 'com.android.support:animated-vector-drawable:28.0.0-alpha3'}
   repositories {
    mavenCentral()
   }

and If the problem persists change "import" on class and xml.

like :

import androidx.fragment.app.Fragment;

import android.support.v4.app.Fragment;

or

import androidx.core.app.ActivityCompat;

import android.support.v4.app.ActivityCompat;

or

com.google.android.material.bottomappbar.BottomAppBar

android.support.design.bottomappbar.BottomAppBar
Akshay Nandwana
  • 1,260
  • 11
  • 18
Hamed Karami
  • 405
  • 1
  • 6
  • 28
  • Can you explain what you've changed compared to the original script and why? – Nico Haase Jun 19 '18 at 11:26
  • @NicoHaase , we don't need to use 'android-P' for compileSdkVersion and Instead it we use 28. 28.0.0-alpha1 and material:1.0.0-alpha1 had problem with a lot of library to me. and with change your gradle like this many problems are solved. and you don't need to add android.useAndroidX = true android.enableJetifier = false . I've tested it and i think maybe this help other developers. – Hamed Karami Jun 19 '18 at 12:52
  • @NicoHaase,I read the question again and I think better answer to your question is "why we want to use material:1.0.0-alpha1"?! .OK.the answer is because it, new material design . that's not important we use which one them.but we have a lot of problems if we use material:1.0.0-alpha1. Of course this is my experience ;). – Hamed Karami Jun 19 '18 at 13:40
  • My main motivation: you should highlight which very change solve the problem, instead of posting twenty lines of "use this"-code. If someone with a similar problem comes around, he should be able to simply see "It's this single line I have to change" – Nico Haase Jun 19 '18 at 14:07
0

If you want to use com.android.support:support-v4:28.0.0-alpha1,

then you have to use

com.android.support:design:28.0.0-alpha1

instead of

com.google.android.material:material:1.0.0-alpha1.

0

If you are using Android Studio V. 3.2.1 , You can simply go to the tools bar open Refactor -> migrate to AndroidX and Android studio will take care of the rest.

Zeyad Assem
  • 1,224
  • 9
  • 6
0

I am using android studio 3.3 version. I wasted my one and a half day looking for this solution. I tried all the answer in this post but nothing helped. Then I find the link which helped me to solve the error.

I removed the below dependency I added,

implemntation 'com.google.android.material:material:1.0.0'

Instead, I used android design support library,

implementation 'com.android.support:design:27.1.1'
Md Nakibul Hassan
  • 2,716
  • 1
  • 15
  • 19
0

try setting android.enableJetifier=true and android.useAndroidX=true in your gradle.properties file.

ahmed mostafa
  • 197
  • 2
  • 12
0

If you have 3.1.0 change to 3.2.0:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.0'
}
fcdt
  • 2,371
  • 5
  • 14
  • 26
0
  1. You need to move to androidx

  2. Remove all the imports which start with import android.support.*

  3. Change All imports to import androix.* and corresponding components.

jdk
  • 451
  • 1
  • 6
  • 18