首页 > 解决方案 > 如何修复“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 问题太难了。有什么解决办法吗?

标签: androidgradlempandroidchart

解决方案


您尝试将此行添加到您的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'
}

推荐阅读