Gradle兼容的新版本

时间:2019-07-05 02:32:17

标签: android gradle

请您能帮我解决这个问题,我不知道所有更新都在哪里

问题:

  

所有com.android.support库必须使用完全相同的版本   规范(混合版本可能导致运行时崩溃)。找到了   版本28.0.0、27.0.2。例子包括   com.android.support:animated-vector-drawable:28.0.0和   com.android.support:customtabs:27.0.2少...(Ctrl + F1)检查   信息:有一些库或工具和库的组合,   不兼容或可能导致错误的代码。一种这样的不兼容   正在使用一个版本的Android支持库进行编译   不是最新版本(或者特别是低于您的版本)   targetSdkVersion)。问题ID:GradleCompatible

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.el.sohaib.babysitter"
        minSdkVersion 22
        targetSdkVersion 28
        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:28.0.0'

    implementation 'com.android.support:animated-vector-drawable:28.0.0'


    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    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'
  //the erreur   implementation 'com.android.support:design:28.0.0'
}


apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.el.sohaib.babysitter"
        minSdkVersion 22
        targetSdkVersion 28
        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:28.0.0'

    implementation 'com.android.support:animated-vector-drawable:28.0.0'


    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.facebook.android:facebook-android-sdk:[5,6)'
    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'
    implementation 'com.android.support:design:28.0.0'
}

1 个答案:

答案 0 :(得分:1)

之所以显示此警告,是因为Facebook sdk使用了较早版本的支持库。在项目中使用的较新版本(28.0.0)效果不佳。

解决方案是排除Facebook sdk中使用的所有较旧版本的库:

 implementation ('com.facebook.android:facebook-android-sdk:[5,6)') {
    exclude group: 'com.android.support', module: 'cardview-v7'
    exclude group: 'com.android.support', module: 'customtabs'
    exclude group: 'com.android.support', module: 'support-media-compat'
    exclude group: 'com.android.support', module: 'support-v4'
}

排除依赖项可能导致运行时崩溃,因为该库将在那些被排除的库中调用函数。 现在,您需要在依赖项中提供所有这些库的较新版本

implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.android.support:support-media-compat:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'

这是我完整的build.gradle文件:

    apply plugin: 'com.android.application'

    apply plugin: 'kotlin-android'

    apply plugin: 'kotlin-android-extensions'

    android {
        compileSdkVersion 28
        defaultConfig {
            applicationId "com.example.myapplication"
            minSdkVersion 19
            targetSdkVersion 28
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation 'com.android.support:appcompat-v7:28.0.0'
        implementation 'com.android.support.constraint:constraint-layout:1.1.3'

        /**
        * Providing newer versions of those libs
        */
        implementation 'com.android.support:cardview-v7:28.0.0'
        implementation 'com.android.support:customtabs:28.0.0'
        implementation 'com.android.support:support-media-compat:28.0.0'
        implementation 'com.android.support:support-v4:28.0.0'

        /**
        * Excluding older libs
        */
        implementation ('com.facebook.android:facebook-android-sdk:[5,6)') {
            exclude group: 'com.android.support', module: 'cardview-v7'
            exclude group: 'com.android.support', module: 'customtabs'
            exclude group: 'com.android.support', module: 'support-media-compat'
            exclude group: 'com.android.support', module: 'support-v4'
        }

        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'


    }