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

Android Compile SDK 30环境下库构建失败求助(新手开发者)

问题原因

Android Support库的最高稳定版本是28.0.0,Google从Android 10(API Level 29)开始就停止了对Support库的更新,全面转向AndroidX。你引用的com.android.support:*:30.0.0这类依赖根本不存在,所以构建时无法找到对应的库文件。

解决方案

1. 替换所有Support库依赖为AndroidX对应库

把你的依赖配置替换成以下内容:

implementation fileTree(dir: 'libs', include: ['*.jar'])
// testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.browser:browser:1.5.0'
implementation 'androidx.media:media:1.6.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

implementation 'com.google.firebase:firebase-core:21.0.0'
implementation 'com.google.firebase:firebase-database:20.0.5'

注:Firebase Database 17.0.0版本较老,建议升级到适配AndroidX的最新稳定版(上述版本为示例,可根据Android Studio提示选择最新版)

2. 调整Gradle配置中的工具版本

修改buildToolsVersion为与Compile SDK 30匹配的版本:

android {
    compileSdkVersion 30
    buildToolsVersion '30.0.3'

    defaultConfig {
        applicationId "com.mayapp"
        minSdkVersion 17
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
    }
}

3. 确保启用AndroidX

在项目根目录的gradle.properties文件中添加以下配置(若未存在):

android.useAndroidX=true
android.enableJetifier=true

Jetifier会自动转换第三方库中的Support库引用为AndroidX,避免兼容问题。

4. 同步并重建项目

  • 点击Android Studio右上角的Sync Project with Gradle Files按钮
  • 执行Build > Clean Project和Build > Rebuild Project

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 08:54:23