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

2022-01-13 00:00:00 android android-gradle-plugin java

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

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

程序类型已存在:android.support.v4.app.INotificationSideChannel$Stub$ProxyMessage{kind=ERROR, text=Program type already present: android.support.v4.app.INotificationSideChannel$Stub$Proxy, sources=[Unknown source file], tool name=Optional.of(D8)}

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

这是我的 gradle 脚本:

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

推荐答案

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

I've been struggling all day with this issue too. Finally I managed to compile and run the project successfully.

首先,摆脱这个:

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 文件中添加以下内容:

Add the following in your gradle.properties file:

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:我无法让 targetSdkVersion 'p' 工作.我的 build.gradle 文件最终如下:

PS: I can't get targetSdkVersion 'p' to work. My build.gradle file end up as follows:

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'

}

希望它也对你有用.

相关文章