State of Kotlin on Android

hi my name is Jeffrey van Gogh I'm a tech lead on Android studio with a focus on programming languages today I'm going to talk about the state of coupling on Android for those who have not booked it : before here's a brief overview Copelan is a modern programming language and it has many features that egg productivity it comes with things like notability support in the type system to help you avoid null pointer exception at runtime shorris index through lambdas makes codec code more succinct and readable here you see a call to an extension function which is a feature to make helper code more discoverable and avoid polluting your code with you tools dot everywhere in this example that calls made as part of a template expression which is a compile time checked occurring the f2 string of format with an elegant syntax the last highlight of this example shows using properties to provide a level of extraction over getters and setters and along an assignment syntax Android has officially supported : since 2017 and there's good reasons why we fell in love with : first of all the language takes care of a lot of boilerplate allowing the developer to spend more time focusing on the business at hand next Copeland's strong type system helped defend runtime issues like null pointer exceptions and string format issues of course it would be hard to get started with Coplin without scene was interrupt with a java programming language allowing for a gradual adoption of coupling into existing projects finally coroutines provide an elegant way to do this asynchronous programming avoiding spaghetti code often associated with callbacks and it's not just us who embrace caught them a recent survey shows that developers who ate of goblin are 50% more likely to be very satisfied with their programming language that same survey shows that 60% of Android Pro developers are using Copeland in their codebase and 70% of top thousand apps on the Google Play Store are using : code the credit for creating and maintaining Kotlin of course goes to jetbrains and it's wonderful team of engineers since officially supporting : three years ago Google has stepped up to help this awesome project together with JetBrains we have formed a foundation for coupling to ensure the language age as well for example through a careful process of vetting breaking changes our contributions extend beyond policies and reviews has a team of engineers continuing to the köppen compiler as their full-time job currently focused on helping get the new ir back-end and front-end compilers ready we're also working on building : related tooling such as copying symbol processing about which we'll learn more later in this talk here is an overview of some of the ways that we expanded : support in Android in the last year on the library site we added new : first libraries such as paging 3.

0 and jetpack compose we also added new : extensions for play core and Google Maps these make using the existing API it's more code named idiomatic as Android developers you spend a lot of time interacting with the Android SDK that's why in Android 11 we added more nihlus annotations making your calls to those API safer developers productivity comes from great tooling and as such we've added built-in Android code in life templates which allow you to use shorthand to add common Android constructs into your code an app at the same time new code and specific name checks help you make : code more language automatic this is especially useful as you're transitioning from the Java programming language to : looking at the compiler tool chain r8r shrinker tool contains new code and specific optimizations for example eliminating intrinsics checks when it can prove that the whole application doesn't need them materials to help you learn cotton are also expanding for example : for cab you Larry is in the youtube series that explains specific code and keywords in each video looking at the documentation if other pilots are caught in page on developer.


com with all of our latest code labs and guidance for getting started with : finally : everywhere the program that we run together with JetBrains and cotton enthusiasts reach over 30, 000 developers last year was another really big year for copelan and while we're big friends our Copelan we want to reassure you that Android is not dropping support for writing apps in Java Coughlin's is an important contributor to the Java ecosystem and any improvement to the larger ecosystem also benefits cotton developers so I wanted to take a brief detour and show some of the improvements that we've made in the last year for developers targeting the Java ecosystem no matter what language we've been working on the ad sugaring to enable using Japanese Java language features in existing versions of Android this support has been stable in the last few releases and in the end art studio 4.

2 will turn the sugaring of Java eight language features on by default as library support is as important as features Android 11 adds a few additional api's such as off methods on collections to avoid having you wait for this new API to land on most devices we introduced the ability to the sugar core Java language libraries such as streams and time starting an Android studio 4.

0 this makes it easier to use general-purpose open-source libraries on Android this library sugaring functionality was built in close partnership with Google's internal tooling team as you can imagine within Google we're also doubling down on call in over fifty five or four apps are now using code and here you see a few of Google's most popular apps that have already started using clothing in their code bits our large internal code base counts over a million lines of code meant code we have recently started using coding for server-side code as well I personally had the pleasure of writing some code analysis in Colton and then running that code at skill inside a MapReduce on thousands of course as part of us building Kotlin support for internal code base we've had a code and support some of our core libraries such as Dr PC and proto both the GOP C work has recently been open sourced and proto both will follow soon we're also using our large internal code base to help vet the new compiler work that will be available in : 1.

4 and speaking of : 1.

4 it is currently available through the early access preview program and brings many improvements on the compiler side this includes language editions type inference improvements and generating type annotations in byte code of Java 8 plus targets the library site 1.

4 brings a common reflection API program configuration for köppen reflection and new contracts the release also brings a slew of performance improvements all across the board let's take a deeper look at some of the new language editions from an early point cotton has supported Sam or single abstract method conversions for interfaces defined in the java programming language however as cotton supports higher-order functions natively it did not support this for Copland interfaces 1.

4 adds the notion of fun interfaces instances of the find phase can be created using lambda syntax and this feature will make expose encoding API to a java consumer even easier the next feature I want to showcase is a small addition to the language but I believe it's a powerful one up until : 1.

3 parameter lists were not allowed to have a training coma for the last element 1.

