Android:gradlew lint错误“不兼容的Gradle版本”

时间:2017-09-18 05:25:11

标签: android gradle lint gradlew

我在Android库项目中运行' gradlew lint '时遇到问题,因为我升级了我的gradle包装器版本和构建工具版本。

我之前使用的是gradlew版本1.3.0和buildToolsVersion 23.0.0我在运行 lint 时没有遇到任何问题。

升级我的gradlew版本和buildTools版本后,我在运行' gradlew lint '时开始出现此错误

我正在使用gradlew版本

classpath 'com.android.tools.build:gradle:2.3.3'

然后在我的build.gradle(app)上我正在使用

compileSdkVersion 25
buildToolsVersion '25.0.0'

我的播放服务版本是

compile 'com.google.android.gms:play-services:8.1.0'

从lint结果来看,这是错误输出

Incompatible Gradle Versions
../../build.gradle: All com.android.support libraries must use 
 the exact same version specification 
(mixing versions can lead to runtime crashes). 
Found versions 26.0.0-alpha1, 22.2.0. 
Examples include com.android.support:support-compat:26.0.0-alpha1 
and com.android.support:appcompat-v7:22.2.0

我有一种直觉,认为这是问题是由play-services和android buildTools版本引起的,但是我不知道如何修复它。

现在我运行' ./ gradlew -q dependencies app:dependencies --configuration compile '

我从播放服务部分了解到这一点

+--- com.google.android.gms:play-services:8.1.0
|    +--- com.google.android.gms:play-services-ads:8.1.0
|    |    +--- com.google.android.gms:play-services-basement:8.1.0
|    |    |    \--- com.android.support:support-v4:22.2.0 -> 26.0.0-alpha1
|    |    |         +--- com.android.support:support-compat:26.0.0-alpha1
|    |    |         |    \--- com.android.support:support-annotations:26.0.0-alpha1 -> 23.0.1
|    |    |         +--- com.android.support:support-media-compat:26.0.0-alpha1
|    |    |         |    +--- com.android.support:support-annotations:26.0.0-alpha1 -> 23.0.1
|    |    |         |    \--- com.android.support:support-compat:26.0.0-alpha1 (*)
|    |    |         +--- com.android.support:support-core-utils:26.0.0-alpha1
|    |    |         |    +--- com.android.support:support-annotations:26.0.0-alpha1 -> 23.0.1
|    |    |         |    \--- com.android.support:support-compat:26.0.0-alpha1 (*)
|    |    |         +--- com.android.support:support-core-ui:26.0.0-alpha1
|    |    |         |    +--- com.android.support:support-annotations:26.0.0-alpha1 -> 23.0.1
|    |    |         |    \--- com.android.support:support-compat:26.0.0-alpha1 (*)
|    |    |         \--- com.android.support:support-fragment:26.0.0-alpha1
|    |    |              +--- com.android.support:support-compat:26.0.0-alpha1 (*)
|    |    |              +--- com.android.support:support-core-ui:26.0.0-alpha1 (*)
|    |    |              \--- com.android.support:support-core-utils:26.0.0-alpha1 (*)

注意:我只显示了播放服务部分,因为这是我从Lint结果中看到的,我认为这是唯一有用的部分。

任何人都可以告诉我,我应该使用buildToolsVersion 25和compiledSdkVersion 25使用哪种播放服务版本?

谢谢!

app build.gradle

import com.android.build.gradle.LibraryPlugin
import org.aspectj.bridge.IMessage
import org.aspectj.bridge.MessageHandler
import org.aspectj.tools.ajc.Main

apply plugin: 'com.android.library'


