package android.support.v4.util does not exist

2019-02-02 22:19发布

问题:

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

回答1:

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.


回答2:

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.



回答3:

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 :)



回答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



回答5:

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



回答6:

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.



回答7:

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.



回答8:

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.



回答9:

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.