How to Update all Android Studio Libraries in Androidx

0
172

After working and searching for hours and you can’t get the solution you are looking for. You are welcome to the home of Android Developer. If you have

 


being using Android Studio for writing Java apps, Java codes is everything sensitive raging from capital letters, punctuation errors, misspelled of words and plugin updates.

dependencies { 

 

//…

implementation ‘com.android.support:appcompat-v7:28.0.0’

implementation ‘com.android.support.constraint:constraint-layout:1.1.3’

// materail io

implementation ‘com.google.android.material:material:1.0.0’

//…

}

Sync gradle. If you will be lucky as me you will see an error

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from

[com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91

is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory).

Suggestion: add ‘tools:replace=”android:appComponentFactory”‘ to <application> element at AndroidManifest.xml:5:5-19:19 to override.

It happened because we should not use the com.android.support and com.google.android.material dependencies in the app at the same

time. I will exploit the circumstances to migrate to androidx. In the mapping table we can see com.android.support:appcompat-v7 maps

to androidx.appcompat:appcompat:1.0.0

dependencies {

//…

// to android x

implementation ‘androidx.appcompat:appcompat:1.0.0’

implementation ‘com.android.support.constraint:constraint-layout:1.1.3’

// materail io

implementation ‘com.google.android.material:material:1.0.0’

//…

}

Sync and rebuild our project. There is no error with sync but rebuild finished with ‘compilation failed’. That’s because we are using

import from now unknown library (android.support)

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

Most common replacements are:

android.support.v7.widget.RecyclerView → androidx.recyclerview.widget.RecyclerView

androidx.constraintlayout.ConstraintLayout → androidx.constraintlayout.widget.ConstraintLayout

android.support.constraint.ConstraintLayout → androidx.constraintlayout.widget.ConstraintLayout

android.support.constraint.Group → androidx.constraintlayout.widget.Group

android.support.v7.widget.GridLayoutManager → androidx.recyclerview.widget.GridLayoutManager

android.support.v7.widget.LinearLayoutManager → androidx.recyclerview.widget.LinearLayoutManager

<android.support.design.widget.AppBarLayout–><com.google.android.material.appbar.AppBarLayout

<android.support.v7.widget.Toolbar–> <androidx.appcompat.widget.Toolbar

android.support.design.widget.CoordinatorLayout

android.support.design.widget.AppBarLayout

android.support.v7.widget.Toolbar

android.support.design.widget.TabLayout

android.support.v4.view.ViewPager

to this;

androidx.coordinatorlayout.widget.CoordinatorLayout

com.google.android.material.appbar.AppBarLayout

androidx.appcompat.widget.Toolbar

com.google.android.material.tabs.TabLayout

androidx.viewpager.widget.ViewPager

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

}

Change to androidx.appcompat library from androidx and rebuild

//import android.support.v7.app.AppCompatActivity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

}

Nice! All Fixed! All we need now is change default them and we can use any elements from material io to android

<resources>

<!– Base application theme. –>

<style name=”AppTheme” parent=”Theme.MaterialComponents.Light.DarkActionBar”>

<!– Customize your theme here. –>

</style>

</resources>

add text field

<com.google.android.material.textfield.TextInputLayout

android:layout_width=”match_parent”

android:layout_height=”wrap_content”

android:hint=”Enter here”>

<com.google.android.material.textfield.TextInputEditText

android:layout_width=”match_parent”

android:layout_height=”wrap_content”/>

</com.google.android.material.textfield.TextInputLayout>

and run in a simulator


Picasso in androidx
Picasso.get().load(imageUri).into(ivBasicImage);

Picasso.with(viewHolder.itemView.getContext()).load(imageUrl).into(viewHolder.field_image_thumb)

Picasso.with(context).load(imageUrl).into(viewHolder.field_image_thumb);

android.support.design.widget.FloatingActionButton

com.google.android.material.floatingactionbutton.FloatingActionButton

android.support.design.widget.CoordinatorLayout
androidx.coordinatorlayout.widget.CoordinatorLayout

com.google.android.material.navigation.NavigationView
android.support.design.widget.NavigationView.

android.support.design.widget.AppBarLayout
com.google.android.material.appbar.AppBarLayout

android.support.v7.widget.CardView
androidx.cardview.widget.CardView

android.support.v7.widget.Toolbar
androidx.appcompat.widget.Toolbar

android.support.v7.widget.RecyclerView
androidx.recyclerview.widget.RecyclerView

androidx.core.widget.NestedScrollView

android.support.design.widget.TextInputLayout
com.google.android.material.textfield.TextInputLayout