我创建了一个新的项目在Android Studio 2.2预览1与Android应用程序和后端模块谷歌消息。这是app文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 15
targetSdkVersion 23
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(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha1'
compile 'com.google.android.gms:play-services-gcm:9.0.0'
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
}
但它给予:
错误:与依赖项“com.google.code.findbugs:jsr305”冲突。应用程序(1.3.9)和测试应用程序(2.0.1)的解析版本不同。详情见http://g.co/androidstudio/app-test-app-conflict。
我是Android的新手,无法找到这个错误是什么。我该怎么解决呢?
方法1:
我删除了espresso-core行上的androidTestCompile,它会自动包含在一个新项目中。然后我的Android Studio编译干净。
androidTestCompile在build中。gradle(模块:应用)”:
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
...
}
我不知道这种删除是否会有任何问题,但它肯定适用于我目前的项目。
方法2:在findbugs上添加一个排除也可以:
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
})
...
}
方法3:使用特定版本强制编译:
(在下面的代码中,我强制它使用更高版本编译。)
dependencies {
...
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
...
}
发生这种情况的原因是diff依赖使用了与diff版本相同的库。
所以,有3步或(1步)来解决这个问题。
1st
Add
configurations.all {
resolutionStrategy.force 'com.google.code.findbugs:jsr305:2.0.1'
}
适合你的身材。Gradle文件在android{…}
2nd
在android studio中打开终端
执行。/gradlew -q app:dependencies命令。
3rd
在Build列表中的android studio菜单栏中单击Clean Project。
它会重新构建项目,然后
在第一步中删除代码。
也许你只需要执行第二步。发生错误时不能回滚。
试试看。
方法1:
我删除了espresso-core行上的androidTestCompile,它会自动包含在一个新项目中。然后我的Android Studio编译干净。
androidTestCompile在build中。gradle(模块:应用)”:
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
...
}
我不知道这种删除是否会有任何问题,但它肯定适用于我目前的项目。
方法2:在findbugs上添加一个排除也可以:
dependencies {
...
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.code.findbugs'
})
...
}
方法3:使用特定版本强制编译:
(在下面的代码中,我强制它使用更高版本编译。)
dependencies {
...
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
...
}