The import android.support cannot be resolved
For me they were appearing when i transferred code manually to another laptop. Just do
File>Invalidate Cache/Restart
click on 'Invalidate Cache and Restart' and your are done.
Another way to solve the issue:
If you are using the support library, you need to add the appcompat
lib to the project. This link shows how to add the support lib to your project.
Assuming you have added the support lib earlier but you are getting the mentioned issue, you can follow the steps below to fix that.
Right click on the project and navigate to Build Path > Configure Build Path.
On the left side of the window, select Android. You will see something like this:
- You can notice that no library is referenced at the moment. Now click on the Add button shown at the bottom-right side. You will see a pop up window as shown below.
- Select the
appcompat
lib and press OK. (Note: The lib will be shown if you have added them as mentioned earlier). Now you will see the following window:
- Press OK. That's it. The lib is now added to your project (notice the red mark) and the errors relating inclusion of support lib must be gone.
andorid-support-v4.jar is an external jar file that you have to import into your project.
This is how you do it in Android Studio:
Go to File -> Project Structure
Go to "Dependencies" Tab -> Click on the Plus sign -> Go to "Library dependency"
Select the support library "support-v4 (com.android.support:support-v4:23.0.1)"
Now to go your "build.gradle" file in your app and make sure the android support library has been added to your dependencies. Alternatively, you could've also just typed compile 'com.android.support:support-v4:23.0.1'
directly into your dependencies{}
instead of doing it through the GUI.
Rebuild your project and now everything should work.
Please follow these Steps:
For Eclipse:
- Go to your Project's
Properties
- Navigate to the
Java Build Path
- Then go to the
Libraries
tab. There click theAdd External JARs
Button on the Right pane. - Select the
android-support-v4.jar
file, usually the path for the Jar file is :
YOUR_DRIVE\android-sdks\extras\android\support\v4\android-support-v4.jar - After adding
android-support-v4.jar
Library, navigate to theOrder and Export
tab and put check mark on theandroid-support-v4
Library file. - After doing the above, Clean the Project and Build it.
- Problem Solved.
For Android Studio:
Short Version:
- Add the following line to your
build.gradle
file:implementation 'com.android.support:support-v4:YOUR_TARGET_VERSION'
Long Version:
Go to File -> Project Structure
Go to "Dependencies" Tab -> Click on the Plus sign -> Go to "Library dependency"
Select the support library "support-v4 (com.android.support:support-v4:YOUR_TARGET_VERSION)"
Navigate to your "build.gradle" inside your App Directory and double check if your desired Android Support Library has been added to your dependencies.
Rebuild your project and now everything should work.
Further reading regarding this Question:
- Support Library - Android Dev
- Recent Support Library Revisions
- Support Library Packages
- What is an Android Support Library?
- How Android Support Library work?
I hope this helps.