The import android.support.v7.app cannot be resolv

2019-01-06 19:25发布

问题:

after updating to Eclipse Kepler, I haven't been able to add the support library appcompat. I've followed this instructions and I still get the error The import android.support.v7.app cannot be resolved on the following lines:

import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;

I have added the appcompat project, added both jars to the Build Path, selected them on the Order and Export tab, and added the library project in the main project.

I copied the v4 library to the libs folder in the main project, but I don't know what else to do or check. Does anyone have any suggestions??

Thank you!

回答1:

After you add appcompat_v7 to your dependencies, be sure that the libs folder from your project are empty. By default, an android-support-v4.jar is created when you define your project, so this will cause conflict when you declare appcompat_v7 library as your dependency.

So, the first thing you need to do is check the folder .../My_Project/libs and fearlessly delete the file android-support-v4.jar.

Then, add the appcompat_v7 library as a dependency of your project: To do this, if you are using Eclipse:

  1. Right click in your project folder, located in the Navigator.
  2. Click in properties, in the final of the list.
  3. In the Properties window, select the Android option (left menu).
  4. In the box Library, add your new reference.

If you are using Android Studio, you can follow the steps mentioned in the @Joey Garcia's comment.

Support Library Setup - https://developer.android.com/tools/support-library/setup.html

Let me know if it helped you. Good Luck!



回答2:

Peter, I had the same problem and this is how I fixed it in Android Studio.

1) Right-Mouse click the Project from the Project Window Pane and select Open Module Settings

2) On the left side, select app, then select the Dependencies tab on the top right

3) Click the + button on the bottom left, select Library Dependency

4) Either type or select appcompat-v7 (com.android.support:appcompat-v7:20.0.0)

5) Click ok on the Choose Library Dependency window

6) Then Click ok, or apply on that Project Structure window.

Now, AS should be able to pull in the missing class.



回答3:

I'm new to Eclipse but I had the same error and somehow fixed it. I had 2 project, one of them fixed itself after restart or something, the first one i fixed by adding back the imports that somehow i or eclipse deleted. mine imports are:

import android.content.res.Resources;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

Are add any that you still need. Hope that helps



回答4:

Just delete android-support-v4.jar from libs folder of your project. Rest of the things/errors will be gone. Eclipse will handle rest of the things.



回答5:

Delete the android-support-v4.jar in lib folder.