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

如何修复与Plugin和SDK版本相关的Android运行错误?

解决Android Plugin与SDK版本不兼容错误

运行Android应用时出现Plugin和SDK版本相关错误,尝试移除maven-publish插件后问题仍未解决,当前使用SDK版本34,模块build.gradle代码如下:

apply plugin: 'com.android.library'
apply plugin: 'maven-publish'

ext {
    bintrayRepo = 'maven'
    bintrayName = 'material-hijri-calendarview'

    publishedGroupId = 'com.github.eltohamy'
    libraryName = 'material-hijri-calendarview'
    artifact = 'material-hijri-calendarview'

    libraryDescription = 'A Material design back port of Android\'s Hijri CalendarView. The goal is to have a Material look and feel, rather than 100% parity with the platform\'s implementation.'

    siteUrl = 'https://github.com/eltohamy/material-hijri-calendarview'
    gitUrl = 'hhttps://github.com/eltohamy/material-hijri-calendarview.git'

    libraryVersion = '1.1.2'

    developerId = 'eltohamy'
    developerName = 'El-Tohamy Allam'
    developerEmail = 'tohamy_allam@yahoo.com'

    licenseName = 'The Apache Software License, Version 2.0'
    licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
    allLicenses = ["Apache-2.0"]
}
android {
    compileSdkVersion 30
    buildToolsVersion "29.0.3"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 31
    }
}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation group: 'com.github.msarhan', name: 'ummalqura-calendar', version: '1.1.9'

    testImplementation 'junit:junit:4.13'

}
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'

解决方案

1. 对齐SDK与编译配置版本

当前使用SDK 34,但模块配置里的编译版本未匹配,修改如下:

android {
    compileSdkVersion 34
    buildToolsVersion "34.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 34
    }
}

2. 解决发布脚本与插件冲突

项目中引入的JCenter旧发布脚本可能与maven-publish或新版Android Gradle Plugin(AGP)不兼容:

  • 如果仅需本地运行,可暂时注释这两行:
    // apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/installv1.gradle'
    // apply from: 'https://raw.githubusercontent.com/nuuneoi/JCenter/master/bintrayv1.gradle'
    
  • 如果需要发布,建议替换为适配新版AGP的发布流程(比如Maven Central官方发布脚本)

3. 匹配根目录AGP版本

项目根目录build.gradle中的AGP版本需与compileSdkVersion 34匹配,推荐使用7.4.0以上稳定版:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.2'
    }
}

4. 同步项目并清理缓存

  • 点击Android Studio工具栏的Sync Project with Gradle Files同步配置
  • 执行File > Invalidate Caches... > Invalidate and Restart清理缓存并重启IDE

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 23:37:47