Android appcompact-v7依赖项的错误

Android appcompact-v7依赖项的错误,android,android-gradle-plugin,Android,Android Gradle Plugin,在使用最新更新的android studio打开一个旧项目后,build.gradle文件出现了此错误。我应该换什么 appcompact-v7依赖项存在错误: 所有com.android.support库必须使用完全相同的版本规范。找到版本26.1.0、19.1.0 apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion '27.0.3' defaultConfig {

在使用最新更新的android studio打开一个旧项目后,build.gradle文件出现了此错误。我应该换什么

appcompact-v7依赖项存在错误: 所有com.android.support库必须使用完全相同的版本规范。找到版本26.1.0、19.1.0

apply plugin: 'com.android.application'

android {
compileSdkVersion 19
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "X"
    minSdkVersion 15
    targetSdkVersion 19
    versionCode 7
    versionName "name"
    }
    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:19.1.0'
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}
这样做:-

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "X"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 7
    versionName "name"
    }
    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:27.0.3'
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}

如错误所示,只需更改库的版本,如下所示:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:27.1.0' //19.1.0 to 27.1.0
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}
注意

如果你得到

Error:Failed to resolve: com.android.support:appcompat-v7:27.1.0'
然后在项目级
build.gradle
部分中使用
google()

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
最后

模块级
构建。梯度

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "X"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 7
    versionName "name"
    }
    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:27.1.0'
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}

然后执行清理重建运行

我已将targetsdkVision设置为19,因为它使用的是旧的摄像头api。。因此,限制使用较旧android版本的用户看到这一点。在这种情况下,在使用高于targetSdkVersion的支持库时会出现错误。有解决方法吗?@user776914不,它不会给出错误,它会向您显示警告,就是这样,在这种情况下,它会给我一个使用高于targetSdkVersion的支持库的错误。有解决方法吗?我已将TargetSdkVision设置为19,因为它使用的是旧的camera api。。因此,限制使用较旧android版本的用户看到这一点。在这种情况下,在使用高于targetSdkVersion的支持库时会出现错误。有解决方法吗?它只会抛出警告。对于同一版本,您是指appcompact依赖项的19.1.0吗?@user776914否。。它的
27
谢谢你的链接!之前我假设compileSdkVersion必须与targetSdkVersion保持相同。将其更改为27,但将targetSdkVersion保留为19(我需要它进行过滤)可以工作!
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
    applicationId "X"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 7
    versionName "name"
    }
    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:27.1.0'
    compile 'com.google.android.gms:play-services-ads:12.0.1'
}