android {
  packagingOptions {
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
  }

  compileSdkVersion 25
  buildToolsVersion '25.0.0'

  defaultConfig {
    minSdkVersion 19
    targetSdkVersion 25
    multiDexEnabled true
    versionCode 1
    versionName "1.0"
  }
  buildTypes {
    debug {
      buildConfigField "String", "APP_VERSION", "\"1.0-SNAPSHOT\""
    }
    release {
      buildConfigField "String", "APP_VERSION", "\"1.0-SNAPSHOT\""

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

  configurations.all {
    resolutionStrategy {
      force 'com.android.support:support-annotations:23.0.1'
    }
  }

  sourceSets {
    defaultConfig {
      testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
  }

}

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
    classpath 'org.aspectj:aspectjtools:1.8.9'
  }
}

repositories {
  maven {
    url 'https://download.01.org/crosswalk/releases/crosswalk/android/maven2'
  }
  maven {
    url "https://maven.java.net/content/groups/public/"
  }
}


apply plugin: 'com.neenbedankt.android-apt'
def dbflow_version = "3.1.1"


dependencies {
  compile fileTree(include: ['*.jar'], dir: 'libs')

  compile 'com.squareup.okhttp3:okhttp:3.0.1'
  compile 'com.squareup.okhttp3:okhttp-urlconnection:3.0.1'

  apt "com.github.Raizlabs.DBFlow:dbflow-processor:${dbflow_version}"
  compile "com.github.Raizlabs.DBFlow:dbflow-core:${dbflow_version}"
  compile "com.github.Raizlabs.DBFlow:dbflow:${dbflow_version}"
  compile 'com.github.Raizlabs.DBFlow:dbflow-sqlcipher:3.1.1@aar'
  compile 'net.zetetic:android-database-sqlcipher:3.5.1'
  compile 'org.xerial:sqlite-jdbc:3.7.2'

  compile 'commons-io:commons-io:2.4'
  compile 'commons-collections:commons-collections:3.2.1'

  compile 'com.google.android.gms:play-services:8.1.0'
  compile 'com.google.code.gson:gson:2.2.4'
  compile 'com.google.guava:guava:18.0'
  compile 'com.scottyab:aescrypt:0.0.1'

  compile([group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.3.2'],
          [group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.3.2'],
          [group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.3.2'])

  compile 'org.aspectj:aspectjrt:1.8.9'
  compile 'org.apache.commons:commons-lang3:3.4'

  compile 'org.slf4j:slf4j-api:1.7.21'
  compile('com.github.tony19:logback-android-classic:1.1.1-6') {
    exclude group: 'com.google.android', module: 'android'
  }
  compile 'com.sun.mail:android-mail:1.5.5'
  compile 'com.sun.mail:android-activation:1.5.5'

  compile 'org.xwalk:xwalk_core_library:20.50.533.12'


  testCompile 'junit:junit:4.12'
  testCompile group: 'com.squareup.okhttp3', name: 'mockwebserver', version: '3.9.0'
  testCompile 'org.powermock:powermock:1.6.5'
  testCompile 'org.powermock:powermock-module-junit4:1.6.5'

  testCompile 'org.powermock:powermock-api-mockito:1.6.5'
  testCompile 'org.robolectric:robolectric:3.0'
  androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'



}

2 个答案:

答案 0 :(得分:2)

  

发现版本26.0.0-alpha1,22.2.0。   示例包括com.android.support:support-compat:26.0.0-alpha1   和com.android.support:appcompat-v7:22.2.0

您正在使用具有不同版本支持库的库 例如,您使用的是com.android.support:appcompat-v7:22.2.0com.android.support:support-compat:26.0.0-alpha1

以特定方式更新到最新版本使用支持库v.26和google play services v.11.2.0。

compile 'com.google.android.gms:play-services:8.1.0'

另请注意,support libraries v26google play services v.11.2.0需要compileSdkVersion 26 google maven repo url "https://maven.google.com"

如果您想要排除com.android.support库,可以使用:

compile ('com.google.android.gms:play-services:11.2.2'){
    exclude group: 'com.android.support'
}

答案 1 :(得分:0)

正如您所看到的,Google Play服务正在挑选一个比您想要的版本更旧的版本-v4

+--- com.google.android.gms:play-services:8.1.0
|    +--- com.google.android.gms:play-services-ads:8.1.0
|    |    +--- com.google.android.gms:play-services- basement:8.1.0
|    |    |    \--- com.android.support:support-v4:22.2.0
  

我应该在buildToolsVersion 25和compiledSdkVersion 25中使用哪种播放服务版本?

这些数字并不重要。但是,理想情况下,您总是希望拥有最新的编译SDK(取决于资源或方法的弃用和删除)和构建工具。至少,我从来没有遇到过这种方法的问题。

至于Google Play,go read the documentation。特别是有选择地编译你真正需要的部分