Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't resolve android.support.design. after migration to AndroidX

I am trying to get the TextView of the Snackbar with this code snippet:

snackbarView.findViewById<TextView>(android.support.design.R.id.snackbar_text)   

but Android Studio does not resolve the design library.

How can I get this code to work?

like image 957
dudi Avatar asked Oct 18 '18 11:10

dudi


People also ask

Is it good to migrate to AndroidX?

So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX. Better package management. With AndroidX, you get standardized and independent versioning, as well as better standardized naming and more frequent releases.

How can I use AndroidX on Android?

Using androidx libraries in your project If you want to use androidx -namespaced libraries in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the following Android Gradle plugin flags to true in your gradle. properties file. android.

Why migrate from Android support library to androidx?

The time is right now to migrate from using the Android Support Library to AndroidX. There are four reasons behind this: The Android Support Library has reached the end of its life. 28.0 was the last release of the Android Support namespace and the namespace is no longer maintained.

How to migrate from Android Studio to Android X?

Migrating to AndroidX 1 Prerequisites. Before you migrate, bring your app up to date. ... 2 Migrate an existing project using Android Studio. With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the ... 3 Mappings. ... 4 Additional resources. ...

Why is it so hard to migrate from Visual Studio to Android?

This can come as quite a challenge especially to massive projects that are quite old. Anyone who has tried to use the built in visual studio “Migrate to Android X” feature has probably realised that it doesn’t always work and you’ll run into compilation errors.

What happened to the Android support library?

The Android Support Library has reached the end of its life. 28.0 was the last release of the Android Support namespace and the namespace is no longer maintained. So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX. Better package management.


2 Answers

Solved with this solution: snackbarView.findViewById<TextView>(com.google.android.material.R.id.snackbar_text)

like image 177
dudi Avatar answered Sep 23 '22 02:09

dudi


Thanks for the great answer by @dudi, in general in migration to androidX you can replace

android.support.design.R

with

com.google.android.material.R

I have written a brief step-by-step article on AndroidX migration here, if someone is interested to know more.

like image 23
Ali Nem Avatar answered Sep 22 '22 02:09

Ali Nem