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

新手上路,请多包涵

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

程序类型已经存在:android.support.v4.app.INotificationSideChannel\(Stub\)Proxy Message{kind=ERROR, text=程序类型已经存在:android.support.v4.app.INotificationSideChannel\(Stub\)Proxy, sources=[Unknown source file], 工具名=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'
}

我是这类错误的新手,我没有发现任何与此错误相关的信息。谢谢

原文由 Smart 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 568
2 个回答

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

首先,摆脱这个:

 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'

}

希望它也对你有用。

原文由 Alvaro Santa Cruz 发布,翻译遵循 CC BY-SA 4.0 许可协议

我浪费了 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"
        }
   }

  1. 转到您的项目结构并将您的 gradle 版本更改为 4.10

  2. 先添加这个依赖:

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

  1. 现在删除所有支持库依赖项:
    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'
   })

  1. 现在将以下内容粘贴到您的 gradle.properties 文件中:
    android.useAndroidX = true
   android.enableJetifier = true

  1. 在您的项目级 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. 现在参考 这个 链接。

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

的替换所有 旧的导入

(使用 android studio [ctrl + shift + R] 的 replaceAll 功能可以节省您一些时间)。

  1. 最后在用新库重构所有旧库之后:

再次重建项目,希望它能正常工作。

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

原文由 Ashu Tyagi 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题