The import android.support cannot be resolved
Asked Answered
P

9

128

I am trying to run the code provided HERE
I downloaded the code from their Github and imported into Android SDK, but it shows error at the lines

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;  

in multiple files. However if I check the Android SDK Manager, the Android Support Library as well as the Android Support Repository in the Extras folder are both installed. I can also see the support folder and it's contents in the SDK_INSTALL\sdk\extras\android\support directory. It also has the v4 folder which also contains the android-support-v4.jar and the src folder. THen why is it still showing the error, how do I resolve it and how do I get that sample code running? THe sample code is for an RSS reader app, if that's relevant.

Pattypatulous answered 18/8, 2013 at 14:4 Comment(6)
If you are using ADT 22, then "external library" might not be checked, go to project properties and check this option in build path.Stung
I can't find this option. Is it in Builders or java Build path?Pattypatulous
project > properties > java build path > order and export > check "Android Private Libraries"Stung
The name of the IDE would have been a useful addition to this question.Jailbird
The IDE was Android SDK downloaded from the Android Developers website. I am not sure which version it was though; it was probably the latest version at the time of posting this questionPattypatulous
#26978108Mayhap
W
286

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 the Add 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 the Order and Export tab and put check mark on the android-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:

  1. Support Library - Android Dev
  2. Recent Support Library Revisions
  3. Support Library Packages
  4. What is an Android Support Library?
  5. How do the Android Support Libraries work?
Winograd answered 18/8, 2013 at 14:22 Comment(11)
Thanks :) Got this error after copying all my stuff to a new laptop, but installing Android on a different pathQuicklime
Thank you! You indeed solved my problem but, it is still wierd to me - My project used the v4 support lib just fine, and only after adding an external project which also uses the support lib it started happening. Why is that? Why didn't I have to add the v4 support lib before I added an external project?Selfaddressed
Here is a link, that clearly answers your question :) #12927048Winograd
@nylon100 That External Library may be using the features that are introduced in later version of Android SDKs and inorder to avail those features in your Project Support library is a must to add.Winograd
Thanks, that was it!! Why is it that the android system can't include this file when we ask for the import? I wasted an hour on this bug.Cambist
In the current version of IntelliJ it is hard to follow your instructions, because there are certain options named differently. But at the end it was a great help!Footcandle
I see there's a new option if you right click on the project, android tools, "install support library". Does the configuration automagically :)Aleshia
In Android Studio go to: File -> Project Structure -> Dependencies Tab -> Click + to add Library dependency -> Choose support-v4 from the list -> Click OK.Presidio
@Presidio Thanks for your response, i will update my Answer.Winograd
compile is obsolete and has been replaced with implementation nowBroadloom
I had the problem and followed the instructions. However, I could not resolve the problem until I realized that the android.useAndroidX and android.enableJetifier are set to true at gradle.properties. By making them false, my problem was solved.Matsuyama
D
15

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 enter image description here

Go to "Dependencies" Tab -> Click on the Plus sign -> Go to "Library dependency" enter image description here

Select the support library "support-v4 (com.android.support:support-v4:23.0.1)" enter image description here

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.

enter image description here

Rebuild your project and now everything should work. enter image description here

Daiquiri answered 13/10, 2015 at 0:39 Comment(0)
T
8

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.

  1. Right click on the project and navigate to Build Path > Configure Build Path.

  2. On the left side of the window, select Android. You will see something like this:

enter image description here

  1. 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.

enter image description here

  1. 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:

enter image description here

  1. 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.
Tridactyl answered 17/12, 2014 at 7:35 Comment(1)
@downvoter.. a brief kind information abt the reason for downvote will be highly appreciated. This'll help me in future to make my ans better in helping others. I've shared what I'd experienced to help future readers and the ans pretty much related to the question.Tridactyl
P
4

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.

Puny answered 29/5, 2018 at 6:7 Comment(0)
P
3

I followed the instructions above by Gene in Android Studio 1.5.1 but it added this to my build.gradle file:

compile 'platforms:android:android-support-v4:23.1.1'

so I changed it to:

compile 'com.android.support:support-v4:23.1.1'

And it started working.

Philbrick answered 29/1, 2016 at 22:45 Comment(0)
A
2

This issue may also occur if you have multiple versions of the same support library android-support-v4.jar. If your project is using other library projects that contain different-2 versions of the support library. To resolve the issue keep the same version of support library at each place.

Alack answered 17/6, 2015 at 6:45 Comment(0)
P
1

This is very easy step to import any 3rd party lib or jar file into your project

  1. Copy android-support-v4.jar file from your_drive\android-sdks\extras\android\support\v4\android-support-v4.jar
    or copy from your existing project's bin folder.
    or any third party .jar file
  2. paste copied jar file into lib folder

  3. right click on this jar file and then click on build Path->Add to Build Path enter image description here

  4. even still you are getting error in your project then Clean the Project and Build it.

Politi answered 31/5, 2015 at 11:21 Comment(0)
M
1

I have resolved it by deleting android-support-v4.jar from my Project. Because appcompat_v7 already have a copy of it.

If you have already import appcompat_v7 but still the problem doesn't solve. then try it.

Merylmes answered 18/9, 2015 at 11:3 Comment(0)
C
0

Android Studio 2.2.3 Linux Mint 18.1

Inside your 'project view' open Gradle Scripts -> build.gradle(Module:app) and put your mouse pointer inside the word dependencies.

Click on the light bulb and click "add library dependency" and for me all the libraries I wanted were listed there.

example libraries that came up for me: compile 'com.android.support:gridlayout-v7:25.1.0' compile 'com.android.support:support-v13:25.1.0'

I am now looking to add android support by default in Gradles default configuration.

Concerned answered 28/12, 2016 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.