Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the pits that use AndroidX?

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "what are the pits that use AndroidX". In the daily operation, I believe many people have doubts about the problems of using AndroidX pits. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the questions of "what are the pits that use AndroidX?" Next, please follow the editor to study!

First, let's start with a new project.

3.5 create a new project that uses androidx by default

Look at the last one, Use androidx.* artifacts. And it can't be cancelled.

1.1. So what do these two sentences represent?

It means that if you use support's package, he will automatically transfer it to androidx for you. Here's an example (the bug in the following example is for system libraries). For example, we used to use AppBarLayout in support to combine CoordinatorLayout to achieve cool effects. As we all know, this is in support's design. So let's add it, and note: adding packages after studio3.5 will be a little different.

Right-click your project and select Open Module Setting

In the open screen, select Dependencies, click the plus sign inside, and continue to select Library Dependency

In the search box, search for design. There is a bunch (this is how the version of androidx is selected), here we choose com.android.support

When you choose to join, studio automatically build and adds dependencies. Build.gradle will add

Implementation 'com.android.support:design:28.0.0'

Note: if you go to xml and type AppBarLayout at this time, you will not be prompted, or even not at all. What I think is that studio3.5 is so optimized that you won't help us with the rebuild project, and I don't know if bug; clicks on build-> Rebuild Project, the project at this time. After that, xml is used normally, as follows

You will find that this is not the support package, click in is the migrated androidx package. It is precisely because of the two words of gradle.properties that helped us to finish it. Build.gradle still shows support's package, what should I do?

Extra note: just like the bug problem mentioned above, if you build.gradle this dependency at this time, if you press the previous action, we will click Sync Projec with Gradl Files to update it. After that, the project didn't have this bag. Yes, it's the same with studio3.5, but when you continue to type AppBarLayout in xml, you will still be prompted, and there will be no error in xml and it will run. It is only after running that it crashes and reports an error. The right thing to do still needs to be done. After getting rid of the dependency, continue to click Rebuild Project, and then it will be normal. (it feels like bug at this time.)

Change the support package of build.gradle to andoridx with one click

Click Refactor-- > Migrate to AndroidX

Follow up by default, I will not map here, just say operation, Migrate-> (select our project, click OK)-- > YES. The following picture will pop up later.

Click Do Refactor. After that, the 'com.android.support:design:28.0.0' will be changed directly to the responsive androidx package

Implementation 'com.google.android.material:material:1.0.0'

3. Some people may have upgraded studio, but not like using androidx

The right thing to do is to remove the two sentences from gradle.properties. At the same time, change your build.gradle to your previous support package. We know that the last version of the support package is 28. After that, all guide packages will no longer be migrated. It's support, which is the support package.

At this point, the study of "what are the pitfalls in using AndroidX" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report