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

Twitter Fabric fails to install in Android Studio due to missing dependencies

我正在使用 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

不过,我对其他那些库一无所知。有什么想法吗?

请遵循此代码示例以确保您的 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' }
}

我有同样的问题,花了半天时间,直到打开推特的官方文档,看到了这个: https://dev.twitter.com/twitter-kit/android/integrate

Fabric 团队在 SO 和其他论坛上提供的答案太多,但没有效果。这行得通。

将 jcenter() 更改为 mavenCentral() 或者您可以同时保留 jcenter 和 mavenCentral 还从 https://maven.fabric.io/repo to https://maven.fabric.io/public

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

光装fabric插件还不够,还得用。单击 Android Studio 中的结构按钮将引导您完成将 Twitter 结构包含在您的应用程序中的过程,它甚至会为您正确修改 build.gradle(当然需要您的许可)。当您按照给定的步骤操作时,您的 build.gradle 看起来就像@AlexVPerl 的回答所说的那样。

其他答案对我来说已经过时了。我根据 github:

上的最新更新 build.gradle 解决了这个问题

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