Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...