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

Android Studio添加Eclipse Paho库后出现‘Program type already present’错误的含义咨询

Fixing the "Program type already present" Conflict with Eclipse Paho & Android Support Library

Hey there, let's tackle that frustrating dependency conflict you're running into. The error Program type already present: android.support.v4.accessibilityservice.AccessibilityServiceInfoCompat happens because the Eclipse Paho library is bringing in its own version of the Android Support Library v4, which clashes with the one already in your project. Here are the most effective fixes, ordered by ease and effectiveness:

1. Exclude the Support Library from Paho's Dependencies

This is the quickest fix—just tell Gradle to ignore the support v4 library that comes bundled with Paho. If your original Paho dependency looks like this:

implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'

Update it to exclude the conflicting module:

implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.1.1') {
    exclude group: 'com.android.support', module: 'support-v4'
}

Now Paho will use the support v4 library already configured in your project instead of adding its own duplicate.

2. Force a Single Version of the Support Library

If excluding the dependency doesn't work, you might have inconsistent support library versions across your project. Force all dependencies to use the same version by adding this block to your project-level build.gradle file:

allprojects {
    repositories {
        // Keep your existing repo config here (Google, MavenCentral, etc.)
    }
    configurations.all {
        resolutionStrategy {
            // Replace with the support v4 version your project actually uses
            force 'com.android.support:support-v4:28.0.0'
        }
    }
}

Make sure to swap 28.0.0 with the version you're already using in your app module's build.gradle.

3. Migrate to AndroidX (Long-Term Solution)

If you're still using the old Support Library, migrating to AndroidX is Google's recommended fix for these kinds of conflicts. AndroidX replaces the old support libraries and includes Jetifier, which automatically converts third-party library dependencies (like Paho) to use AndroidX. Here's how to do it:

  • Add these two lines to your project's gradle.properties file:
android.useAndroidX=true
android.enableJetifier=true
  • Replace all old Support Library references in your app's build.gradle with their AndroidX equivalents (e.g., com.android.support:support-v4 becomes androidx.core:core:1.7.0)
  • Sync your Gradle project—Jetifier will handle converting Paho's internal support library references to AndroidX, eliminating the conflict.

4. Check Your Dependency Tree

If you're still unsure where the duplicate is coming from, run this command in Android Studio's Terminal to generate a full dependency tree:

# For macOS/Linux
./gradlew app:dependencies

# For Windows
gradlew app:dependencies

Search the output for support-v4—this will show you every dependency that's pulling in the library, so you can target the exact source of the conflict.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.22 08:09:24