简体   繁体   English

设计支持库中不同模块的Android SDK兼容性

[英]Android SDK compatibility for different modules from the Design Support Library

I would like to create a bottom navigation in my application and I found an easy way with Bottom Navigation provided from Material Design . 我想在我的应用程序中创建一个底部导航,并通过Material Design提供的底部导航找到了一种简单的方法。

My only problem is that I want the application to run on Android SDK 23 and I can see that Bottom Navigation from Material requires compile 'com.android.support:design:25.0.0' which requires 'com.android.support:appcompat-v7:25.0.0' . 我唯一的问题是我希望该应用程序在Android SDK 23上运行,并且我可以看到从Material的底部导航需要compile 'com.android.support:design:25.0.0' ,而该文件需要'com.android.support:appcompat-v7:25.0.0' Currently I'm using 23.4.0 and I'm assuming that changing this will make my application to work on Android SDK 25 and up only. 目前,我正在使用23.4.0并且我假设更改此设置将使我的应用程序只能在Android SDK 25及更高版本上运行。

Is this correct? 这个对吗?

No. That is not correct. 不,那是不正确的。 There's a big important difference between compile version and minimum version. 编译版本和最低版本之间有很大的重要区别。 This change is only in compile version. 此更改仅在编译版本中。

  • Compile version is the version your compiler will look at the moment it's compiling your code. 编译版本是编译器在编译代码时将查看的版本。 That is only for the compiler to know which methods are available on the device. 这只是让编译器知道设备上可用的方法。 For example, to know that an Activity has a findViewById and that a ViewGroup have a addView . 例如,要知道一个Activity有一个findViewById ,一个ViewGroup有一个addView As long you don't use a method that is higher that your minimum it makes no difference. 只要您不使用高于最小值的方法就没有区别。

  • Minimum version that is the one you're telling the Google Play and the Android system the minimum where your app can be installed and that it should work fine. 最低版本是您要告诉Google Play和Android系统的最低版本,可以在该版本中安装您的应用,并且该版本应能正常运行。 That's the one that limits which version to it can be installed. 那是限制可以安装哪个版本的版本。

For more on that I suggest you to read the official training materials here https://developer.android.com/training/material/compatibility.html and more specific the section "Check the System Version" https://developer.android.com/training/material/compatibility.html#CheckVersion 有关更多信息,我建议您在https://developer.android.com/training/material/compatibility.html上阅读官方培训材料,更具体地说,在“检查系统版本”部分https://developer.android中阅读。 com / training / material / compatibility.html#CheckVersion

Don't worry, you refer to compile 'com.android.support:design:25.0.0 that´s just your dependency, so first at all 不用担心,您指的是compile 'com.android.support:design:25.0.0这只是您的依赖项,因此首先

1.- If you want to use 'com.android.support:design:25.0.0 you should use at least building version 25: 1.-如果要使用'com.android.support:design:25.0.0 ,则应至少使用建筑版本25:

compileSdkVersion 25
buildToolsVersion '25.0.0'

2.- Your app works with 'com.android.support:design:25.0.0 if you defined in your gradle a minimun SDK or target SDK less than 25: 2.-如果您在gradle中定义了小于25的最小SDK或目标SDK,则您的应用程序可与'com.android.support:design:25.0.0一起使用:

minSdkVersion 15
targetSdkVersion 25

Now look this gradle, is from an app that works on API 19 and the Bottom Navigation View works fine 现在看一下这个问题,来自适用于API 19的应用程序,并且底部导航视图可以正常工作

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "**********"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled = true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    dexOptions {
        jumboMode true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.github.PhilJay:MPAndroidChart:v3.0.1'
    testCompile 'junit:junit:4.12'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM