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

报错:android.support.v7.widget.Toolbar未找到,附App级build.gradle代码

Fixing the android.support.v7.widget.Toolbar Not Found Error

Hey there, let's break down why you're hitting this error and how to fix it. The core issues here are mixed AndroidX/Support Library dependencies and version mismatches across your libraries—let's tackle them one by one.

Root Causes

  1. Mixed AndroidX and Support Libraries: You're using androidx.constraintlayout:constraintlayout:1.1.3 (an AndroidX library) alongside old Support Library dependencies like com.android.support:appcompat-v7. AndroidX and the old Support Library are incompatible, which leads to missing class errors.
  2. Inconsistent Support Library Versions: Your design/support-v4 dependencies use 28.0.0-rc01, while appcompat-v7 uses 28.0.3. Mismatched versions cause class conflicts or missing implementations.
  3. Firebase UI Version Mismatch: firebase-ui-database:3.2.2 isn't compatible with Support Library 28, which adds another layer of dependency conflict.

The old Support Library is deprecated, so migrating to AndroidX is the long-term fix. Here's how to adjust your build.gradle (app-level):

Step 1: Enable AndroidX in gradle.properties

Add these lines to your project-level gradle.properties file:

android.useAndroidX=true
android.enableJetifier=true

Jetifier automatically converts old Support Library dependencies to AndroidX, so you don't have to rewrite everything.

Step 2: Update Your App-Level build.gradle

Replace your dependencies with AndroidX equivalents, and use Firebase BOM to manage Firebase versions (avoids mismatches):

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 33 // Upgrade to a stable modern version
    buildToolsVersion "33.0.2"

    defaultConfig {
        applicationId "com.example.sscmessenger"
        minSdkVersion 19
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // AndroidX core libraries
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.9.0' // Replaces support:design
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'

    // Firebase BOM manages all Firebase dependency versions
    implementation platform('com.google.firebase:firebase-bom:32.4.0')
    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.firebase:firebase-database'

    // Firebase UI compatible with AndroidX
    implementation 'com.firebaseui:firebase-ui-database:8.0.0'

    testImplementation 'junit:junit:4.13.2'
}

Step 3: Update Your Layout XML

If your layout uses android.support.v7.widget.Toolbar, replace it with the AndroidX version:

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"/>

If you can't migrate right now, fix the version mismatches and remove AndroidX dependencies:

Updated App-Level build.gradle Dependencies

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    // 统一所有Support Library版本到稳定的28.0.0
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support:support-v4:28.0.0'
    // 替换AndroidX约束布局为Support版本
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'

    // Firebase UI compatible with Support Library 28
    implementation 'com.firebaseui:firebase-ui-database:4.3.2'
    // Firebase versions compatible with Support Library 28
    implementation 'com.google.firebase:firebase-auth:16.2.1'
    implementation 'com.google.firebase:firebase-database:16.1.0'

    testImplementation 'junit:junit:4.12'
}

After making either set of changes, clean and rebuild your project (Build > Clean Project then Build > Rebuild Project in Android Studio) to apply the fixes.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:25:09