Migrating to AndroidX: The time is right (Android Dev Summit '19)

[Music] everyone my name is Nick Anthony and I'm a program manager with jetpack hello everyone my name is Tim song I'm a developer programs engineer on the Android dev rel team today we're going to talk about migrating your app to Android X great so before we dive in it's important to ask ourselves what is Android X we throw a lot of terms out there so by a show of hands who here has heard of Android X ok by a show of hands who here has heard of jetpack by a show of hands who here has heard of the support library ok by a show of hands here knows what the difference is between all those great so for those of you I think I caught most of people in the room but for those of you who needs more fication or clarification or may not know jetpack is the set of libraries tools and guidance to help you developers write high-quality apps easier so we think of that in terms of three things that's best practices eliminating boilerplate code and simplifying complex tasks so you can focus on the code that you really care about so how's this way to Android X's you can see on the slide Android X is the package name for all libraries within jetpack so we think of Android X says this is the open source project that we use to develop test version and release jetpack libraries now how is this ready to support library so if you remember back in IO of 2018 we announced that we'd be refactoring the support library to the Android X namespace so we did this with support library 28 we also announced Android x1 dot o and so we'll touch on that a little bit about why it's important great so we've got to the point now we kind of talked a little about what these things are and now there's the next question when I ask ourselves is why should I migrate why is this talk important why are we here so there's kind of four points want to bring up one is that the support library is done 28 Auto was the last release of the Android support namespace so this is a namespace for no longer maintaining so if you want bug fixes or new features that normally would have gone in the support library you're gonna need to go and migrate to Android X the next thing you get some better package management so these are kind of the reasoning why we made the refactor that's the standardized and independent versioning as well as the better naming and standardized naming and more frequent releases these are kind of what you get of the box with Android X the third thing is that you're gonna the other some other libraries have migrated to the Android X namespace so there's some notable notable players in there as well as you know Google Play services firebase butter-knife mockito – in some cases in sequel delight and we're going to touch on migrating these dependencies in just a minute the final thing we want to point out is that all new libraries are coming out in Android X so we're really pushing forward on the Android X namespace and so some of you might have heard of things like jetpack compose or camera X those are going to be in the angel vex namespace and a precursor is gonna be migrating to Android X so now we've talked about what these things are what is jetpack what is Android X we've also talked about why you should migrate I'm gonna pass her a team now to talk about the specifics of actually going through this migration thanks Nick so let's go ahead and talk about how we want to migrate but before we do that here are some things to do to prepare your project for migration so you can have a more smoother experience first back up your project now many of you might be using source control so that's probably okay but just in case make a backup of this project because the migration will change many of the files in your project next we want you to try to minimize future development during this time and we'll cover this more in a little bit and also try to make these migrations on a separate branch now we have recommended approach on how to migrate now I know are a lot of steps and we'll explore these one-by-one I'll explore steps one through three and then Nick will talk about steps four and five so first we want to update the support library to version 28 now if you're on a older version of the support library stage 26 or 27 and try to make the migration all the way to Android X well you're probably going to have a bad time that's because not only will you need to address the namespace changes but also the API changes between 26 27 28 and Android X so what we suggest is first try to update to version 28 and address all of those API changes and get your app compiling with 28 and at that point make them jump over to Android X now support library version 28 and Android X 1.

0 our binary equivalent so what does that mean that means only the package name changes between those two versions all the AP errors are the same so this way you'll have probably a minimal set of things that you need to fix between migrating from 28 to Android X so now that you've migrated your app to support library 28 we next want to enable jeddah fire so what is jeddah fire and why is necessary so dirty fire will help you migrate your third-party dependencies that use Android X what this means is that judgeth fire will actually change the bytecode of those dependencies to be compatible with your project that's using Android X now general fire won't do a couple of things it won't change your source code nor will it change your migrated up bullet nor will it migrate your generated code so once you well here's how to enable data fire in your app you add a couple of lines to your Gradle dot properties files and then here use Android X is set to true along with enable Jetta fire now the use Android X setting turned a true me that when you do code auto-completion and you're importing libraries you'll import the Android X version of that library instead of the old support library version alright so moving on to step three once you've enabled Jetta fire we'll need to update your dependencies so a lot of third-party dependencies may need to be updated before you actually start the migration so here are some of the dependencies that we covered earlier and I want to highlight a specific example now one of our flagship sample apps is called plaid and it uses the Glide image loading library we wanted to use plaid as an example of how to migrate over to Android X and we discovered when we did the migration without first migrating our Glide dependency we ran into a bunch of compilation issues and we look at me found that version of Glide that we were using was not Android X compatible so what we did was we first updated Glide and our other dependencies and then ran the Android X migration and then that error no longer appeared so if you can try to update your third-party dependencies first before starting the migration now if you using a code generation library a jitter fire won't modify these so you might need to check if the code in eration library actually is compatible with Android X so let's look at some common errors that might happen if you skip steps two and three of one of which is the third-party code that you're using is not compatible with Android X you'll see that as trying to pull in the old version of the support library also if you have a project that's partially migrated you might get a duplicate class error we're trying to pull in the same code from both the support library and Android X so back over to Nick to talk about step four thank you so now this point we're going to talk a little more about the actual source code so we've gone through we've got support library 28 we've enabled Jetta fire we got our dependencies in order now we're going go in and as of Studio 3.

2 stable and above there is a handy my great Android X button so you can see under the refactor how they'd in blue here there is a migrant Android X what that will do was migrate your source code and this will work for a majority of cases now however we do realize that some teams me out you studio or you know there is some more sophisticated architectures that are truly can't exactly automate so there's leaves you with two options here so these options include just migrating the source code itself and what options use a bash script so this is a grep and said and we'll talk we'll see the script in just a second here in the next slide and we want to before we dive in there we want a special thanks to Dan Lew for fitting this up you can follow this go link goog le a / Android X migration script and that'll link you to the github source page where you can see that script as well as more community contributions so how about that script you can see here we have the class mapping as well as your project and what is effectively just a grep command followed by a said command to replace those package names one thing to note when using the script it's pretty brute force it's a it is a it is a bash script so it may do some of those migrations incorrectly in some cases so just be aware of that when you're using this con this kind of methodology the other option is get your hands you didn't do it by hand so if you go to developer.

android.

com put our migrate android X page we have an artifact mapping from the support library packages to our new ones as well as a class mapping with the same support library to Android X and that ax lets you do kind of a case-by-case basis so you know what's right so at this point if you've kind of managed to follow us along this long path you get your project compiling again and fix any tests that may have broken along the way you'll have a project that's running on Android X which is awesome so before we end this talk I think it's also important to talk about some issues that the community has run into and so I'm gonna pass sort of team note to dive into those so you know about them ahead of time so here are some issues that you might run into for your migration so there are some things that we cannot automate so your version control files may require some manual intervention now let's go ahead next I see that in action here is your build.

gradle file prior to migration now you'll note that we use the old support library and then here we actually extract out our version variables into its own separate section now after running the migration tool we now have our drawer layout and recyclerview using the new Android X packages but you'll notice that the version numbers are now in lined and the variable numbers are not yet changed so the tool does not modify this so you'll need to manually update this as such let's change the drawer and recyclerview versions manually take 1.

0 and then we'll need to inline those variables back in so something to be aware of next the tool is enabled to migrate your ProGuard and any built scripts so if you're using these and have package names in them you'll need to go in and manually edit these as well now earlier we talked about trying to slow down development or working on separate branches and we'll talk about this a little bit more because so many files will need to change we suggest that if possible try to slow down or stop development entirely I know this is like a very very big ask asking entire development team to stop development but this definitely reduces the amount of merge conflicts that will happen if you can have a few people on your team just focus on the migration and then have everybody else to say like hey there's a big like merge conflict that will come that will happen in your future so let them know about this ahead of time also try to do the migration on a separate branch when you're doing this migration it's good to just focus on addressing the errors and getting your app to compile and all test passing again don't try to do refactoring or don't try to pull in new features during this time it'll just make this a lot more difficult so when you run this migration tool you may have an alpha version or a stable version of the library depending on the most recent release now here we have the support library version of app compat and we run a migration tool which migrates our app compat to an alpha version of the library now depending on your particular needs in your project you may want to use an alpha version or maybe you prefer stable so this is something that you'll need to go back and manually check to see which version of migrated to and make sure that you select the version that's appropriate for your needs and you can find more about these particular versions in the table and we'll cover that in our resources section so we have our Android X documentation on our developer.

android.

com/design droid X project our migration guide the mapping table of the old support library to the new stable and alpha versions and also the CSV files if you want to script your migration we also wrote an article detailing our migration to Android X in the plant sample project and in here we uncover like the steps that we took some of the problems that we ran across and the solutions to those problems and you can access that by a goog ollies slash plaid – Android X – migration and finally we have the issue tracker where you can go to see the issues that we're currently working on what the migration tool or if you like you can create a new issue using the button at the top left of the page so we wish you the best of luck and migrating your app to Android X and if you're attending the conference in person please stop by our jetpack sandbox with any questions tell us about your experience and migrating thank you very much thank you [Applause] [Music] you.

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.


*