摇篮无法解决Android Studio中的依赖 [英] Gradle fails to resolve dependency in Android Studio
问题描述
我已导入在Android的Studio中的PhoneGap项目,我做了一个基于摇篮项目。结果
现在我想要编译一些外部依赖,我得到这个错误:
I have imported a Phonegap project in Android Studio and I made it a Gradle-based project.
Now I'm trying to compile some external dependencies and I get this error :
错误:(72,13)无法解析:com.loopj.android:android-async-http:1.4.6
在显示结果的文件中显示项目结构对话框
Error:(72, 13) Failed to resolve: com.loopj.android:android-async-http:1.4.6 Show in File
Show in Project Structure dialog
我试过在文件 - > ProjectStructure->相关性去和自动,并称他们添加这些依赖关系。 Android的工作室找到了该库和他加入他们在我的build.gradle但我仍然得到同样的错误...
I've tried to add those dependencies by going in File-> ProjectStructure-> Dependencies and adding them "automatically". Android Studio do find the libraries and he add them in my build.gradle but I still get the same error...
这是我的build.gradle文件的一部分(的依赖是在底部):
here is a part of my build.gradle file (the dependencies are at the bottom) :
import java.util.regex.Pattern
apply plugin: 'android'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0+'
}
}
ext.multiarch=false
android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
defaultConfig {
versionCode Integer.parseInt("" + getVersionCodeFromManifest() + "0")
}
compileSdkVersion 21
buildToolsVersion "21.0.0"
if (multiarch || System.env.BUILD_MULTIPLE_APKS) {
productFlavors {
armv7 {
versionCode defaultConfig.versionCode + 2
ndk {
abiFilters "armeabi-v7a", ""
}
}
x86 {
versionCode defaultConfig.versionCode + 4
ndk {
abiFilters "x86", ""
}
}
all {
ndk {
abiFilters "all", ""
}
}
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.loopj.android:android-async-http:1.4.6'
compile 'org.altbeacon:android-beacon-library:2+@aar'
for (subproject in getProjectList()) {
compile project(subproject)
}
}
感谢您的帮助:)
thanks for any help :)
推荐答案
这不应该是里面的 buildscript
,保持外 buildscript
。使用 jcenter()
或 mavenCentral()
上根据您的要求。
this should not be inside buildscript
, keep it outside buildscript
. use jcenter()
or mavenCentral()
on depending your requirement.
repositories {
mavenCentral()
}
另外你正在使用错误的插件。如果建设应用,使用
Also you are using wrong plugin. if building for app, use
apply plugin: 'com.android.application'
如果建立图书馆,使用
apply plugin: 'com.android.library'
这篇关于摇篮无法解决Android Studio中的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!