Java 谷歌材料设计库错误程序类型已经存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50289355/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 23:32:36  来源:igfitidea点击:

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

javaandroidandroid-gradle-plugin

提问by Smart

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

每当我implemntation 'com.google.android.material:material:1.0.0-alpha1'尝试构建我的项目时添加Android Studio 说:

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)}

程序类型已经存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy Message{kind=ERROR, text=程序类型已经存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy, sources=[Unknown source文件],工具名称=Optional.of(D8)}

This is my gradle script:

这是我的gradle脚本:

    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

我是新来的这种类型的错误,我没有发现这个错误。谢谢

采纳答案by Alvaro Santa Cruz

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:

在 gradle.properties 文件中添加以下内容:

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:

PS:我无法让 targetSdkVersion 'p' 工作。我的 build.gradle 文件最终如下:

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.

希望它也适用于你。

回答by Ihar Paliashchuk

Try to add

尝试添加

android.enableD8 = false

to gradle.properties file.

到 gradle.properties 文件。

回答by 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.

如果问题仍然存在,请更改类和 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

回答by GFPF

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

将 ButterKnife 升级到 8.8.1 版后,我开始收到此错误。

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

因此,我运行该命令gradle -q dependencies以生成依赖关系报告,之后您应该会看到 D8 的来源。在我的例子中来自“ButterKnife”库:

+--- 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).

您还可以通过转到 Android Studio Gradle 视图(在 Android Studio 工具栏中导航到“View/Tool Windows/Gradle”),然后在“My-Project-Name/Tasks/”下选择目标“androidDependencies”来查看您的 android 依赖项android”(双击运行或右键单击运行)。

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

为了解决这个问题,我将这段代码添加exclude module: 'support-compat'到我的“app/build.gradle”中,如下所示:

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!

希望它适用于其他人:] 干杯!

回答by KRIPA SHANKAR JHA

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

then you have to use

如果你想使用 com.android.support:support-v4:28.0.0-alpha1

那么你必须使用

com.android.support:design:28.0.0-alpha1

com.android.support:design:28.0.0-alpha1

instead of

代替

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

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

回答by Always Lucky

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.

Android Studio v3.2+ 解决了这个问题。它还在 Refactor 菜单下添加了“Migrate to AndroidX”项。无需解决方法或回滚。

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

从 beta 通道更新 Android Studio 以使用 3.2+ 或等待稳定版本发布。

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.

编辑:Android Studio v3.2 现在处于稳定通道。重要的是您不再使用支持库并迁移到 AndroidX 库,因为对旧支持库的支持已经结束。

回答by Victor Rendina

If you are including a library that has a transitive dependency on the Android support library you also have to use the jetifierfeature 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 dependenciestask.

如果您包含的库对 Android 支持库具有传递依赖关系,您还必须使用jetifierAndroid Gradle 插件版本 3.2.0-alpha14 或更高版本中的功能。您可以通过运行 Gradledependencies任务来确定您是否有依赖于支持库的库。

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

来自 Android 开发者的博文(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.

如果您依赖引用旧支持库的库,Android Studio 将更新该库以通过依赖关系转换来引用 androidx。Android Gradle Plugin 3.2.0-alpha14 会自动应用依赖关系转换,它会重写 JAR 和 AAR 依赖项(以及传递依赖项)的字节码和资源以引用新的 androidx 打包类和工件。我们还将提供一个独立的翻译工具作为 JAR。

In your gradle.propertiesfile make sure that you have:

在您的gradle.properties文件中,请确保您有:

android.enableJetifier=true android.useAndroidX=true

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

我在一个小项目中遇到了 Leak Canary 的这个问题,它通过将 Android Gradle 插件升级到适当的版本来解决。https://github.com/square/leakcanary/issues/1103

回答by Ashu Tyagi

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

我浪费了 2 天寻找解决方案。任何仍在寻找解决方案的人都可以按照以下步骤操作:

  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.propertiesfile:

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

    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
        classpath 'com.google.gms:google-services:4.1.0'
    };
    
  1. 将您的 Android Studio 更新到最新版本。

  2. 将 compileSdkVersion 和 targetSdkVersion 更新为 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. 转到您的项目结构并将您的 gradle 版本更改为4.10

  4. 首先添加此依赖项:

    implementation 'com.google.android.material:material:1.0.0'
    
  5. 现在删除所有支持库依赖项:

    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. 现在将以下内容粘贴到您的gradle.properties文件中:

    android.useAndroidX = true
    android.enableJetifier = true
    
  7. 在您的项目级build.gradle文件中:

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

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

对于那些使用Butterknife 的人,在你的项目级 build.gradle 文件中添加以下行:

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.gradlefile add below dependencies:

并在您的模块build.gradle文件中添加以下依赖项:

 implementation "com.jakewharton:butterknife:9.0.0-SNAPSHOT"
 annotationProcessor "com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT"
  1. Now Goto Build > Rebuild Projectthen you might be getting a lot of errors.
  1. 现在转到Build > Rebuild Project那么你可能会遇到很多错误。
  1. Now refer thislink.

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

    Replace all your old importswith the newones
    (Use replaceAll feature of android studio [ctrl + shift + R] which will save you some time).
  1. 现在参考这个链接。

    它包含所有(android.support) 和(androidx.*) 依赖项的列表。

    替换所有的旧进口的人
    (机器人工作室[Ctrl + Shift + R]这将节省您的时间使用的replaceAll功能)。
  1. Finally After refactoring all the old libraries with the new ones:
    Rebuild the project again and hopefully it should work.
  1. 最后在用新库重构所有旧库之后:
    再次重建项目,希望它可以工作。

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

注意:您也可以在 android studio 中使用Refactor > Migrate to androidx但它对我不起作用。

回答by Zeyad Assem

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.

如果您使用的是 Android Studio V. 3.2.1 ,您只需转到工具栏打开 Refactor -> migrate to AndroidX,Android Studio 将处理其余的工作。

回答by Md Nakibul Hassan

I am using android studio 3.3version. 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.

我正在使用 android studio 3.3版本。我浪费了一天半的时间寻找这个解决方案。我尝试了这篇文章中的所有答案,但没有任何帮助。然后我找到了帮助我解决错误的链接。

I removed the below dependency I added,

我删除了我添加的以下依赖项,

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

Instead, I used android design support library,

相反,我使用了android设计支持库,

implementation 'com.android.support:design:27.1.1'