安卓Gradle同步问题

11

这个应用之前一直运行得很好,没有任何问题。突然间我遇到了gradle同步的问题,现在陷入了困境,需要帮助。该怎么办?我已经在SDK管理器中卸载并重新安装了安卓支持库。

C:\Users\DELL\AndroidStudioProjects\Prokriti\app\build.gradle
    Error:Error:Failed to resolve: com.android.support:support-annotations:27.0.1
Install Repository and sync project
    Error:Error:Failed to resolve: com.android.support:appcompat-v7:27.0.1
Install Repository and sync project
    Error:Error:Failed to resolve: com.android.support:customtabs:27.0.1
Install Repository and sync project
    Error:Error:Failed to resolve: com.android.support:cardview-v7:27.0.1
Install Repository and sync project
    Error:Error:Failed to resolve: com.android.support:support-v4:27.0.1
Install Repository and sync project
    Error:Error:Failed to resolve: com.android.support:support-core-utils:27.0.1
Install Repository and sync project

构建文件 build.gradle(应用程序)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.avtro.prokriti.prokriti"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })


    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support:cardview-v7:25.3.1'
    compile 'com.android.support:design:25.3.1'
    compile 'com.android.support:support-core-utils:25.3.1'
    compile 'com.android.support:support-annotations:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.android.gms:play-services-auth:11.0.4'
    compile 'com.google.firebase:firebase-core:11.0.2'
    compile 'com.google.firebase:firebase-messaging:11.0.2'
    compile 'com.google.firebase:firebase-database:11.0.2'
    compile 'com.google.firebase:firebase-auth:11.0.2'
    compile 'com.google.firebase:firebase-ads:11.0.2'
    compile 'com.afollestad.material-dialogs:core:0.9.4.5'
    compile 'com.wang.avi:library:2.1.3'
    compile 'com.google.android.gms:play-services-ads:11.0.4'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.survivingwithandroid:weatherlib:1.6.0'
    compile 'com.amitshekhar.android:android-networking:1.0.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
    compile 'com.google.firebase:firebase-storage:11.0.2'
    androidTestCompile 'junit:junit:4.12'
    compile 'javax.inject:javax.inject:1'
    compile 'com.android.support:support-v4:25.3.1'
    compile 'com.github.bumptech.glide:glide:3.8.0'
}
apply plugin: 'com.google.gms.google-services'

build.gradle (项目)

buildscript {
    repositories {
        jcenter()
    }
dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我没有更新Android Studio或Gradle。安装了Android支持库。


尝试将所有Firebase和GAS依赖项更改为11.0.4。 编辑:刚刚看到您的图像截图,我知道之前一切都很好,因此您可以执行无效缓存并重新启动Android Studio。如果仍然存在问题,请尝试将构建工具版本更改为27.0.1。 - Mofe Ejegi
未能解决...需要帮助。 - Tough questions
我们也遇到了同样的问题。你已经解决了这个问题吗? - Lalit Mohan
@Toughquestions,我也遇到了这个问题,从今天早上开始它还能正常工作,昨晚都好好的。你找到任何解决方案了吗? - ManMohan
1
遇到了相同的问题。这个问题只出现了大约2个小时。还有希望吗? - emilpmp
1
@Emil Pradeep 请尝试一下用户e9060393给出的答案。这解决了我的问题。 - ManMohan
9个回答

39
我通过移除来解决问题。
 compile 'com.facebook.android:facebook-android-sdk:[4,5)'

并添加

compile 'com.facebook.android:facebook-android-sdk:4.26.0'

未能解决问题,Error:(49, 13) Failed to resolve: com.facebook.android:facebook-login:4.26.0 - Latief Anwar
1
谢谢,问题已解决,通过删除compile 'com.facebook.android:facebook-login:[4,5)'并替换为compile 'com.facebook.android:facebook-android-sdk:4.26.0' - Latief Anwar
通过@usere9060393给出的答案解决了我的问题。非常感谢.....但我想知道为什么FB SDK会导致这种情况,以及为什么会发生这种情况?我的意思是它之前一直正常工作的..... - Tough questions
有时候它是compile 'com.facebook.android:facebook-android-sdk:4.+'。将其更改为compile 'com.facebook.android:facebook-android-sdk:4.26.0' - jafarbtech
真的花了一整天的时间来尝试解决这个问题,非常感谢您!!! - ben

9

你只需要更改一行代码。

通过更新Facebook SDK版本进行修复。


compile 'com.facebook.android:facebook-android-sdk:[4,5)'

compile 'com.facebook.android:facebook-android-sdk:4.26.0'


这对我也起作用了,你怎么知道它是 FB? - MiMo

7

enter image description here

"com.facebook.android:facebook-android-sdk:[4,5)" 或者。"

'com.facebook.android:facebook-android-sdk:4.+'

replace替换为下面

'com.facebook.android:facebook-android-sdk:4.26.0'


1
替换
compile 'com.facebook.android:facebook-android-sdk:[4,5)'

by

compile 'com.facebook.android:facebook-android-sdk:4.26.0'

希望它能够工作。

0

不要

compile 'com.facebook.android:facebook-android-sdk:[4,5)'

根据 Facebook SDK for Android,您应该使用:
 // Facebook Android SDK (everything)
  compile 'com.facebook.android:facebook-android-sdk:4.+'

如需更新的情况,请阅读{{link1:Facebook Android SDK 的变更日志和发布说明。}}

compile 'com.facebook.android:facebook-android-sdk:4.26.0'
compile 'com.facebook.android:facebook-android-sdk:4.27.0'
compile 'com.facebook.android:facebook-android-sdk:4.28.0'
compile 'com.facebook.android:facebook-android-sdk:4.29.0'

0
在编程方面的翻译:将google()添加到buildscript.repositoriesallprojects.repositories中:
buildscript {
    repositories {
        google()
        jcenter()
    }
dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

这应该可以解决你的问题。


1
请注意,此快捷方式仅适用于Gradle 4.1及以上版本!否则,您必须使用以下代码: // 如果您使用的是低于4.1版本的Gradle,则必须改用以下代码: maven { url 'https://maven.google.com' } - and_dev

0
Its work for me
Its work for me
Update Android SDK Build -Tools and SDK platforms
Changed in project build file.
buildscript {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}
changed in app build file
compileSdkVersion 26
buildToolsVersion "26.0.2"
Disable dependencies inspection.
compile 'com.android.support:design:25.3.1

0

使用这个

repositories {
        maven { url 'https://maven.google.com/' }
    }

0
对于React Native项目:将Maven存储库添加到您的项目中(在添加Maven存储库链接后删除react-native-fbsdk错误)。
buildscript {
    repositories {
       jcenter()
       mavenCentral()
       maven {            // Add this block
          url "https://maven.google.com"
       }
    }
}

allprojects {
    repositories {
        mavenLocal()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }

        // If something is not found from above maven repo.
        maven { url 'https://maven.google.com' }    // Add this block 
    }
}

更多信息在这里


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接