33

Since the last update for android support libraries, I am having issues with importing LruCache. Eclipse, and now even android studio, keep saying that package android.support.v4.util does not exist.

I am using actionbarsherlock and it has included android support v4 and shows no errors. My application was working fine before this last SDK update. What has changed? How do I fix this?

Here is the error that shows:

java: /Users/amit/App/src/com/app/EMCache.java:5: package android.support.v4.util does not exist
java: /Users/amit/App/src/com/app/EMCache.java:9: cannot find symbol
symbol  : class LruCache
location: class com.app.EMCache
java: /Users/amit/App/src/com/app/EMCache.java:20: cannot find symbol
symbol  : class LruCache
location: class com.app.EMCache
Amit
  • 3,952
  • 7
  • 46
  • 80
  • This might be related to [ClassNotFoundException after ADT update](https://stackoverflow.com/questions/16610190/classnotfoundexception-after-adt-update/16610247#16610247) or [Eclipse giving error, missing R.java file after recent update](https://stackoverflow.com/questions/16608524/eclipse-giving-error-missing-r-java-file-after-recent-update/16608570#16608570), which were solutions to common problems in the rev. 22 update. – Krauxe May 18 '13 at 06:45

11 Answers11

30

In my case, the solution was eventually found as documented here:

  • Make sure you have downloaded the Android Support Library using the SDK Manager.
  • Create a libs/ directory in the root of your application project.
  • Copy the JAR file from your Android SDK installation directory (e.g., <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/ directory.
Danny Schoemann
  • 1,270
  • 26
  • 41
15

After trying tweaking build.gradle different ways, ended up with solution found here: https://github.com/kmagiera/react-native-gesture-handler/issues/394#issuecomment-508358572

in short - you can solve it with jetifier:

npm install --save-dev jetifier npx jetify

From the package docs:

If you use React Native modules with native Java code that isn't converted to AndroidX, and your app is AndroidX, you probably need this.

Valentin Kantor
  • 1,799
  • 1
  • 23
  • 27
14

If you're using Gradle, I had to also add this line to the dependencies section of my inner build.gradle, the file where you specify your minSdkVersion and targetSdkVersion:

dependencies {
  compile "com.android.support:support-v4:19.0.+"
}

I believe the '19' is supposed to be whatever your compileSdkVersion. If I'm wrong, it will tell you what it's supposed to be.

craned
  • 2,991
  • 2
  • 34
  • 38
  • You will probably have to update the version to the version in your environment. eg, for me the version was: "com.android.support:support-v4:23.0.+" – steven smith Feb 19 '17 at 22:10
12

For those importing the support libraries using gradle like this:

// compat libraries
compile 'com.android.support:support-v4:23.2.0' // v4
compile 'com.android.support:appcompat-v7:23.2.0' // v7
compile 'com.android.support:support-v13:23.2.0' //v13

Remember to remove this all*.exclude module: 'support-v4' from configurations

configurations {
    //all*.exclude module: 'support-v4'
}

...might have been a dummy mistake from my part though :)

mogile_oli
  • 2,148
  • 2
  • 21
  • 21
  • 1
    Thank you. Updating the gradle file to use the latest support library ( 23.3.0 as of 2016-04-14) has solved my problem. It was using 23.2.1, and had this problem after an SDK update. – Hong Apr 14 '16 at 21:08
4

In my case I was porting an Android Googlemaps app API1 to API2, and after many hours I realized I was not adding

C:\Program Files\..(your_path_)..
  ..\adt-bundle-windows-x86_64\sdk\extras\android\support\v4

to External Libraries..

Hope this helps

user9869932
  • 6,571
  • 3
  • 55
  • 49
3

Step-1: Open Project in AndroidStudio3.3 or above, wait until loading of the project completes.

Step-2: Right click 'app' -> Refactor -> Migrate to AnroidX

Step-3: Review the changes in AndroidStudio console below and click 'Do Refactor'

The issue will be fixed.

sent.ror
  • 187
  • 1
  • 5
  • I replace 'import androidx.core.util.LruCache;' with 'import android.util.LruCache;', and then no error – Venus May 25 '21 at 09:12
2

craned's answer:

dependencies {
    compile "com.android.support:support-v4:19.0.+"
}

worked for me. But (in my case at least) the '19' should match the compileSdkVersion

Undo
  • 25,519
  • 37
  • 106
  • 129
ttguy
  • 23
  • 5
1

Go to your Android SDK's directory and:

jar tvf ./extras/android/support/v13/android-support-v13.jar |grep v4.*util

And within this jar file you can see one of the classes (under v4/util) you have used in your applications.

     0 Wed Mar 26 20:29:48 SGT 2014 android/support/v4/util/
  3373 Wed Mar 26 20:29:48 SGT 2014 android/support/v4/util/ArrayMap.class
  5329 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/MapCollections.class
  1625 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/ContainerHelpers.class
  3677 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/MapCollections$KeySet.class
  1220 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/DebugUtils.class
  3435 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/AtomicFile.class
  1287 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/LogWriter.class
  3701 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/MapCollections$ValuesCollection.class
  4446 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/MapCollections$EntrySet.class
  5910 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/SparseArrayCompat.class
  3273 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/TimeUtils.class
  5776 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/LongSparseArray.class
  5680 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/LruCache.class
  3341 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/MapCollections$MapIterator.class
  1575 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/MapCollections$ArrayIterator.class
  2439 Wed Mar 26 20:29:48 SGT 2014 android/support/v4/util/ArrayMap$1.class
  8611 Wed Mar 26 20:29:46 SGT 2014 android/support/v4/util/SimpleArrayMap.class

So the error "package android.support.v4.util does not exist" simply means you have to copy the above jar file to your libs subdirectory and recompile.

Peter Teoh
  • 6,337
  • 4
  • 42
  • 58
1

In my case the problem was referencing the jar from sdk installation folder, copying the jar to project's libs folder adding to build path actually resolved the issue.

Khurram Shehzad
  • 1,010
  • 12
  • 16
1

In my case with Android Studio, this error appeared in the middle of a working project and refused to disappear despite much fooling around. I finally forced a Gradle Sync operation by adding a single space character to a Gradle file. The Gradle Sync fixed it instantly.

emrys57
  • 6,679
  • 3
  • 39
  • 49
1

add dependency

dependencies { compile 'com.android.support:support-v4:+'}

Change Build Tool

 dependencies {  classpath 'com.android.tools.build:gradle:2.3.0'}

Worked for me.

Vipin Yadav
  • 707
  • 5
  • 6