I have only one Build.gradle file. My problem is that, when I'm trying to add new library for example gson inside dependency it fails
我只有一个版本。gradle文件。我的问题是,当我尝试在依赖项中添加新的库时,例如gson,它会失败
Failed to resolve: com.google.code.gson:gson:2.7
未能解决:com.google.code.gson:gson:2.7
This is my Build.gradle file
这是我的建立。gradle文件
apply plugin: 'com.android.application'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}
}
android {
compileSdkVersion 19
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1"
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDir 'libs'
}
instrumentTest.setRoot('tests')
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
buildTypes {
}
}
dependencies {
compile fileTree(include: '*.jar', dir: 'libs')
compile 'com.google.code.gson:gson:2.7'
// compile 'com.squareup.retrofit2:retrofit:2.1.0'
}
task clean(type: Delete) {
delete rootProject.buildDir
}
2 个解决方案
#1
1
You didn't declare any repository (for the actual project). You just declared repositories for build-script dependencies. Those are dependencies the build-script itself needs to run like custom tasks, plugins etc.
您没有声明任何存储库(对于实际的项目)。您刚刚声明了构建脚本依赖项的存储库。这些是构建脚本本身需要运行的依赖项,如自定义任务、插件等。
Add a repositories block outside the buildscript block and define where to search for project dependencies in there.
在buildscript块之外添加一个存储库块,并定义在其中搜索项目依赖项的位置。
#2
0
You can try with adding the jar files into the lib and adding it to the Gradle.
您可以尝试将jar文件添加到库中,并将其添加到渐变中。
dependencies {
compile files('libs/gson-x.x.x.jar')
}
you can download the jar from this link
您可以从这个链接下载jar
#1
1
You didn't declare any repository (for the actual project). You just declared repositories for build-script dependencies. Those are dependencies the build-script itself needs to run like custom tasks, plugins etc.
您没有声明任何存储库(对于实际的项目)。您刚刚声明了构建脚本依赖项的存储库。这些是构建脚本本身需要运行的依赖项,如自定义任务、插件等。
Add a repositories block outside the buildscript block and define where to search for project dependencies in there.
在buildscript块之外添加一个存储库块,并定义在其中搜索项目依赖项的位置。
#2
0
You can try with adding the jar files into the lib and adding it to the Gradle.
您可以尝试将jar文件添加到库中,并将其添加到渐变中。
dependencies {
compile files('libs/gson-x.x.x.jar')
}
you can download the jar from this link
您可以从这个链接下载jar