Eclipse在Android Studio中导出项目并在build.gradle中添加远程依赖项

时间:2014-06-09 12:58:12

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

我已将Eclipse中的Android项目导出为gradle构建文件,并在Android Studio中导入。

我今天将我的Android Studio更新为v0.6.0,该版本于2014年6月5日生效。

作为远程依赖项,我已将AppCompat添加到依赖项中,这可以正常工作。

compile 'com.android.support:appcompat-v7:19.+'

但是当我尝试添加其他库,例如SmoothProgressBaractionbarsherlocknineoldandroids等时,它就失败了。当我运行应用程序时,它会在Gradle Build选项卡中显示以下内容:

Error:A problem occurred configuring root project 'MyApp'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
   > Could not find com.github.castorflex.smoothprogressbar:library:0.5.1.
     Required by:
         :MyApp:unspecified

当我将项目与Gradle文件同步时,它会在Gradle Sync选项卡中显示以下内容:

Error:com.github.castorflex.smoothprogressbar:library:0.5.1 (double-click here to find usages.)

我尝试了一个空的新项目,并为所提到的库(Sherlock等)添加远程依赖项按预期工作。那么I guess I missed something in build.gradle还是其他任何解决方案?

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.11.+'
    }
}
apply plugin: 'android'

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.github.castorflex.smoothprogressbar:library:0.5.1'
    compile 'com.android.support:appcompat-v7:19.+'
}

android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

1 个答案:

答案 0 :(得分:3)

将此代码添加到build.gradle

repositories {
    mavenCentral()
}

更新解释答案: 要解决依赖关系,您必须在gradle脚本中指明要使用的存储库。您可以使用更多存储库......

使用support libs(支持和支持 - 契约)没有必要,因为Android插件会在您的SDK Manager下载androidRepositorygoogleRepository中进行搜索。