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

2022-09-01 03:36:24

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

程序类型已存在:android.support.v4.app.INotificationSideChannel$Stub$Proxy Message{kind=ERROR, text=Program type 已存在: android.support.v4.app.INotificationSideChannel$Stub$Proxy, sources=[未知源文件], 工具名称=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'
}

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


答案 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'

}

希望它也对你有用。


答案 2

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

  1. 将您的安卓工作室更新到最新版本。

  2. 将编译SdkVersion和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. 现在转到构建>重建项目,那么您可能会遇到很多错误。
  1. 现在参考链接。

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

    新的替换所有旧的导入
    (使用替换Android工作室的所有功能[ctrl + shift + R],这将节省一些时间)。
  1. 最后,在用新库重构所有旧库之后:
    再次重新生成项目,希望它应该可以正常工作。

注意:您也可以使用重构>迁移到android studio中的androidx,但它对我不起作用。


推荐