简体   繁体   中英

Android app Supporting Major android Versions

我已经有一个支持pre-lollipop设备的Android应用程序,但我想移植Android应用程序以支持最新版本到Marshmallow和早期版本到Jellybean,是否有任何特定指南可用于支持上述标准?

In your manifest/build.gradle:(depending on what you use)

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="23" />

Gradle:

defaultConfig {
    ........
    minSdkVersion 14
    targetSdkVersion 23


}

Set the minSDK to as low as possible. If it is too low, it will show an error. Remember that if you are using any code that requires higher API levels(eg when writing xml only writing android:layout_marginStart that requires API 17) you get an error telling you to increase min API level. Now, there are some ways to avoid increasing;

  • If possible, add code that also supports lower API levels(eg android:layout_marginRight
  • Aim your code at lower API levels if no alternatives are available for supporting both.
  • Remember the OS distribution and target the platforms with the highest percentage. No need to target practically dead platforms.
  • You can run old code on new devices, however new code on old devices is either not possible or requires AppCompat(eg material design)
  • Even though I say run old code to target old and new platforms, avoid deprecated code! If possible, use AppCompat to use new code on old devices.

To summarize:

When coding XML, use code that supports old and new(if available). When doing normal coding, attempt to use code that supports older versions and new that aren't deprecated. If possible use AppCompat to get new code and new things on old devices.

You can change your support version from gradle file like this

 defaultConfig {

    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1"
    multiDexEnabled true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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