将“com.github.persian-calendar:calendar”添加到空的 android 项目时出现问题?

Problem adding "com.github.persian-calendar:calendar" to an empty android project?

提问人:Sepidehye Fanavari 提问时间:9/24/2022 更新时间:9/25/2022 访问量:100

问:

将“com.github.persian-calendar:calendar:1.2.1”添加到空的android项目的正确步骤是什么?我尝试了包括本指南在内的不同方法,但 Gradle 抱怨所有这些方法。

Build.gradle(项目):

buildscript {
        ext {   compose_version = '1.2.0'   }
    }
    plugins {
        id 'com.android.application' version '7.4.0-alpha10' apply false
        id 'com.android.library' version '7.4.0-alpha10' apply false
        id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
    }
    allprojects {
        repositories {
            maven("https://jitpack.io")
        }
    }

Build.gradle (模块):

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
}

android {
    namespace 'com.example.trash2'
    compileSdk 32

    defaultConfig {
        applicationId "com.example.trash2"
        minSdk 24
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    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'
    }
    buildFeatures {
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion '1.2.0'
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {
    implementation("com.github.persian-calendar:calendar:1.2.1")

    ...
}

错误:

org.gradle.api.GradleScriptException:评估根项目“trash2”时出现问题。......原因:org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException:在 org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler 类型的存储库容器上找不到参数 [https://jitpack.io] 的方法 maven()。

安卓 android-gradle-plugin

评论


答:

1赞 AmirMohamamd 9/25/2022 #1

步骤 1 :

Use  maven { url 'https://jitpack.io' }  instead of  maven("https://jitpack.io")

步骤 2 :

Put  maven { url 'https://jitpack.io' }  in settings.gradle :

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}