首页 > 解决方案 > 如何成功提高目标api级别

问题描述

我想增加我的应用程序的目标 api 级别,而不影响应用程序依赖的其他库,例如 firebase 等。我尝试在 app 模块下的项目结构中更改它,但这没有成功。gradle 文件没有任何变化 我的下一个选择是通过编辑 gradle 文件本身并增加到 api 级别 28 来增加它。但是我害怕这可能对其他库产生影响。以下是我的构建 gradle 文件,请帮助我。

android {

    compileSdkVersion 26
    defaultConfig {
        applicationId "com.chomba.haroldking.kuta"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:design: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'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.jakewharton.threetenabp:threetenabp:1.2.1'
    implementation 'com.android.support:recyclerview-v7:26.1.0'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.firebaseui:firebase-ui-database:3.1.0'
    implementation 'com.android.support:palette-v7:26.1.0'
    implementation 'com.wdullaer:materialdatetimepicker:3.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.0'
    implementation 'com.android.support:support-annotations:28.0.0'
    implementation 'com.google.firebase:firebase-storage:16.0.1'
}
apply plugin: 'com.google.gms.google-services'

我需要对其他库进行更改吗

标签: javaandroidgradle

解决方案


要升级你的targetSdkVersion,你应该把它和build.gradle一起更新compileSdkVersion(如果你不更新它,你会得到一个错误)。

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 28
    }
}

更新targetSdkVersion和 后,compileSdkVersion您还需要将支持库版本更新为28.0.0,因为支持库的主要版本需要与targetSdkVersion. 例如:

implementation 'com.android.support:appcompat-v7:28.0.0' // instead of 26.1.0

版本28.0.0支持库的最终版本。要在升级到 API 29 后继续使用支持库,您应该迁移到AndroidX

更新时,您还应该检查Android 9中是否有您需要考虑的相关更改。

在您的情况下,如果不更新targetSdkVersion依赖项,您将无法更新。


推荐阅读