Google material design library error Program type

2020-01-23 07:38发布

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

12条回答
家丑人穷心不美
2楼-- · 2020-01-23 07:52

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.

查看更多
聊天终结者
3楼-- · 2020-01-23 07:52

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
查看更多
The star\"
4楼-- · 2020-01-23 07:55

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

implementation "com.android.support:appcompat-v7
查看更多
【Aperson】
5楼-- · 2020-01-23 08:00

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'
查看更多
来,给爷笑一个
6楼-- · 2020-01-23 08:04

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.

查看更多
做自己的国王
7楼-- · 2020-01-23 08:05

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

查看更多
登录 后发表回答