我有android studio的问题。
我已经从这个链接添加了okhttp的.jar文件:https://github.com/square/okhttp到我的android studio上的libs目录。当我尝试添加这一行时:在build.gradle(Module:app)的依赖项中编译'com.squareup.okhttp3:okhttp:3.2.0',在尝试同步之后我得到错误28,13。实际上之后研究我发现我无法编译依赖项中的任何内容并同步它记住我已经检查了我的“android SDK构建工具”已安装。
听到我在build.gradle(app)目录中的全部代码:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.kasra.stormy"
minSdkVersion 14
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.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/okhttp-3.2.0.jar')
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
如果有人帮助我解决这个问题,我将非常高兴和感激。
非常感谢你:)
您的互联网是坏的,您无法从JCenter下载该文件,或者您只是在gradle文件中缺少repositories
部分。
apply plugin: 'com.android.application'
repositories {
jcenter()
}
此外,如果您要使用gradle而不是JAR文件进行编译,则删除文件libs/okhttp-3.2.0.jar
并删除说compile files('libs/okhttp-3.2.0.jar')
的行。
还值得一提的是,您不需要任何以compile files('libs/
开头的行,因为compile fileTree(dir: 'libs', include: ['*.jar'], )
已经包含了libs/
文件夹中的所有JAR文件。
只需删除compile files('libs/okhttp-3.2.0.jar')
我通过编辑build.gradle解决了我的问题,如下所示:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':library')
//compile('com.squareup.okhttp3:okhttp:+') {
// exclude group: 'org.json'
//}
//replaced as below:
compile 'com.squareup.okhttp3:okhttp:3.9.1'
}
你应该改变build.gradle(app):use
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
代替
compile 'com.squareup.okhttp3:okhttp:3.2.0'
或者只是按照here提到的指南。
检查app.gradle中的代码
apply plugin: 'com.android.application'
repositories {
jcenter()}
要么
使你的编译okhttp进入离线模式,然后在设置 - > gradle中取消选中离线模式。然后再试一次