如何在Android Studio中的Gradle for Project中添加Git依赖项和实现

ocebsuys  于 2023-10-19  发布在  Android
关注(0)|答案(1)|浏览(107)

你好,我是新的android应用程序开发,到目前为止,我试图使一个android应用程序,让你阅读和显示pdf文件的应用程序内部以下一些在线指南.主要的问题来的时候,我需要从github导入一个依赖,以便能够读取和显示文件(com.github.barteksc:android-pdf-viewer:2.8.2)我得到了一堆错误,一些来自系统无法定位所述依赖的文件和函数,gradle build无法定位git repo
我的项目Setings

  • Kotlin作为主要语言
    -Android 8.0(oreo)作为SDK
    -Android Studio Giraffe| 2022.3.1作为IDE
    我读到的一些解决方案是,我必须首先在gradle文件的“allprojects”块中添加“jitpack”,以便能够导入依赖项。
allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

我的gradle文件如下
build.gradle.kts(项目)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id("com.android.application") version "8.1.2" apply false
    id("org.jetbrains.kotlin.android") version "1.9.0" apply false
}

build.gradle.kts(模块:app)

plugins {
    id("com.android.application")
    id("org.jetbrains.kotlin.android")
}

android {
    namespace = "com.example.pdfviewtest"
    compileSdk = 33

    defaultConfig {
        applicationId = "com.example.pdfviewtest"
        minSdk = 26
        targetSdk = 33
        versionCode = 1
        versionName = "1.0"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = 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.9.0")
    implementation("androidx.appcompat:appcompat:1.6.1")
    implementation("com.google.android.material:material:1.8.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")

    //dependency I want to add
    implementation("com.github.barteksc:android-pdf-viewer:2.8.2")

    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}

settings.gradle.kts

pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()

    }
}

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "Pdfviewtest"
include(":app")

在我的gradle文件中没有一个“allprojects”块,并且在属于pluginManagement和dependencyResolutionManagement的存储库中添加jitpack没有工作,我不知道是我做错了什么,还是有一个设置我需要首先修改。希望有人能帮忙

qv7cva1a

qv7cva1a1#

你可以试试这种方式,在设置。gradle:

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

在build.gradle(项目级),添加jcenter():

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }
}

相关问题