Error "package android.support.v7.app does not exist"
Asked Answered
L

18

62

I am new to android development, and I have been using the command line tools to create an android project. I followed all the instructions given in the tutorial at android developers. However, they are focused more on IDE users.

When I tried extending my MainActivity class from ActionBarActivity instead of just Activity, it threw the following error.

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

It was complaining about this import statement.

import android.support.v7.app.ActionBarActivity;

I made sure to visit the SDK manager, and it says Android Support Library is installed. I am truly stumped on this one, and I would really appreciate any help you guys could give me.

This might help: http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html

Lampert answered 28/4, 2014 at 0:37 Comment(4)
You have to add the appcompat library to your project, it's not enough to just download it with the sdk manager. You can find information here and here.Take
I have run into the same problem. I'm not sure why @vgonisanz's answer was accepted - I can't right click libraries in from the command line. I'm not using Gradle either - the command line tools default to Ant, so I installed Ant.Interblend
@Iiridayn: Yeah, I ended up giving up on the command line tools. Android studio is a really nice IDE, and ended up being way less of a hassle than trying to compile with ant.Lampert
for androidx see https://mcmap.net/q/319942/-error-quot-package-android-support-v7-app-does-not-exist-quotCarbonic
P
15

Your project is missing the support library from the SDK.

If you have no installed them, just right click on the project > Android Tools > Install support library.

Then, just import into workspace, as an Android project, android-support-v7-appcompat, located into ${android-sdk-path}/extras/android/support/v7

And finally, right click in the Android project > Properties > Android Tab. Push the Add button and add the support project "android-support-v7-appcompat" as dependency.

Clean your project and the must compile and work properly.

Preventer answered 7/7, 2014 at 10:58 Comment(3)
This is outdated nowGaunt
For those who migrated to androidx, here is a list of mappings to new packages: developer.android.com/jetpack/androidx/migrate#class_mappingsBlackfellow
the changes are so quick...! I think the updated time frame shouldn't be too quick as this one...Powell
T
104

First of all check if your project is using androidx or android support library. Check gradle.properties file:

android.useAndroidX=true

android.enableJetifier=true

If it contains the above lines, it is using androidx with an old code from some old tutorial.

In build.gradle (module:app)

Use

implementation 'androidx.appcompat:appcompat:1.0.0'

Instead of

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

Also in MainActivity.java : Use

import androidx.appcompat.app.AppCompatActivity;

instead of :

import android.support.v7.app.AppCompatActivity;
Tropism answered 8/8, 2019 at 7:8 Comment(6)
It would be much helpful If you could share What all changes to be done id we dont want to use andoridx i.e if we want to use android.support.v7.... ThanksLollard
I think everyone has to switch to androidx, there is not an optionTropism
Thanks But, I found a way I just deleted all androidx lines and replaced them with supprtWidgetV7 and restarted (invalidate cache and restart) Everything started working fine And... btw I am a newbie in android, can I know which one is old/new among these, and which one is better and why ThanksLollard
androidx is new v7 is old, v7 is deprecated. Everyone has to use androidx in future.Tropism
for androidx see https://mcmap.net/q/319942/-error-quot-package-android-support-v7-app-does-not-exist-quotCarbonic
any shortcut for importing thisimport androidx.appcompat.app.AppCompatActivity; in whole projectFlawed
F
27

If the issue reported from MainActivity.java then replace

import android.support.v7.app.AppCompatActivity;

with

import androidx.appcompat.app.AppCompatActivity;
Fragonard answered 7/2, 2020 at 14:40 Comment(1)
we are forced to move forward.... right @siva?Powell
P
15

Your project is missing the support library from the SDK.

If you have no installed them, just right click on the project > Android Tools > Install support library.

Then, just import into workspace, as an Android project, android-support-v7-appcompat, located into ${android-sdk-path}/extras/android/support/v7

And finally, right click in the Android project > Properties > Android Tab. Push the Add button and add the support project "android-support-v7-appcompat" as dependency.

Clean your project and the must compile and work properly.

Preventer answered 7/7, 2014 at 10:58 Comment(3)
This is outdated nowGaunt
For those who migrated to androidx, here is a list of mappings to new packages: developer.android.com/jetpack/androidx/migrate#class_mappingsBlackfellow
the changes are so quick...! I think the updated time frame shouldn't be too quick as this one...Powell
I
10

Using Android Studio you have to add the dependency of the support library that was not indicated in the tutorial

dependencies {

    implementation 'com.android.support:appcompat-v7:22.0.0'
}
Ingemar answered 21/5, 2015 at 20:0 Comment(1)
A
9

If you are using latest Android Studio, then v7 libraries contradict with AndroidX, only you have to do is:

In Project files go in gradle.properties
Find out android.useAndroidX=true then set it to android.useAndroidX=false
Find out android.enableJetifier=true then set it to android.enableJetifier=false
Rebuild your project, all will working fine.

