android - 如何修复“Android MPAndroidChart 找不到方法 dependencyResolutionManagement() 用于 gradle 中的参数错误”?
问题描述
好吧,我尝试在 Android Studio 中使用 MPAndroidChart 库,我的 gradle 版本是 7.0.2,但效果不佳。所以我将 gradle 版本更改为 6.7.1,并将 Android Gradle 插件版本更改为 4.2.2 我还将 sdk 的版本更改为 Android 11.0(R) 我的目标 SDK 版本是 30
--build.gradle(项目)
// Top-level build file where you can add configuration options common to all sub-
projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects{
repositories{
google()
mavenCentral()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--build.gradle(模块)
plugins {
id 'com.android.application'
}
android {
compileSdk 31
BuildToolsVersion '30.0.3'
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories{
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
--setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
}
}
rootProject.name = "My Application"
include ':app'
--捕获错误 在此处输入图像描述
--bug 代码 设置文件'C:\Users\kimta\AndroidStudioProjects\MyApplication\settings.gradle' 行:1
评估设置“MyApplication”时出现问题。
在 org.gradle.initialization.DefaultSettings 类型的设置“MyApplication”上找不到参数 [settings_5pc4jcjs87c9dkfx5manehm0u$_run_closure1@69c68d91] 的方法 dependencyResolutionManagement()。
对于像我这样的新手来说,gradle 问题太难了。有什么解决办法吗?
解决方案
您尝试将此行添加到您的settings.gradle
:
maven { url 'https://jitpack.io' }
--setting.gradle
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
maven { url 'https://jitpack.io' } //Add this line in your settings.gradle
}
}
rootProject.name = "My Application"
include ':app'
--build.gradle(项目)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
--build.gradle(模块)
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.myapplication"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
// MPAndroidChart
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
}
推荐阅读
- postgresql - 错误:无效的正则表达式:在 Postgres 11.0 中执行左连接时括号 () 不平衡
- azure-logic-apps - Add an Azure AD user to a Azure DevOps project group using Azure Logic Apps
- shell - 检查字符串是否计算为 zsh 中变量的名称 - 间接扩展
- swift - 如何动画删除使用 ForEach 循环创建的视图从 SwiftUI 中的 ObservableObject 获取其数据
- android - Android如何在不改变视图可见性的情况下调用绑定适配器?
- node.js - 使用 Sequelize 为请求 Node.Js 中给出的现有字段更新数据库
- react-native - react-native svg-charts中的X轴标签未正确显示
- python - 你能帮我让 Selenium 在 Chromedriver 中单击图像吗?
- godot - 如何将信号添加到使用 add_child 创建的对象
- php - 在选择 WooCommerce 产品变体价格后添加自定义字段值