Android Tutorial android.jar / targetSdkVersion / minSdkVersion

Discussion in 'Tutorials & Examples' started by Erel, Dec 24, 2017.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    There are several versioned components that affect the compilation process and the runtime behavior of our apps.
    The purpose of this tutorial is to explain the differences between them and help you choose which version to use.

    Each Android version is mapped to an api level. You can see this mapping here:
    The api level is used in our code.


    Set in the manifest editor. Default value is 5 (Android 2.0). This one is very simple. Your app will only run on devices running this OS version or higher.
    In most cases you can leave it with the default value or set it to 16 to target Android 4.1+ and (theoretically) lose 1% of the devices.


    Set under Tools - Configure Paths. android.jar is a referenced library. It is only used during compilation.
    It doesn't affect the runtime behavior and it will not cause your app not to run on older versions.
    Use the latest version available to avoid compilation errors.


    Set in the manifest editor.
    This one is a bit more confusing. It helps with backwards compatibility.
    I will explain it with an example. Google introduced the runtime permissions system in Android 6 (API 23). Requesting runtime permissions requires developers to update their existing apps. Forcing this feature on existing apps would have broken 90% of the apps (only when they run on Android 6+).
    The way to solve it is to check the targetSdkVersion value. If it is 22 or below then the system knows that the app doesn't handle the changes introduced in API 23+ and it runs it without those changes.
    This means that an app with targetSdkVersion set to 14 (Android 4.0) will run properly on an Android 8.0 device and it will not be required to request runtime permissions, nor handle any other breaking change.

    Q: Will my app run on Android 4.0 if targetSdkVersion is set to 8.0?
    A: Yes.

    Q: Can I use new features without setting the targetSdkVersion to a higher version?
    A: In most cases yes.

    The minimum version for Google Play app is 26. It will be raised to 28 on August 2019.

    Q: What are the consequences of raising the targetSdkVersion?
    A: There are many changes that might affect your app.

    The most common are:
    - 22 (?) - notifications icons colors are ignored. Alpha levels used as a mask.
    - 23 - runtime permissions (
    - 23 - Setting system settings require special handling - WRITE_SETTINGS permission (
    - 24 - must use FileProvider when sharing files (
    - 24 - Default background color is white (
    - 24 - Setting the volume or the ringer mode will throw an error if the user set the Do Not Disturb mode. Your app can request special access:
    - 26 - notifications will not work without channels (
    - 26 - background limits. Features such as push notifications, StartServiceAt or #StartAtBoot will only work with B4A v8+.
    - 26 - installation from unknown sources requires explicit setting:
    - 28 - Foreground services require a new non-dangerous permission. It is added automatically if using B4A v9+.
    - 28 - The old http SDK is not available by default. This will cause problems with native libraries such as Google Maps who rely on the old SDK. To enable it:
    - 28 - Non-ssl (non-https) communication is not permitted by default. It can be enabled in B4A v9+ by adding this line to the manifest editor:
    CreateResourceFromFile(Macro, Core.NetworkClearText)
    You can see the behavior changes of each version:

    Q: Can I test the new behavior changes with a device running an older version of Android?
    A: No. This means that you must test your app on devices running a recent version of Android.
    Last edited: Oct 15, 2019
    Watchkido1, androh, Xicu and 53 others like this.
  2. Multiverse app

    Multiverse app Active Member Licensed User

    Thank you for this tutorial.
    hromek likes this.
  3. somed3v3loper

    somed3v3loper Well-Known Member Licensed User

    I started to panic though I don't have any apps published
    ocalle, eps, j_o_h_n and 6 others like this.
  4. incendio

    incendio Well-Known Member Licensed User

    Can new behavior test via emulator such as genie?

    What about private app that isn't publish on play store, will it still runs OK after Oct 18 if target sdk not set to 26?
  5. Erel

    Erel Administrator Staff Member Licensed User

    Yes. Emulators are not perfect but they can be useful for these tests.
    Peter Simpson likes this.
  6. Eme Fibonacci

    Eme Fibonacci Well-Known Member Licensed User

    Is it correct to think that many apps are will not be updated and will be out of the market in August 2018?
  7. Erel

    Erel Administrator Staff Member Licensed User

    No. Quoting Google's blog:
    This will be required for new apps in August 2018, and for updates to existing apps in November 2018.

    At this point it only affects updates to existing apps. So as long as an existing app is not updated it will continue to run without this restriction.
  8. ilan

    ilan Expert Licensed User

    igodese and Peter Simpson like this.
  9. mw71

    mw71 Active Member Licensed User

    is there an solution for that?
  10. Erel

    Erel Administrator Staff Member Licensed User

    I don't think that it requires a solution, it is not a problem. It is a new design that we need to follow.

    There is no workaround for this.
  11. LucaMs

    LucaMs Expert Licensed User

    I don't understand this statement:
    Who "forces"?

    Nice! Fortunately, I already live with panic, I'm used to it :p

    This is a further reason to publish libraries written using B4A and their SOURCE CODE (the same as GitHub).
  12. Erel

    Erel Administrator Staff Member Licensed User

  13. jnjft

    jnjft Member Licensed User

    Where do I get the latest version from?

    Thank you.
  14. NJDude

    NJDude Expert Licensed User

    "android.jar" is part of the Android SDK, by downloading the latest SDK you are getting the latest .jar.
    jnjft likes this.
  15. jnjft

    jnjft Member Licensed User

    Thanks for your light speed answer!
  16. janderkan

    janderkan Active Member Licensed User

    - 26 - background limits. Will require an update to B4A. Don't set targetSdkVersion to 26 if you are using features such as: push notifications, StartServiceAt or #StartAtBoot.

    Will there be an update to B4A before august 18 ?
    Multiverse app likes this.
  17. DonManfred

    DonManfred Expert Licensed User

    Yes. It is announced for next month somewhere here in forum if i remember correctly.
    Erel, Multiverse app and janderkan like this.
  18. Erel

    Erel Administrator Staff Member Licensed User

    One of the reasons that I decided to wait with the release of B4A v8.0 is that not everything related to the new background limitation is exactly clear from Google documentation. More experience is gained over time as more developers implement it.

    v8.0 is planned to be released in March (at least a beta version).
  19. Erel

    Erel Administrator Staff Member Licensed User

    Multiverse app likes this.
  20. Erel

    Erel Administrator Staff Member Licensed User

Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice