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

Android新项目启用DataBinding报错:找不到ActivityCompatApi23类

Fixing "class file for android.support.v4.app.ActivityCompatApi23 not found" with DataBinding

Hey David, sorry you're hitting this roadblock while setting up DataBinding—let's walk through some fixes that usually resolve this missing class error. It almost always boils down to mismatched support library versions or configuration oversights, so let's start checking:

  • Align all support library versions with your compileSdk
    Since your project uses compileSdkVersion 27, every support library dependency should use the same 27.x.x version. Mixing versions is a common culprit for missing class errors. Update your module-level build.gradle dependencies to look something like this:

    dependencies {
        implementation 'com.android.support:appcompat-v7:27.1.1'
        implementation 'com.android.support:support-v4:27.1.1'
        implementation 'com.android.support:design:27.1.1'
        // Add any other support libraries you need, all on 27.x.x
    }
    

    Double-check that there are no stray support libraries using older or newer versions hiding in your dependencies.

  • Confirm DataBinding is properly enabled
    It's easy to misplace this config—make sure the DataBinding toggle is in the right spot in your module's build.gradle:

    android {
        compileSdkVersion 27
        buildToolsVersion "27.0.3"
        flavorDimensions ""
    
        defaultConfig {
            minSdkVersion 19
            targetSdkVersion 22
            versionCode 24
            versionName "1.0"
        }
    
        // Make sure this block exists and is enabled
        dataBinding {
            enabled = true
        }
    }
    

    Sync your project after verifying this to ensure the changes take effect.

  • Clean out build caches and rebuild
    Android Studio's cached build files often cause weird class-not-found issues. Try these steps:

    1. Go to Build > Clean Project
    2. Then run Build > Rebuild Project
    3. If that doesn't work, delete the .gradle folder in your project root, restart Android Studio, and sync again.
  • Consider aligning targetSdkVersion with compileSdkVersion
    Your targetSdkVersion 22 is older than your compileSdkVersion 27. While this is technically allowed, support libraries for newer compileSdk versions can reference classes that expect a newer targetSdk. Updating targetSdk to 27 can eliminate this mismatch:

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27 // Match compileSdk here
        versionCode 24
        versionName "1.0"
    }
    
  • Verify buildToolsVersion is installed
    Head to Android Studio's SDK Manager (Tools > SDK Manager), go to the SDK Tools tab, and confirm that "Android SDK Build-Tools 27.0.3" is installed. If it's missing, install it and sync your project once more.

Give these steps a shot in order—most folks fix this error with the first two or three. Let me know if you're still stuck after trying all of them!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 04:09:37