【问题标题】:Add specific repository to build file添加特定存储库以构建文件
【发布时间】:2016-10-09 20:37:00
【问题描述】:

问题:我想将 library 包含到我的项目中。当我添加依赖项时,我得到:

无法解决:com.github.glomadrian:loadingballs1.1

问题:如何更改我的 gradle 文件才能解决问题?我认为这与添加存储库 maven 有关。如果是这样,我必须在哪里正确放置?

注意:我找到了一个post,它似乎可以回答我的问题,但不幸的是我仍然遇到了这个问题。

图书馆给出了一个小教程:

将特定的存储库添加到您的构建文件中:

他们的示例代码:

repositories {
    maven {
        url "https://jitpack.io"
    }
}

我已将 maven 存储库添加到我的构建文件中:

build.gradle(项目)

   buildscript {
    repositories {
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'

        //Maven plugin
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        maven { url "https://jitpack.io" }
    }

}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle (Module:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.stack.overflow"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    (...)
    compile 'com.github.glomadrian:loadingballs:1.1@aar'

}

【问题讨论】:

    标签: android android-studio gradle dependencies


    【解决方案1】:

    是的,您需要将存储库添加到您的 gradle 配置中,或者在您的项目 build.gradle 中,如下所示:

    allprojects {
        repositories {
            jcenter()
            maven {
                url "http://dl.bintray.com/glomadrian/maven"
            }
        }
    }
    

    或到模块:app build.gradle 像这样:

    apply plugin: 'com.android.application'
    
    android {
        (... your config...)
    }
    
    repositories {
        maven {
            url "http://dl.bintray.com/glomadrian/maven"
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        testCompile 'junit:junit:4.12'
        (... more dependencies ...)
        compile 'com.github.glomadrian:loadingballs:1.1@aar'
    
    }
    

    【讨论】:

    • 我应该使用哪个版本?是的,我已经在项目 gradle 文件中读到,它将应用于模块内部的所有内容和特定模块。但我一直误解这一点。当我添加依赖项时,它在整个项目中都可用,对吗?那么如果我使用在 build.gradle 模块应用文件中包含该库,它将在哪里无法访问?
    • 是的,如果将存储库添加到 module:app (第二个版本),它只会在那里可用,这就是它的首选方式。除非需要,否则不要向项目 build.gradle 添加依赖项。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-19
    • 1970-01-01
    • 2021-12-12
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    相关资源
    最近更新 更多