2018-07-31

【Android Studio】All com.android.support libraries must use the exact same version specification 的解決方法


在我的 app 層級build.gradle
  1.  
  2. ...
  3. ...
  4.  
  5. dependencies {
  6. implementation 'com.android.support:support-v4:27.1.1'
  7.  
  8. ...
  9. ...
  10. }
  11.  

出現錯誤訊息
  1.  
  2. All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 27.1.1, 26.1.0. Examples include com.android.support:recyclerview-v7:27.1.1 and com.android.support:customtabs:26.1.0 less... (Ctrl+F1)
  3.  
  4. 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).
  5.  

關鍵在於
com.android.support:customtabs:26.1.0

com.android.support:support-v4:27.1.1
版本不同

所以再加入 customtabs 並指定版本為 27.1.1 即可,如下:
  1.  
  2. ...
  3. ...
  4.  
  5. dependencies {
  6. implementation 'com.android.support:support-v4:27.1.1'
  7. implementation 'com.android.support:customtabs:27.1.1'
  8.  
  9. ...
  10. ...
  11. }
  12.