Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "package android.support.v7.app does not exist"

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

like image 752
Alexander Otavka Avatar asked Apr 28 '14 00:04

Alexander Otavka


People also ask

How do I install support library?

Downloading the Support LibrariesStart the android SDK Manager. In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder. Select the Android Support Library item. Click the Install packages button.

What is Androidx Appcompat app AppCompatActivity?

androidx.appcompat.app.AppCompatActivity. Base class for activities that wish to use some of the newer platform features on older Android devices. Some of these backported features include: Using the action bar, including action items, navigation modes and more with the setSupportActionBar(Toolbar) API.


2 Answers

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; 
like image 159
Sunil Kumar Avatar answered Sep 22 '22 04:09

Sunil Kumar


If the issue reported from MainActivity.java then replace

import android.support.v7.app.AppCompatActivity; 

with

import androidx.appcompat.app.AppCompatActivity; 
like image 41
siva balan Avatar answered Sep 19 '22 04:09

siva balan