【问题标题】:Google material design library error Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy谷歌材料设计库错误程序类型已经存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy
【发布时间】:2018-05-11 09:36:36
【问题描述】:

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

程序类型已存在: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)}

这是我的 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'
}

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

【问题讨论】:

    标签: java android android-gradle-plugin


    【解决方案1】:

    我也整天都在为这个问题苦苦挣扎。最后,我成功编译并运行了项目。

    首先,摆脱这个:

    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'
    

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

    android.useAndroidX = true
    android.enableJetifier = false
    

    最后,同步项目,然后编译。

    如果不起作用,请清理项目,然后重新构建。

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

    希望它也对你有用。

    【讨论】:

    • 虽然这最初似乎对我有用,但在我将 Room 添加到项目后,它现在抛出了同样的错误。
    • 请记住要使用 appcompatactivity 和其他内容,请查看此页面:-developer.android.com/topic/libraries/support-library/refactor
    • 不需要添加 'android.useAndroidX = true' 或 'android.enableJetifier = false'。只需确保您使用的是 AndroidX 支持库而不是 v4 或 v7 支持库。参考developer.android.com/topic/libraries/support-library/refactor
    • 大家好!我遇到了同样的问题,我尝试了上述解决方案,但没有奏效。 Android studio 3.1.3 Gradle 文件:
    • @SMGhost 在 gradle.properties 文件中。不要尝试在 build.gradle 上这样做
    【解决方案2】:

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

    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'
      };
      

    对于那些使用 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" }
      }
    }
    

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

     implementation "com.jakewharton:butterknife:9.0.0-SNAPSHOT"
     annotationProcessor "com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT"
    
    1. 现在转到 Build > Rebuild Project 那么您可能会遇到很多错误。
    1. 现在参考this 链接。

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

      新的 替换所有旧的导入
      (使用 android studio [ctrl + shift + R] 的 replaceAll 功能,这将为您节省一些时间)。李>
    1. 最后在用新库重构所有旧库之后:
      再次重建项目,希望它应该可以工作。

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

    【讨论】:

    • 忽略这个答案。 Android Studio v3.2+ 解决了该问题,而无需回滚到已放弃的支持库。使用 Refactor 菜单下的“Migrate to AndroidX”功能,省点麻烦!
    • @AlwaysLucky 我确实尝试过,但它对我不起作用。我已经在回答中提到了。无论如何,如果它现在可以工作,那就更好了。
    • 很抱歉,我评论了错误的答案。我的意思是评论接受的答案。真是一个菜鸟的错误,哈哈。感谢您为详细回答所付出的时间和精力。我在这个问题上花了很多时间,我所做的只是更新到 AS 3.2 测试版,所以我试图节省其他人在这个问题上浪费的时间。
    • 只记得最后清理项目
    • @AshuTyagi 请参阅meta.stackoverflow.com/questions/355274/… 关于块引用的使用....
    【解决方案3】:

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

    所以,我运行命令gradle -q dependencies 来生成依赖报告,之后您应该会看到 D8 的来源。就我而言,来自“ButterKnife”库:

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

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

    为了解决这个问题,我将这段代码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'
    

    希望它对其他人有用:] 干杯!

    【讨论】:

    • 处理此问题的适当方法是将您的 Android Gradle 插件升级到至少版本 3.2.0-alpha14,然后确保您的 gradle.properties 文件中有 android.enableJetifier=true
    • 进行排除,给了我以下信息:在 org.gradle 类型的对象上找不到参数 [build_aay4rtv2iznrl6v18va02zedg$_run_closure2$_closure6@10afe254] 的方法 com.jakewharton:butterknife:8.8.1() .api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
    【解决方案4】:

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

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

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

    【讨论】:

    • 更新到最新的 Android Studio 版本并运行 Migrate to Android X 为我解决了这个问题。
    【解决方案5】:

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

    来自 Android 开发者的博文 (https://android-developers.googleblog.com/2018/05/hello-world-androidx.html):

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

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

    android.enableJetifier=true android.useAndroidX=true

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

    【讨论】:

      【解决方案6】:

      进入app/build.gradle,在依赖项中,去掉这一行:

      implementation "com.android.support:appcompat-v7
      

      【讨论】:

      • 你能解释一下你为什么提出这个建议吗?
      【解决方案7】:

      尝试添加

      android.enableD8 = false
      

      到 gradle.properties 文件。

      【讨论】:

      • 我现在的错误是com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
      • android.enableD8 = false 已弃用。默认情况下禁用 D8。您只能使用android.enableD8 = true 来启用它。
      • 它已被弃用,但它也使我的构建成功 - 所以设置为 false 有一些默认值未涵盖的副作用。
      【解决方案8】:

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

      那么你必须使用

      com.android.support:design:28.0.0-alpha1

      而不是

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

      【讨论】:

        【解决方案9】:

        使用这个

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

        如果问题仍然存在,请更改类和 xml 上的“导入”。

        喜欢:

        import androidx.fragment.app.Fragment;
        
        import android.support.v4.app.Fragment;
        

        import androidx.core.app.ActivityCompat;
        
        import android.support.v4.app.ActivityCompat;
        

        com.google.android.material.bottomappbar.BottomAppBar
        
        android.support.design.bottomappbar.BottomAppBar
        

        【讨论】:

        • 您能解释一下与原始脚本相比您做了哪些更改以及原因吗?
        • @NicoHaase ,我们不需要使用 'android-P' 来编译 compileSdkVersion 而是我们使用 28. 28.0.0-alpha1 和 material:1.0.0-alpha1 有很多问题图书馆给我。像这样改变你的gradle,很多问题都解决了。而且您不需要添加 android.useAndroidX = true android.enableJetifier = false 。我已经对其进行了测试,我认为这可能对其他开发人员有所帮助。
        • @NicoHaase,我再次阅读了这个问题,我认为更好地回答你的问题是“为什么我们要使用材料:1.0.0-alpha1”?! .OK.答案是因为它,新材料设计。我们使用哪一个并不重要。但是如果我们使用材料:1.0.0-alpha1,我们会遇到很多问题。当然这是我的经验;)。
        • 我的主要动机:你应该强调哪些改变解决了问题,而不是发布二十行“使用这个”代码。如果遇到类似问题的人,他应该能够简单地看到“这是我必须更改的这一行”
        【解决方案10】:

        如果您使用的是 Android Studio V. 3.2.1 ,您只需前往工具栏打开 Refactor -> 迁移到 AndroidX,Android Studio 将完成其余工作。

        【讨论】:

          【解决方案11】:

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

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

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

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

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

          【讨论】:

            【解决方案12】:

            尝试设置android.enableJetifier=trueandroid.useAndroidX=true 在你的 gradle.properties 文件中。

            【讨论】:

              【解决方案13】:

              如果您有3.1.0 更改为3.2.0

              dependencies {
                  classpath 'com.android.tools.build:gradle:3.2.0'
              }
              

              【讨论】:

                【解决方案14】:
                1. 您需要转到androidx

                2. 删除所有以 import android.support.*

                3. 将所有导入更改为import androix.* 和相应的组件。

                【讨论】:

                  猜你喜欢
                  • 2019-01-25
                  • 1970-01-01
                  • 2019-02-02
                  • 2020-03-24
                  • 2018-11-29
                  • 2020-02-22
                  • 2019-09-07
                  • 2019-06-06
                  • 2018-09-25
                  相关资源
                  最近更新 更多