The question is this. At the moment, the most accessible version of the platform is 6.0. I do not have phone 4.4.2. Does this mean that I need to install sdk for version 4, or can I install and develop an application on the 6th and it will run on my phone? If the first option, then what sdk version will be more universal?

    3 answers 3

    In the development environment (for example, Android Studio), it makes sense to install the latest stable version of the SDK (today API 23 Android 6.0) - this will allow you to develop an application with the maximum number of supported devices and use the capabilities of new APIs for devices that support them. The same applies to the packages SDK Tools, SDK Build Tools, SDK Platform Tools. SDKs must also be installed for which virtual devices will be created for testing. Other versions of the SDK, including real testing devices, are not necessary to install - the real device has all the necessary SDKs in itself.
    The SDK is installed using the SDK Manager utility ( Tools -> Android -> SDK Manager in Android Studio).

    In this case, an application being developed can be run on any device whose API is higher than that set in the minSdkVersion project minSdkVersion , the upper limit is usually not specified. By specifying this parameter, you will sometimes receive warnings from the IDE that you are trying to use classes or methods that are not compatible with the specified minimum API. This means that this class (method) was added to the SDK later than the restriction you specified, and will not work on some of the devices listed as supported. Google's support libraries greatly enhance the use of new classes on devices where their API does not allow them to be used. In this case, instead of SDK classes, classes from support-libraries are used.

    In order to specify which minimum API your application can work with (on which minimum version of Android it can be launched), you need to specify this in the configs of your project in one of the ways:

    1. The corresponding parameter in the AndroidManifest.xml file.

    An example of the indication in the manifest:

     <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.application" /> <uses-sdk android:minSdkVersion="15" android:compileSdkVersion="23" /> <!-- остальное содержимое--> </manifest> 
    1. In the defaultConfig section of the project module build.gradle configuration file.

    An example in the build.gradle file:

     android { compileSdkVersion 23 buildToolsVersion '23.0.3' defaultConfig { applicationId "com.example.application" minSdkVersion 15 targetSdkVersion 23 } 

    With the transition to the Gradle assembly system, it is recommended to use the second option. These settings in the project mean that the application can be run on any device with Android 4.0 (API15) or newer.
    These parameters can be configured either directly by editing configuration files or in the Project Structure window via a graphical interface:

    scrn

    PS: compileSdkVersion (indicates by which SDK to build the project) must be the latest API version, otherwise new support libraries will not work (the major support library number and compileSdkVersion must match).

    targetSdkVersion specifies the primary target device (preferred for the SDK application). The secondary parameter, but traditionally specified as compileSdkVersion

      There are minSdkVersion and targetSdkVersion . targetSdkVersion should preferably be the last available, but minSdkVersion you specify from which version your program will work (well, you need to use, respectively, methods, etc., available starting from this version).

      If minSdkVersion 14 , it will work on all devices starting from Android 4.0. If minSdkVersion 19 , then with Android 5.0, etc.

      Due to the presence of Support libraries, you can significantly lower minSdkVersion without losing anything, but if you want to develop only for new devices using the latest API, then on older versions, of course, the program will not work.

      • That's right, but not Compat , but support . AppCompat is only one of the compatibility libraries that implements Material Design on devices below API 19. And there are quite a few support libraries (about 20) and beyond this. - pavlofff
      • @pavlofff thanks for the amendment, I just postponed from the once read that Compat , from the word "Compatibility" - compatibility, so I call them generally all Compat - VAndrJ
      • and where can I see minSdkVersion and targetSdkVersion? in the sdk manager there are tabs Tools, preview channel, system versions and extraz. When you create a project, you can select only the desired sdk and that's it .. everything that you wrote about I do not find .. - Iga
      • @Iga when creating you specify minSdkVersion . And in the project in build.gradle (Module: app), see - VAndrJ
      • opened ide. I found where you can choose minsdkversion, but in the default gradle you only see: buildscript, allprojects, task clean (type: Delete). I didn't see anything about the versions there - Iga

      If you want to test on your phone, then minSdkVersion should be <= 19. Otherwise, you will not be able to run the program on the phone. targetSdkVersion may be up to the very last, but> = minSdkVersion . Usually and choose the latest version of the SDK. If you publish your application, it is advisable to test it on phones, tablets of different versions of the SDK and screen resolutions. Without an emulator can not do.

      The lower the value as minSdkVersion chosen, the greater the proportion of existing devices in the world will be covered (see Dashboards ). But the more difficult it will be to develop (more restrictions, the need to take into account different options) and testing. Need a compromise.

      Both parameters ( minSdkVersion , targetSdkVersion ) are set in the file build.gradle(Module:app) . You can find this file quickly if you watch a project in Android mode in AndroidStudio (In the Gradle Scripts section). After its correction, you need to synchronize the project with the Gradle files (Sync project with Gradle Files) - on the panel icon is the green circle and the blue down arrow.

      • Given that all APIs <16 occupy less than 3%, then the compromise is not great :) - pavlofff