4 removes this restriction by allowing the training coma the code looks more symmetrical and it will cause fewer distractions in code review as adding new entries will no longer highlight multiple change lines these new features help with productivity for sure however the biggest thing that will help your productivity is tooling performance we've heard you and both JetBrains and Google are working hard in this area the new front-end compiler which I mentioned earlier will deliver large improvements but as writing a new compiler is a large undertaking you want to make sure the compiler is not only fast but also correct they'll be a while before this is available in this table releases so we need to make sure we add addition performance gains in the meantime we've been working on support in the cotton Gradle plug-in to make annotation processors more incremental as well as helping annotation processor authors make their annotation processors ready for incremental runs to help track IDE performance issues Google and JetBrains teams have been organized being combined performance hackathons these have led to numerous improvements in : 1.

3 dot 60 and above on the Gradle side we're working with Gradle Inc to make drastic changes to its model for incremental compilation under a project and instance execution combined with additional caching for faster up-to-date checks we are seeing up to 30% improvements in controlled experiments this work is under heavy development and expect more news in the coming months one topic around performance I'll talk about is a new project called : signal processing our data shows that many common builds are significantly slowed down by annotation processors the copying tool chain needs to be firm lots of magic to make this run seamlessly between Java and : leading to these performance concerns my team has been working on : symbol processing or KSP as an alternative to this instead of using capped developers can now build lightweight plugins that run as part of the content compilation process KSP allows for incremental resolution of symbols and reporting some existing annotation processors we're seeing 30 to 40% faster compilations KSP comes with a rich set of API and provide access to all coughing symbols including ones that are not available in the java programming language such as properties function types etc KSP is multi-platform ready so you can write your single processor once and use it on all target platforms your project uses we're launching a developer preview of KSP today and while it's not quite ready for production usage we want to invite existing annotation processors authors to give it a spin and provide us with feedback prior this short link visible on the slide and the video description below or via the KSP slack channel on cotton Langille org so far we've seen a lot of great things for both cotton and Android but this is the Android 11 beta launch show so let's briefly talk about Android 11 with Android 11 we have deprecated the async task class and let's be honest it's been an API with a fair share of problems to begin with so what should you use instead well developers have turned to various custom solutions including threats executors higher-level libraries such as Eric's Java or guava and twit : there is one more container and that is Co routines coroutines are a calling way for doing asynchronous programming it will support in the language and library since version 1.

3 was released over one and a half year ago here you see a small example using Co routines to perform an asynchronous call to receive server-side data followed by a synchronous call to store that data in the local database again followed by a UI update coroutines code is executed in a scope in Android we have libraries to tie these lifetime of these calls into the Android lifecycle dispatchers allow you to schedule execution of network and database exits on the i/o background thread acing Network calls can be made through libraries like retrofit that support co-routines out of the box and here we're using rooms court in support to store the data on the device without locking the UI thread finally we pass the value onto the view model to be displayed in the UI with all these asynchronous steps the IDE Clues you in on any asynchronous behavior with the icon on the left side of your code today we're officially recommending Cortines as the way to do a sickness programming in : and if you haven't adopted cotton yet and are struggling with asynchronous programming this is another great reason to take a closer look at goblin you might wonder why so many developers chose to pick co-routines esther acing solution and why we stand by their choice with our official recommendation core routines are particularly good fit for mobile applications running on Android structured concurrency helps developers scope the work to the application lifecycle and to prevent memory leaks next to this callback free code is easier to read and less error-prone while building support for cancellation and natural exception handling helps ensure that error cases is treated gracefully many of our api is already support using co-routines to enter the world of coroutines we have created special Medeco routine scopes that allow you to run async code inside view models and within these scopes you can make use of the covert in support in various jetpack libraries for example in the Android room library which provides structured database access you can easily access databases without blocking the main thread through co-routines meanwhile longer running tasks are often modeled through jobs inside work manager with quarantine worker you can easily model job cancellation both of these are extensions to existing libraries in some of our new libraries we started with quarantines from the ground up a great example is our paging frequent or library and lastly new jetpack compose API will rely heavily on coroutines as composing Cortines complement each other is splendidly composable functions declare snapshots that react to change over time and suspending functions provided change over time so what does this recommendation mean for Java users and people who have adopted other higher-level asynchronous programming libraries the great thing about the Cortines library is that it makes it entirely possible to write interrupt support for both libraries for example paging will ship with our Java and listenable future compatible api's conversely for libraries that have not yet adopted quarantines api's you can use many third-party adapters such as once it converts task-based api from google play services to quarantine suspend calls and you can even write your own we recognize that many of you we want to begin learning about quarantines and we've made sure that you're covered over the previous months we have been updating our learning materials including our quarantine code labs multiple quarantine articles covering a large range of topics from basics to deep lives into quarantine internals and you can check out our conference talks from Android dev summit : calm as well especially recorded Cortines intro videos you can find links to our content in the video description below to wrap things up I hope it's clear to see that Android loves Scotland the language helped developers be more productive and makes them happier with their toolset we continue to expand support for content within Android and Google is expanding its own use of : both on our Android apps as well as on the server Google is working closely with JetBrains to make the language and tools even better : 1.

4 will bring many enhancements and we would love to hear your feedback on : single processing coroutines are now a recommended way of doing a cygnus programming on Android 4 : developers as it provides a structured easter egg and less error-prone way to do the many asynchronous tasks that Android developers need to code all the time for those new to : we hope our continuously expanding documentation code labs and videos helps you get started easily and with that thanks for watching [Music].


See More Android:

Hãy bình luận đầu tiên

Để lại một phản hồi

Thư điện tử của bạn sẽ không được hiện thị công khai.