Aldred answered 18/8, 2019 at 12:23 Comment(2)
Thx! I had no idea Android Studio had enabled AndroidX without asking...Lickerish
I need import androidx.appcompat.app.AppCompatActivity; to debug some legacy code, and struggled for DAYS as Android Studio REFUSED to work, Until I stumbled across these two lines in the toplevel build.gradle. I set them to "false" ... and everything magically started working.Trish
D
7

Switching to AndroidX helped me: import androidx.appcompat.app.AppCompatActivity;

Dateless answered 12/9, 2019 at 17:16 Comment(1)
Works for me, Thanks SamiTicktock
C
5

For what it's worth:

I ran in to this issue when using Xamarin, even though I did have the Support packages installed, both the v4 and the v7 ones.

It was resolved for me by doing Build -> Clean All.

Cupel answered 29/8, 2016 at 13:11 Comment(0)
H
3

For those who migrated to androidx, here is a list of mappings to new packages: https://developer.android.com/jetpack/androidx/migrate#class_mappings

Use implementation 'androidx.appcompat:appcompat:1.0.0'

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

Headlight answered 21/7, 2019 at 6:54 Comment(0)
W
2

If your app is AndroidX, This response may apply to your problem:

npm install --save-dev jetifier
npx jetify (may take a while)
npx react-native run-android
Wsan answered 3/9, 2019 at 10:31 Comment(0)
S
2

I use:

npx jetifier

this fix the problem.

ref: Cannot build Ionic App on Android once installed BackgroundGeolocation Plugin with Capacitor

Sidnee answered 25/9, 2020 at 22:47 Comment(0)
C
1

try to copy C:\Program Files\Java\jdk1.8.0_121 && C:\Program Files\Java\jre1.8.0_121 from other working PC then all (clean && rebuild)

Cruel answered 1/5, 2017 at 8:35 Comment(0)
A
1

If you are using SDK 28 or higher, you need to migrate to AndroidX library.

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.

Arjuna answered 8/10, 2019 at 11:49 Comment(1)
I think, he don't use to SDK 28. Because the question was asked 5 years ago.Punctuality
C
1

For AndroidX implement following lib in gridle

implementation 'androidx.palette:palette:1.0.0'

and import following class in activity -

import androidx.palette.graphics.Palette;

for more info see class and mapping for AndroidX https://developer.android.com/jetpack/androidx/migrate/artifact-mappings https://developer.android.com/jetpack/androidx/migrate/class-mappings

Carbonic answered 22/4, 2020 at 4:29 Comment(0)
C
1

It is 2020 December. The same problem came to me in a different way. When I was going to Deploy in google play store, it said I have to create the bundle higher than android v28 and I updated my projects Compile using Android Version 30 (in Xamarin Android project properties). It was not possible to do it with the same error (Android support library has no support for V7). I tried everything mentioned above and was not working and here is what worked for me. I was using this in splashactivity.cs

using Android.Support.V7.App;

And it is the one giving the trouble and i changed it into V4

using Android.Support.V4.App;

then AppCompatActivity was underlined red and I had to get androidx appcompat app as follows

using AndroidX.AppCompat.App;

Now it is working and it may help someone else too.

Cockcrow answered 16/12, 2020 at 3:18 Comment(0)
P
0

I'm a beginner but what I did for my code to work was to import androidx hence replacing the android.v7 then I erased the support.v7 line and my code worked. I'm sorry I couldn't explain in more technical terms but that's what worked for me. Actually the Java codes were codes I copied from an old tutorial hence the error encountered. Hope this helps.

Phenolic answered 4/1, 2020 at 23:9 Comment(0)
R
0

I just got this error today and this is how I fixed.

  • On my build output, I double click on the class with the error.
  • After the class opened, I expanded the imports section and deleted existing imports with errors.
  • I then hovered my mouse near the errors which were:RecyclerView,LinearLayoutManager, and FragmentTransaction and chose Alt+Enter to import appropriate classes.

Note: in my case, the error occured after I migrated one of my old projects to androidx and so imports hard to be androidx related. I am using android studio.

Note: You may run into other issues, so everytime I run into an error, I check other called classes and makes sure their imports are correct. What I do mostly is press ctrl+shift+R, and put the old import in the first field and the correct import on the second field and then replace all. This way, I replace all imports that in the project at once.

You can use ctrl+shift+f to find where imports are used.

Railhead answered 17/2, 2020 at 9:28 Comment(0)
C
-1

If you have a problem with dependencies when download a new version, try...

FILE....MANAGE IDE SETTINGS...RESTORE DEFAULT SETTINGS

Clerc answered 28/2, 2021 at 0:39 Comment(0)
E
-3

After Rebuild the project issue resolved..

Eaglet answered 28/7, 2019 at 12:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.