无法解决':app @ debug / compileClasspath':无法解析com.google.android.gms:play-services-basement:[15.0.0,16.0.0)

时间:2018-06-12 16:53:56

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

我收到此错误: 这是我的build.gradle(模块:app)

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.mycompany.myapp"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding.enabled = true
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.google.firebase:firebase-core:15.0.0'
    compileOnly "org.projectlombok:lombok:1.16.20"
    annotationProcessor 'org.projectlombok:lombok:1.16.20'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.google.android.gms:play-services-maps:15.0.0'
    implementation 'com.google.android.gms:play-services-location:15.0.0'
    implementation 'com.google.android.gms:play-services-places:15.0.0'
    implementation 'com.paytm.pgsdk:pgsdk:1.0.8'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.crashlytics.sdk.android:crashlytics:2.9.1'
}

apply plugin: 'com.google.gms.google-services'

这是我的build.gradle(Project:myApp)

buildscript {

    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'io.fabric.tools:gradle:1.25.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.1.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://maven.google.com/'
        }
    }
}

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

我已经检查了其他解决方案,其中大多数建议添加

maven { url "https://maven.google.com" }

to build.gradle of project。我已经尝试过了,但我仍然遇到同样的错误。

我在android studio 3.0上。 我还尝试添加google()而不是maven(另一个建议)

15 个答案:

答案 0 :(得分:6)

转到File -> Other Settings -> Default Settings -> Build, Execution, Deployment -> Build Tools -> Gradle ->

然后取消选中Offline work选项。

答案 1 :(得分:4)

选项1:

按照以下说明进行操作。

  

项目级build.gradle

使用

maven { url "https://www.jitpack.io" }

代替

maven { url "https://jitpack.io" }

选项2:

  

项目级build.gradle

google()存储库应为第一优先级

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

选项3:

请按照以下步骤进行解决。

第1步:

  

项目级build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.2.0' // google-services plugin
        classpath 'com.android.tools.build:gradle:3.4.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        maven { url "https://jitpack.io" } // For Ucrop
        maven { url "https://maven.google.com" } // Google's Maven repository - FCM
        maven {
            url 'https://dl.bintray.com/azeesoft/maven'
        }
        google()
        jcenter()
        mavenCentral()
    }
}

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

第二步:

  

应用程序级build.gradle

我已经更新了一个信号版本。

使用

implementation 'com.onesignal:OneSignal:3.11.1'

代替

implementation 'com.onesignal:OneSignal:3.10.9' 

答案 2 :(得分:3)

如果您在项目build.gradle中声明了以下内容,则

maven { url "https://jitpack.io" }

尝试更改为

maven { url "https://www.jitpack.io" }

答案 3 :(得分:1)

在使用OneSignal处理我的android应用程序中的推送通知时,我遇到了同样的问题。

解决方案是将exclude子句添加到其依赖项中:

implementation ('com.onesignal:OneSignal:3.8.3'){
    exclude group: 'com.google.android.gms'
}

在应用文件夹中,然后手动添加任何其他缺少的依赖项,例如:

implementation 'com.google.android.gms:play-services-appinvite:16.1.0'

问题是OneSignal SDK包含与我在应用程序中使用的最新版本的gms和firesbase不同版本的Google Play服务依赖项。

因此,我建议您找出添加的依赖项,该依赖项在项目中使用google play服务并在其上使用exclude子句。如果您的系统连接到Internet,虽然应该可以建立gradle。

希望这会有所帮助。

答案 4 :(得分:1)

我正在使用VPN进行互联网连接。我关闭了VPN,它对我有用。

答案 5 :(得分:0)

使用VPN解决了我的问题。

答案 6 :(得分:0)

Just Build-> Clean Project为我工作

答案 7 :(得分:0)

我遇到了这个问题,以前使用过代理。我发现我的代理不再工作了,所以我进入设置并将代理配置更改为“自动”,但仍然显示相同的错误。

我终于发现代理也被自动设置为gradle,但是当我禁用它时,它并未从我的gradle配置中删除。所以我去了C:Users/User/.gradle/gradle.properties,在那个文件里有这样的东西:

## For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#enter code here
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx1024m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Sat Aug 31 18:23:27 IRDT 2019
systemProp.https.proxyPort=8118
systemProp.http.proxyHost=fodev.org
systemProp.https.proxyHost=fodev.org
systemProp.http.proxyPort=8118

所以我刚刚编辑了此文件,并注释了最后4行,它解决了我的问题。

我也在使用VPN服务。

答案 8 :(得分:0)

我的问题是...
我可以运行项目...但是突然出现此错误。
经过几次尝试“再试一次”的解决方案,但没有解决。

几分钟后终于浪费了。我尝试清洁项目。并重建。 Tadaaaa它起作用。
我不知道这是否可以帮助任何人,但可以解决我的问题。希望它能解决您的问题。

答案 9 :(得分:0)

打开顶级build.gradle文件并添加google-services

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.google.gms:google-services:4.3.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

如果您已经添加了它,只需将google-service更新并升级到最新版本

答案 10 :(得分:0)

如果您突然遇到此问题,则可能是在生成apk时它已损坏。这很少发生

解决方案:重建任务

enter image description here

答案 11 :(得分:0)

将存储库更新到最新版本为我解决了这个问题。

import React from 'react';
import DatePicker,{ CalendarContainer } from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";


function App() {
  const [startDate, setStartDate] = React.useState(new Date());
  const MyContainer = ({ className, children }) => {

    return (
      <div >
        <CalendarContainer className={className}>
          <div style={{ background: "#f0f0f0" }}>
            What is your favorite day?
              </div>
          <div style={{ position: "relative" }}>{children}</div>
        </CalendarContainer>
      </div>
    );
  };

  return (
    <DatePicker
      selected={startDate}
      onChange={(date) => setStartDate(date)}
      calendarContainer={MyContainer}
    />
  );
}

export default App;

答案 12 :(得分:-1)

您是否尝试在依赖项中添加此内容:

implementation 'com.google.android.gms:play-services-basement:15.0.0'

答案 13 :(得分:-1)

就我而言,我只是更改了我的项目,将我的项目级别构建Gradle和其他依赖项更改为最新版本,而将应用程序级别build gradle中的google maps依赖项更改为10.0.0。

答案 14 :(得分:-1)

我遇到了同样的问题,请执行以下操作为我解决了该错误 更改了 classpath'com.google.gms:google-services:4.3.2' 至   classpath'com.google.gms:google-services:4.3.3'。 当android studio告诉您存在新版本的依赖项时,寻找提示。如果有,则将您的依赖关系更改为最新的依赖关系。

相关问题