1

I want to add an Action Bar to my app. And there is a problem appearing

error: package android.support.v7.widget does not exist.

I cannot fix that problem whatever i tried. Any solution on internet does not work on me.I do not know why this is happening and i am really tired of it. I am the beginner and this problem drives me crazy.I've tried to change

android.useAndroidX=true --> to false

and

android.enableJetifier=true --> false on gradle.properties

Yeah, its work!But here is another problem appearing:

java.lang.RuntimeException: 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 

Here is my build.gradle:

 compileSdkVersion 29 buildToolsVersion '29.0.1' minSdkVersion 21 targetSdkVersion 29 dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' implementation 'com.google.android.material:material:1.1.0-alpha07' testİmplementation 'junit:junit:4.13-beta-3' androidTestİmplementation 'androidx.test:runner:1.3.0-alpha01' androidTestİmplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01' implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:support-v4:28.0.0' implementation 'com.android.support:support-v13:28.0.0' } 

Could be problem on implementation methods, i do not know. May be i have a problem on SDK versions. I have tried migrate to AndroidX and not worked.

5

3 Answers 3

3

Try replacing

android.support.v7.widget 

with

androidx.appcompat.widget 
Sign up to request clarification or add additional context in comments.

Comments

2

Welcome to stackoverflow!

You have both support library and androidx library in one project...that's your issue...

Change the support libraries to the preferred AndroidX library...

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2' implementation 'com.google.android.material:material:1.1.0-alpha07' testİmplementation 'junit:junit:4.13-beta-3' androidTestİmplementation 'androidx.test:runner:1.3.0-alpha01' androidTestİmplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha01' implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' } 

Or you can probably Migrate to AndroidX and it can be done right in Android Studio

Simply go to Refactor > Migrate to AndroidX > Migrate

Adding an Action Bar

<androidx.appcompat.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="@color/yourColor"/> 

I hope this helps....

5 Comments

Yeahi thanks for help. But if i ask, why we cannot use both support libraries and AndroidX. Because i watch a tuttorial and they can import android.support.v7.widget.Toolbar
Then i suggest you use the support library instead of androidx
'android.support.v7.widget.Toolbar' and 'androidx.appcompat.widget.Toolbar' do the same thing...the tutorial you're been taught on is just a bit old...but are you still having any issue?
Dave i am really pleasured for your help, really thanks! The last question is, how can i use only v7.widget? I just wonder it.
Well there's a way you could use android.support.v7.widget.Toolbar in your project..but you could have issues later in the future. Replace com.google.android.material:material:1.1.0-alpha07 with com.android.support:design:28.0.0 then go to your AndroidManifest.xml and add tools:replace="android:appComponentFactory" android:appComponentFactory="whateverString" just below your application tag...it should work
2

Please try this:

implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'com.google.android.material:material:1.0.0' implementation 'androidx.vectordrawable:vectordrawable:1.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0' 

1 Comment

Thank you for answer. I've tried but the problem still persist.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.