Google material design library error Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy

半城伤御伤魂 提交于 2019-11-26 15:23:57

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.

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.

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!

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.

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

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

implementation "com.android.support:appcompat-v7

Try to add

android.enableD8 = false

to gradle.properties file.

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.

Hamed Karami

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

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.

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'

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!