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

Android编译报错Program type already present: android.support.v4.app.BackStackRecord$Op求助

Fixing "Program type already present: android.support.v4.app.BackStackRecord$Op" Error

Hey there, let's work through this frustrating duplicate dependency error you're hitting. This specific error almost always stems from either conflicting versions of Android support libraries in your project, or a mix of old support libraries and AndroidX components. Here are step-by-step fixes you can try right away:

1. Hunt down duplicate support library dependencies

First, let's identify if multiple versions of the same support library are being pulled in.

  • Open your app-level build.gradle file and scan through the dependencies block. Look for any repeated references to libraries like com.android.support:support-v4 or related support artifacts.
  • Run this command in your project's terminal to get a full breakdown of all dependencies and spot conflicts:
    ./gradlew app:dependencies
    
  • If you find a conflicting library being pulled in by a third-party dependency, exclude it explicitly. For example:
    implementation('com.example:third-party-lib:1.2.3') {
        exclude group: 'com.android.support', module: 'support-v4'
    }
    

Mixing old support libraries with AndroidX is a common cause of this error. AndroidX is the official replacement, so migrating will prevent future conflicts:

  1. In Android Studio, go to Refactor > Migrate to AndroidX...
  2. Follow the on-screen prompts to update all your project files and dependencies to their AndroidX equivalents.
  3. Ensure your gradle.properties file includes these two lines to enable Jetifier (which converts third-party support library uses to AndroidX):
    android.useAndroidX=true
    android.enableJetifier=true
    

3. Enforce consistent support library versions (if sticking with support libraries)

If you're not ready to migrate to AndroidX yet, force all dependencies to use the same support library version matching your compileSdkVersion (you're using 27, so stick to 27.x.x versions):
Add this inside the android block of your app-level build.gradle:

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.1'
        force 'com.android.support:appcompat-v7:27.1.1'
        // Add other support libraries you use here with the same version
    }
}

4. Clean and rebuild your project

Cached build files can sometimes cause odd lingering issues. Do a full clean and rebuild:

  • In Android Studio, click Build > Clean Project
  • Then click Build > Rebuild Project
  • If that doesn't help, delete the .gradle folder in your project root, restart Android Studio, and try building again.

If you can share the full dependencies block from your gradle file, we can zero in on the exact conflicting library. But these steps should resolve most cases of this error.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 08:31:15