Go to Androidx or an exciting journey on the rake
The theme of the transition to Androidx is now in the air. There are already A short article in English from Daniel Lew , there are Report 3-333214. . But they all quite superficially consider the transition scenario described in
Google documentation
3r33333. I want to share my experience. In my project, Moxy and Cicerone are used, I find my experience interesting, because the official telegram channels of these libraries periodically raise the question of when they will be transferred to Androidx.
3r33333. 3r314.
3r33333.
3r33333. 3r3198. Just Migrate to AndroidX
3r33333.
3r33333. In order to translate a project on Androidx, you need to follow a few simple steps:
3r33333. 1. Install 3r3192. compileSdkVersion 28 [/i] and 3r3192. targetSdkVersion 28 [/i] , update all support libraries to the latest versions.
3r33333. 2. In the file 3-333180. gradle.properties [/b] add lines:
3r33333. 3r3338. android.useAndroidX = true
3r3342.
android.enableJetifier = true
3r33333. 3. If you are already using Android Studio 3.? then use refactoring: 3r-3200. 3r33333. 3r33333. He will do more (or less) for you.
3r33333. If you, for some reason, do not use Git, or another version control system, then at this stage you will have a chance to make a project archive:
3r33333. 3r33333.
3r33333. Click the Migrate button, choose where to save the archive, and after a while, we get the result of checking the project before refactoring: 3r-3200. 3r33333. 3r361.
3r33333.
3r33333. Here we see which dependencies in build.gradle and in import directives will be replaced. On the example of the MainActivity class, as can be seen in the screenshot above, one dependency will be replaced: android.support.v4.view.GravityCompat , but if we open this class, we will see that in fact there are three more dependencies that need to be replaced:
3r33333. 3r33333.
3r33333. I did not understand the reason for this selective behavior, but these dependencies will have to be corrected manually. Click "Do Refactor".
3r33333.
If you are not using Android Studio 3.? then all dependencies are manually edited by [/b] 3r380. It will be necessary to change the dependencies in build.gradle (for clarity, I commented out the old dependencies):
3r33333. 3r33333.
3r33333. A complete list of replacements can be found 3r390. here is
.
3r33333. Then synchronize the project with Gradle, and get a bunch of errors. These are import directives in your classes, they refer to old packages, you need to change them according to 3r3394. this table
.
3r33333. 3r33333. 3r33333.
3r33333.
3r33333. So, since the studio could not replace all the dependencies (maybe you could, then you can be congratulated), when you try to build a project, you will see a similar list of errors: 3r33200. 3r33333. 3r33333.
3r33333. Having opened a class with errors, we will see something like this:
3r33333. 3r3113.
3r33333.
3r33333. We delete the obsolete dependencies, and by the Alt + Enter hotkey we import classes from the package. androidx
3r33333. 3r3122.
3r33333.
3r33333. Thus we fix all the classes. If the error is not related to the “import”, do not pay attention to it, most likely it is due to the same problems in another class.
3r33333. For example: 3r33200. 3r33333. 3r33333.
3r33333. Here, errors are due to the fact that the TimelineView class also needs to fix problems with imports. When all the errors are corrected, we build the project again, and perhaps we get a list of errors again, only in other classes, the process is iteratively continued.
3r33333. For errors with classes that are generated (Dagger or DataBinding), at this stage do not pay attention. If there are no errors in your classes, and the studio swears only on the generated code, then you need to run the Clean Project and the Rebuild Project.
3r33333. 3r33140.
3r33333. If that doesn't help, you can try clearing the studio cache:
3r33333. 3r3145.
3r33333. You will have to clear the cache at least once to correctly create classes that generate a DataBinding or Room.
3r33333.
3r33333. 3r3198. External libraries 3r3-3999.
3r33333. Generally, the flag android.enableJetifier = true we installed it just so that at the project build stage, the dependencies of external libraries were replaced with the corresponding AndroidX dependencies automatically, but for some reason, for me, this does not happen.
3r33333. In any case, before doing what is described below, make sure that you have this problem and that the latest versions of the libraries you use are not yet translated to AndroidX.
3r33333.
3r33333. 3r3186. Moxy 3r3r7187.
3r33333. 3r3192. MainActivity [/i] in my project inherited from MvpAppCompatActivity This class is Moxy, which, at the time of this writing, has not yet been translated to AndroidX. To solve this problem, I copied the class to my project, in a separate package androidx and fixed dependencies in it. The class name is best left unchanged, so it will be easier to update dependencies.
3r33333. The same procedure needs to be done for fragments, for the class MvpAppCompatFragment .
3r33333. Note that in these classes there is a generic, in the field mMvpDelegate , do not forget to fix the dependency in it, it is easy not to notice, because it is a dependency on the Moxy class, and not on the support library class.
3r33333.
3r33333. 3r3186. Cicerone
3r33333. To solve problems with Cicerone, I had to create in my project a copy of the class. SupportAppScreen and 3r3192. SupportAppNavigator [/i] . Please note that the SupportAppNavigator class depends on SupportAppScreen. Do not forget to correct this dependence on your copy.
3r33333.
3r33333. 3r3198. Conclusions 3r-33199.
3r33333. The transition to AndroidX, an exciting experience, and perhaps, if you do not have an urgent need, it is worth a little delay with it. After all, then, when most of the rake is removed from your path, it will be easier and faster to do this. But personally, I am pleased that I have gone this way, the bumps on my forehead will heal, and the useful experience will remain with me. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333. 3r33333. 3r33333. 3r33333.
Only registered users can participate in the survey. Enter , you are welcome.
3r33333. 3r33333.
3r33333.
3r33333.
Have you switched to AndroidX? 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333.
3r33333. 3r33232. 3r33333.
3r33333. 3r33333.
3r33333. 3r3309. 3r33333. 3r33311. 3r33333.
3r33333. Yes, there were similar problems. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333. 3r3309. 3r33333. 3r33311. 3r33333.
3r33333. Yes, and this is not the main rake, I will share in the comments. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333. 3r3309. 3r33333. 3r33311. 3r33333.
3r33333. Yes, but it was much easier. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333. 3r3309. 3r33333. 3r33311. 3r33333.
3r33333. No, but right now I'll do it. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333. 3r3309. 3r33333. 3r33311. 3r33333.
3r33333. No, wait for it to be easier. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333. 3r3309. 3r33333. 3r33311. 3r33333.
3r33333. No, I do not understand why it is, and so everything works. 3r33333. 3r33333. 3r33333. 3r33333. 3r33333.
3r33333.
3r33333. 3r33333.
3r33333. 3r33333. 3r33333. 3r33333. 6 users have voted. Abstained 2 users. 3r33333. 3r33333. 3r33333.
It may be interesting
weber
Author22-11-2018, 14:27
Publication DateDevelopment / Programming
Category- Comments: 0
- Views: 280
nursing test bank
nursing test bank