android项目迁移到androidx

1.Android Studio自带可以把项目升级为Androidx

android项目迁移到androidx_第1张图片

2. 在gradle.properties文件添加

android.useAndroidX=true
android.enableJetifier=true

3.修改java类引用

import androidx.core.view.PagerAdapter;    import androidx.viewpager.widget.PagerAdapter;

import androidx.core.view.ViewPager;         import androidx.viewpager.widget.ViewPager;

import android.support.v7.view.ContextThemeWrapper;    import androidx.appcompat.view.ContextThemeWrapper;

 

修改前import android.app.FragmentManager;     修改后 import  androidx.fragment.app.FragmentManager;

import androidx.core.app.FragmentPagerAdapter;   import androidx.fragment.app.FragmentPagerAdapter;

import androidx.core.app.Fragment;        import androidx.fragment.app.Fragment;

import androidx.core.app.FragmentActivity;       import androidx.fragment.app.FragmentActivity;

import androidx.core.app.FragmentStatePagerAdapter;   import androidx.fragment.app.FragmentStatePagerAdapter;

import android.support.v7.app.AppCompatActivity;      import androidx.appcompat.app.AppCompatActivity;

import androidx.core.app.FragmentTransaction;    import androidx.fragment.app.FragmentTransaction;

 

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

import android.support.v4.widget.SwipeRefreshLayout;      import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import androidx.core.widget.SwipeRefreshLayout.OnRefreshListener;  import  androidx.swiperefreshlayout.widget.SwipeRefreshLayou.OnRefreshListener; 

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

import android.support.v7.widget.LinearLayoutManager;   import androidx.recyclerview.widget.LinearLayoutManager;

import android.support.v7.widget.AppCompatImageView;   import androidx.appcompat.widget.AppCompatImageView;

import androidx.core.widget.DrawerLayout;    import androidx.drawerlayout.widget.DrawerLayout;

 

import androidx.core.util.LruCache;     import androidx.collection.LruCache;

import androidx.core.util.SimpleArrayMap;   import androidx.collection.SimpleArrayMap;

 

import android.support.annotation.DrawableRes;   import androidx.annotation.DrawableRes;

import android.support.annotation.NonNull;   import androidx.annotation.NonNull;

import android.support.annotation.Nullable;       import androidx.annotation.Nullable;

import android.support.annotation.IntDef;    import androidx.annotation.IntDef;

import android.support.annotation.AnimRes;    import androidx.annotation.AnimRes;

import android.support.annotation.AnimatorRes;   import androidx.annotation.AnimatorRes;

import android.support.annotation.ColorInt;    import androidx.annotation.ColorInt;

import android.support.annotation.RequiresApi;   import androidx.annotation.RequiresApi;

import android.support.annotation.RequiresPermission;    import androidx.annotation.RequiresPermission;

import android.support.annotation.IdRes;    import androidx.annotation.IdRes;

import android.support.annotation.FloatRange;    import androidx.annotation.FloatRange;

import android.support.annotation.IntRange;    import androidx.annotation.IntRange;

 

 

import android.support.design.internal.BottomNavigationItemView;   import com.google.android.material.bottomnavigation.BottomNavigationItemView;

import android.support.design.internal.BottomNavigationMenuView;   import com.google.android.material.bottomnavigation.BottomNavigationMenuView;

import android.support.design.widget.BottomNavigationView;  import com.google.android.material.bottomnavigation.BottomNavigationItemView;

 

 

4.修改布局文件中的控件

如:RecyclerView   ViewPager等

 

5.使用非androidx的第三方库时报错如:

android项目迁移到androidx_第2张图片

解决:项目中添加依赖如:

android项目迁移到androidx_第3张图片

 

 

 

 

介绍参考:https://blog.csdn.net/haoxuhong/article/details/100584316

操作参考:https://www.jianshu.com/p/0805698a3b23

你可能感兴趣的:(Android其它)