A while back Google announced that starting in August 2018 they will no longer accept applications targeting API levels below 26. With that in mind we plan to migrate our builds to use API level 27 which brings with it a lot of great new features but will probably break some things as we go through the migration. Please read this post carefully, I’ll try to cover everything.
Notice that this announcement means that we will need to start updating the API levels every year which is a much faster pace.
I’ve constructed this post as a set of questions/answers.
What’s an API Level?
Every time Google releases a new version of Android it updates the API level e.g. currently Oreo (8.1) is API level 27.
When we build a native Android application we need to declare the "target" this means we compiled the project against this given API level. This is a double edged sword… When we pick a higher API level we can target new features of newer OS’s but we are also subject to new restrictions and changes.
E.g. when we migrated to API level 23 we had to change the way permissions are processed in applications. For Codename One code this was mostly seamless but if you relied on native code this sometimes triggered issues.
API level 27 can impact things such as background behavior of your application and can break some cn1libs/native code you might have in place.
FYI this is also explained in this article from Ars.
Will this Work for Older Devices?
The target API level doesn’t restrict older devices. For that we have a separate minimum target device and it indicates the lowest API level we support. Currently the default is 15 (Android 4.0.3 - Ice Cream Sandwich) but you can probably set it as low as 9 (Android 2.3 - Gingerbread) as long as you test the functionality properly and disable Google Play Services.
See this for a table of all the API levels from Google.
What API Level do we use Now?
That depends on your app. Our default is 23 but some cn1libs set the API level to 25.
We chose to migrate slowly as level 23 is generally good and stable.
Test This Now!
Test API level 27 right now before we flip the switch!
This is important as we want to iron out bugs/regressions before they impact everyone. You can enable this seamlessly by setting the build hint:
| || Remove this build hint after testing, otherwise when we migrate to a newer version later on it might fail! |
This will implicitly set a lot of other values including the target level and it will change the gradle version from 2.12 to 4.6.
By flipping this switch the build should now work on Android Studio 3.x out of the box without the changes listed in this tip. We also plan to enable other things in the resulting project such as using Googles builtin Java 8 support instead of ours (this isn’t enabled yet).
This will mean that native Android code would be able to use Java 8 features. Notice that this currently applies to the native interfaces only and not to the code in the Codename One implementation.
This should make it easier to work with some 3rd party libraries that already moved forward.
When Will this Happen?
The 27 build target is available now using the build hint:
Currently we are aiming to flip the switch by May. This might be pushed to a different date based on responses/feedback on the current status. We want to have enough time ahead so the July release of Codename One 5.0 (Social) will use this.
Is this a Good Thing?
I think it is. It prevents stagnation within the appstore.
I still see apps in the stores that target Gingerbread (API level 9). That’s a problem both visually & in terms of permissions/security.
I don’t think it will do enough to combat fragmentation. Google will need to change a lot more to fix that pickle but it’s a baby step in the right direction.