You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加Google Material库后出现Program type already present编译错误求助

Fixing "Program type already present" Error with Material Library

Hey there, I know this error can feel frustrating when you're just getting started—let's break down what's going on and fix it!

What's Causing the Error?

The Program type already present message means the same Java class is being included in your project multiple times. Here's the root cause in your case:

  • The com.google.android.material:material:1.0.0-alpha1 library already includes all the functionality from the old com.android.support:design and com.android.support:support-v4 libraries (Material Components is the official successor to the Design Support Library).
  • By adding those two support libraries manually alongside Material, you're forcing duplicate class definitions into your build, which the D8 compiler can't resolve.

Step-by-Step Fix

  1. Remove the duplicate dependencies from your build.gradle file. You don’t need these anymore because Material Components covers their functionality:

    • implementation 'com.android.support:design:28.0.0-alpha1'
    • implementation 'com.android.support:support-v4:28.0.0-alpha1'
  2. Sync and rebuild your project: Click the "Sync Project with Gradle Files" button (the elephant icon) in Android Studio, then try building your project again.

Modified build.gradle Example

Here's what your dependencies block should look like after the fix:

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

Bonus Tip for Future Conflicts

If you run into similar dependency issues later, you can check your full dependency tree to spot duplicates. Open the terminal in Android Studio and run:

./gradlew app:dependencies

This will show you every library your project depends on. If you find a duplicate, you can exclude it from a specific dependency like this:

implementation 'some.third-party:library:1.0' {
    exclude group: 'com.android.support', module: 'support-v4'
}

内容的提问来源于stack exchange,提问作者Smart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:15:47