【问题标题】:Unable To add dependencies in android studio无法在android studio中添加依赖项
【发布时间】:2016-10-13 11:14:02
【问题描述】:

如何使用 build.gradle 文件在 android studio 中添加库

这是我的 build.gradle(Module) 文件

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.example.akshay.popupdemo"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 7
    versionName "1.0.7"
    multiDexEnabled true
}
packagingOptions {
    exclude 'META-INF/LGPL2.1'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE'
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
dexOptions {
    javaMaxHeapSize "4g"
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.scottyab:secure-preferences-lib:0.1.3'
compile 'com.google.code.gson:gson:2.3'
compile 'com.esri.arcgis.android:arcgis-android:10.2.7'
}

还有我的 build.gradle(project) 文件

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url 'http://dl.bintray.com/esri/arcgis'
        }
    }
}

我收到以下错误

   D:\Yogesh_Kadam_Projects\Android-Projects\Current Projects\PopUpDemo\app\build.gradle
    Error:Error:line (36)Failed to resolve: com.scottyab:secure-preferences-lib:0.1.3
    Error:Error:line (37)Failed to resolve: com.google.code.gson:gson:2.3
    Error:Error:line (38)Failed to resolve: com.esri.arcgis.android:arcgis-android:10.2.7

我知道如何使用库文件夹添加,然后使用项目结构对话框添加依赖项。

如何使用 build.gradle 文件添加库?

我应该在android studio中进行什么设置才能自己下载库? 请解释一下。

Log IMAGE

【问题讨论】:

  • 提供完整的错误日志
  • 这很奇怪。我想离线工作已启用。检查Preferences > Build, Exceution, Deployment > Gradle > offline work 未选中。
  • @nshmura 离线工作已被禁用
  • 嗯...这可能是网络连接或代理设置等连接问题。
  • @nshmura 代理工作正常

标签: android android-studio android-gradle-plugin build.gradle


【解决方案1】:

@yogesh

尝试使用 Module Setting -> Dependencies -> Library Dependency 添加依赖项

在搜索区域粘贴依赖路径 例如。 com.google.code.gson:gson 这将使用正确的版本搜索并纠正依赖关系

【讨论】:

    猜你喜欢
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    相关资源
    最近更新 更多