如何将SDK版本从26更改为19

时间:2017-11-12 18:33:30

标签: android sdk

首先,这是我的第一个应用程序开发。

所有这些在我基于

构建我的应用程序时
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
    minSdkVersion 23
    targetSdkVersion 25
}


dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:recyclerview-v7:26.0.0-alpha1'
compile 'com.android.support:design:26.0.0-alpha1'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:support-v4:26.0.0-alpha1'
}

一切都很完美。没错。

当我决定将sdk更改为19时,错误开始发生。

compileSdkVersion 'Google Inc.:Google APIs:19'
buildToolsVersion "26.0.1"
defaultConfig {
    applicationId "vinnito.plando"
    minSdkVersion 19
    targetSdkVersion 19

Errors that I got after changing SDK version

我想将其更改为19的原因是因为我的手机笔记2我希望用作调试我的应用程序的工具。 我知道有可用的模拟器,但我确实想在实际设备中运行该应用程序。

我想为SDK 19添加依赖项,但我找不到任何依赖项。所有这些都是SDK 26。 在我的SDK Manager中,我已经下载了SDK 19及更高版本..

Library Dependencies

任何人都知道如何在没有重大代码更改的情况下使这个源代码能够在SDK 19中运行,或者我别无选择?

提前致谢。

3 个答案:

答案 0 :(得分:1)

如果您想首先使用支持库v.26,请使用:

compileSdkVersion 26

无法使用api 19编译

然后使用稳定版本:

compile 'com.android.support:recyclerview-v7:26.1.0
//....do the same for the other libraries.

请注意,因为v.26.x.x需要maven google repo.

最后,如果您想使用api 19支持设备,请使用:

defaultConfig {
    minSdkVersion 19
}

请记住,您也可以在带有api 19的设备上使用支持库v26。

答案 1 :(得分:0)

出于测试目的,您应该仅将minSdkVersion更改为19。 降级targetSdkVersion是不好的做法,没有必要。

您的gradle文件应如下所示:

compileSdkVersion 27
buildToolsVersion "26.0.2"

defaultConfig {
    minSdkVersion 19
    targetSdkVersion 27
}

ext {
    androidSupportVersion = '27.0.0'
}

dependencies {
    compile fileTree ( include: ['*.jar'], dir: 'libs' )
    compile "com.android.support:appcompat-v7:$androidSupportVersion"
    compile "com.android.support:design:$androidSupportVersion"
    compile "com.android.support:recyclerview-v7:$androidSupportVersion"
    compile "com.android.support:support-v4:$androidSupportVersion"
}

答案 2 :(得分:0)

您可以删除buildToolsVersion "26.0.1",在Android 3.0之后没有必要。设置minSdkVersion 19就足够了,不需要将targetSdkVersion更改为19.我使用Android 4.4进行测试,但它不适用于com.android.support:appcompat-v7:26.0.0及以上,因为它,我使用25.xx版本的app-compat和设计库。我还要更清楚地添加我的gradle,你也不需要显式编译recyclerview,它包含在设计库中。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 21
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:multidex:1.0.2'
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:design:25.4.0'
    compile 'com.android.support:cardview-v7:25.4.0'
    compile 'com.android.support:appcompat-v7:25.4.0'
}
相关问题