Can't use android.support.v7.widget.Toolbar with android.useAndroidX=true

半世苍凉 提交于 2020-01-24 20:47:07

问题


in app/build.gradle:

implementation 'com.android.support:appcompat-v7:28.0.0'

in my activity I use

import android.support.v7.widget.Toolbar

Nice. It's work finde.

But when I migrate to androidx I add this:

android.useAndroidX=true
android.enableJetifier=true

As result now my activity not compile with error:

import android.support.v7.widget.Toolbar;

Cannot resolve symbol 'v7'

Is it possible to use android.support.v7.widget.Toolbar together with anrdoidx.* package?


回答1:


Since you are migrating your project to androidx

  1. With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

  2. Remove imports having v7 support and import androidx dependencies all over in your project.

  3. Add implementation 'androidx.appcompat:appcompat:1.1.0' in your app gradle( if not added already).
  4. Import androidx.appcompat.widget.Toolbar in class and replace <android.support.v7.widget.Toolbar/> with <androidx.appcompat.widget.Toolbar/> in XML layout.

Answering your second query : you cannot use both v7 support library and androidx in same project as androidx is full replacement of the Support Library provided in Android Jetpack.

Also update your project to use the final version of the support library: version 28.0.0 (highly recommended).

For further details about androidx migration visit this link.

Hope it helps :)




回答2:


Use the updated component androidx.appcompat.widget.Toolbar and remove all android.support.v7.* packages.



来源:https://stackoverflow.com/questions/56951323/cant-use-android-support-v7-widget-toolbar-with-android-useandroidx-true

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!