找不到满足版本限制的 'com.android.support:support-annotations' 版本
Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints
当我想使用 Proguard 规则生成签名的 APK(发布)时,我收到了这条错误消息:
Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints:
Dependency path 'Transition:library:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1'
Constraint path 'Transition:library:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' because of the following reason: debugRuntimeClasspath uses version 26.1.0
...
Gradle(应用):
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-
android.txt'),'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-annotations:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:cardview-v7:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.android.support:appcompat-v7'
api 'com.google.android.gms:play-services:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
implementation project(':library')
implementation 'com.jpardogo.materialtabstrip:library:1.1.1'
implementation group: 'com.jcraft', name: 'jsch', version: '0.1.54'
implementation 'com.google.guava:guava:26.0-android'
// glide
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.googlecode.json-simple:json-simple:1.1'
implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2'){
exclude module: 'support-v4'
}}
Gradle(项目):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle(图书馆):
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Proguard 规则:
-keep class com.jcraft.jsch.jce.*
-keep class * extends com.jcraft.jsch.KeyExchange
-keep class com.jcraft.jsch.**
-keep class com.jcraft.jzlib.**
-keep class com.jcraft.jsch.jce.*
-keep class com.jcraft.jzlib.ZStream
-keep class com.jcraft.jsch.Compression
-keep class org.ietf.jgss.*
-dontwarn org.ietf.jgss.**
-dontwarn com.jcraft.jsch.**
-keepattributes Signature, InnerClasses
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
-dontwarn com.google.errorprone.**
-dontwarn sun.misc.Unsafe
-dontwarn java.lang.ClassValue
我认为问题出在 Proguard 上,因为我通常可以在没有它的情况下生成 APK。
我也尝试在同步项目之前添加不同的 'com.android.support:support-annotations:xx' 实现,但问题仍然存在。
该项目是从 git 存储库导入的。
尝试添加
repositories {
maven { url 'https://maven.google.com' }
}
在您的项目级别 gradle。
问题已解决!我需要添加
implementation 'com.android.support:support-annotations:28.0.0'
android/app/build.gradle
中的依赖项
在我的图书馆里。消息警告足够明确,但我没有考虑修改库依赖项。
对我有用的是添加一个配置来解决这个冲突,尽管有许多其他选项,但强制系统使用指定的依赖路径。
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor(0, 'seconds')
cacheChangingModulesFor(0, 'seconds')
force('com.android.support:support-annotations:26.1.0')
}
transitive = true
}
我有一条类似的错误消息并通过删除此行解决了它:
androidTestImplementation 'androidx.annotation:annotation:1.1.0'
当我想使用 Proguard 规则生成签名的 APK(发布)时,我收到了这条错误消息:
Cannot find a version of 'com.android.support:support-annotations' that satisfies the version constraints: Dependency path 'Transition:library:unspecified' --> 'com.android.support.test:runner:1.0.2' --> 'com.android.support:support-annotations:27.1.1' Constraint path 'Transition:library:unspecified' --> 'com.android.support:support-annotations' strictly '26.1.0' because of the following reason: debugRuntimeClasspath uses version 26.1.0 ...
Gradle(应用):
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 21
targetSdkVersion 26
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-
android.txt'),'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleCompatible
implementation 'com.android.support:support-compat:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:support-annotations:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:cardview-v7:28.0.0'
//noinspection GradleCompatible
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.android.support:appcompat-v7'
api 'com.google.android.gms:play-services:12.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support:support-annotations:28.0.0'
implementation project(':library')
implementation 'com.jpardogo.materialtabstrip:library:1.1.1'
implementation group: 'com.jcraft', name: 'jsch', version: '0.1.54'
implementation 'com.google.guava:guava:26.0-android'
// glide
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.googlecode.json-simple:json-simple:1.1'
implementation ('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2'){
exclude module: 'support-v4'
}}
Gradle(项目):
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0-alpha13'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Gradle(图书馆):
apply plugin: 'com.android.library'
android {
compileSdkVersion 26
defaultConfig {
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Proguard 规则:
-keep class com.jcraft.jsch.jce.*
-keep class * extends com.jcraft.jsch.KeyExchange
-keep class com.jcraft.jsch.**
-keep class com.jcraft.jzlib.**
-keep class com.jcraft.jsch.jce.*
-keep class com.jcraft.jzlib.ZStream
-keep class com.jcraft.jsch.Compression
-keep class org.ietf.jgss.*
-dontwarn org.ietf.jgss.**
-dontwarn com.jcraft.jsch.**
-keepattributes Signature, InnerClasses
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn afu.org.checkerframework.**
-dontwarn org.checkerframework.**
-dontwarn com.google.errorprone.**
-dontwarn sun.misc.Unsafe
-dontwarn java.lang.ClassValue
我认为问题出在 Proguard 上,因为我通常可以在没有它的情况下生成 APK。 我也尝试在同步项目之前添加不同的 'com.android.support:support-annotations:xx' 实现,但问题仍然存在。
该项目是从 git 存储库导入的。
尝试添加
repositories {
maven { url 'https://maven.google.com' }
}
在您的项目级别 gradle。
问题已解决!我需要添加
implementation 'com.android.support:support-annotations:28.0.0'
android/app/build.gradle
中的依赖项
在我的图书馆里。消息警告足够明确,但我没有考虑修改库依赖项。
对我有用的是添加一个配置来解决这个冲突,尽管有许多其他选项,但强制系统使用指定的依赖路径。
configurations.all {
resolutionStrategy {
cacheDynamicVersionsFor(0, 'seconds')
cacheChangingModulesFor(0, 'seconds')
force('com.android.support:support-annotations:26.1.0')
}
transitive = true
}
我有一条类似的错误消息并通过删除此行解决了它:
androidTestImplementation 'androidx.annotation:annotation:1.1.0'