由于缺少依赖关系,Twitter Fabric无法在Android Studio中安装

时间:2015-01-23 15:27:39

标签: android twitter gradle twitter-fabric

我正在与Fabric建立一个Cordova项目,以便通过Twitter登录。我刚刚将Fabric插件安装到Android Studio中,但是当我同步Gradle文件时,我收到以下错误:

Information:Gradle tasks [:generateDebugSources, :generateDebugTestSources]
Error:A problem occurred configuring root project 'android'.
> Could not resolve all dependencies for configuration ':_debugCompile'.
   > Could not find com.squareup.picasso:picasso:2.3.2.
     Searched in the following locations:
         https://maven.fabric.io/public/com/squareup/picasso/picasso/2.3.2/picasso-2.3.2.pom
         https://maven.fabric.io/public/com/squareup/picasso/picasso/2.3.2/picasso-2.3.2.jar
     Required by:
         :android:unspecified > com.twitter.sdk.android:twitter:1.1.1 > com.twitter.sdk.android:tweet-ui:1.0.3
   > Could not find com.android.support:support-v4:21.0.0.
     Searched in the following locations:
         https://maven.fabric.io/public/com/android/support/support-v4/21.0.0/support-v4-21.0.0.pom
         https://maven.fabric.io/public/com/android/support/support-v4/21.0.0/support-v4-21.0.0.jar
     Required by:
         :android:unspecified > com.twitter.sdk.android:twitter:1.1.1 > com.twitter.sdk.android:tweet-ui:1.0.3
   > Could not find com.squareup.retrofit:retrofit:1.6.1.
     Searched in the following locations:
         https://maven.fabric.io/public/com/squareup/retrofit/retrofit/1.6.1/retrofit-1.6.1.pom
         https://maven.fabric.io/public/com/squareup/retrofit/retrofit/1.6.1/retrofit-1.6.1.jar
     Required by:
         :android:unspecified > com.twitter.sdk.android:twitter:1.1.1 > com.twitter.sdk.android:twitter-core:1.1.1
   > Could not find com.google.code.gson:gson:2.2.4.
     Searched in the following locations:
         https://maven.fabric.io/public/com/google/code/gson/gson/2.2.4/gson-2.2.4.pom
         https://maven.fabric.io/public/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
     Required by:
         :android:unspecified > com.twitter.sdk.android:twitter:1.1.1 > com.twitter.sdk.android:twitter-core:1.1.1

Android SDK更新程序为我提供了支持库21.0.3但不支持21.0.0,正如来自Fabric的Hemal所建议的那样:Android Twitter Fabric SDK conflict with support library

但我不知道其他那些库。有什么想法吗?

4 个答案:

答案 0 :(得分:26)

请按照此代码示例确保您的build.gradle文件类似:

    buildscript {
  repositories {
    jcenter()   // <- *add this
    maven { url 'https://maven.fabric.io/repo' }
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:0.13.3'
    // The Fabric Gradle plugin uses an open ended version to
    // react quickly to Android tooling updates
    classpath 'io.fabric.tools:gradle:1.+'
  }
}

apply plugin: 'com.android.application'   // <- *make sure this is the same

//Put Fabric plugin after Android plugin
apply plugin: 'io.fabric'

repositories {
    jcenter()   // <- *add this
    maven { url 'https://maven.fabric.io/repo' }
}

我遇到了同样的问题,花了半天时间才打开twitters官方文档并发现了这个问题: https://dev.twitter.com/twitter-kit/android/integrate

Fabric团队在SO和其他无效的论坛上给出的答案太多了。这很有效。

答案 1 :(得分:9)

将jcenter()更改为mavenCentral(),或者您可以保留jcenter和mavenCentral 还会将网址从https://maven.fabric.io/repo更改为https://maven.fabric.io/public

buildscript {
    repositories {
        mavenCentral()   // <- *add this
        maven { url 'https://maven.fabric.io/public' }
    }
}

答案 2 :(得分:2)

安装Fabric插件是不够的,你也必须使用它。单击Android Studio中的结构按钮可指导您完成在应用程序中包含twitter结构的过程,它甚至可以为您正确修改build.gradle(当然是在您的许可下)。当你按照给出的步骤进行操作时,你的build.gradle看起来就像@ AlexVPerl的答案所说的那样。

答案 3 :(得分:0)

其他答案对我来说已经过时了。我通过根据github上的最新更新build.gradle修复了问题:

https://github.com/twitter/twitter-kit-android