2017-10-12 41 views
0

我正在开发Android,并尝试实现GPS和Google Map。如何解决build.gradle中不同版本库的错误?

build.gradle(Module:app)就像下面

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.2" 
    defaultConfig { 
     multiDexEnabled true 
     applicationId "com.app.t.pro" 
     minSdkVersion 21 
     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' 
     } 
    } 
} 

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:26.+' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile 'com.android.support:design:26.+' 
    compile 'com.google.android.gms:play-services:11.0.4' 
    compile 'com.google.android.gms:play-services-maps:11.0.4' 
    testCompile 'junit:junit:4.12' 
} 

但它显示错误的compile 'com.android.support:appcompat-v7:26.+'。 错误是

All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 26.1.0, 25.2.0. Examples include com.android.support:animated-vector-drawable:26.1.0 and com.android.support:mediarouter-v7:25.2.0 less... (Ctrl+F1) 
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.) 

,但我没有看到任何build.gradleversion-25。 我错过了什么? 在此先感谢。

+0

https://stackoverflow.com/questions/39008887/how-do-i-show -dependencies-tree-in-android-studio/39020703#39020703 –

+1

你正在编译更多的lib只用''com.google.android.gms:play-services:11.0.4'' –

回答

4

compile 'com.android.support:appcompat-v7:26.1.0' 
compile 'com.android.support:design:26.1.0' 

而且

compile 'com.google.android.gms:play-services-maps:11.4.2' 
compile 'com.google.android.gms:play-services-location:11.4.2' 

同时删除,

compile 'com.google.android.gms:play-services:11.4.2' 
+0

但是,当我移除“compile”com.google时,它将显示**无法解析符号 'import com.google.android.gms.location.LocationServices;'**。 android.gms:播放服务:11.4.2''。 – Wun

1

TL;博士您需要更新的谷歌播放库至少11.2+

检查Google Play Release Notes

SDK版本支持在11.2

当你升级你的应用的Play服务依赖关系到11.2.0或更高版本,您的应用程序的build.gradle也必须更新以指定至少26(Android O)的compileSdkVersion。这不会改变您的应用运行方式。您不需要更新targetSdkVersion。如果更新compileSdkVersion至26日,你可以在你的编译收到错误以下消息指的是Android的支持库:

This support library should should not use a different version (25) than the compileSdkVersion (26).

这个错误可以通过升级支持库的依赖被解析为至少版本26.0.0。

+0

比位置和地图有点戏剧性我已经升级到API 26播放服务。但是错误依然存在。 – Wun

+0

Api 26不是Google Play的版本 –

相关问题