60

I've recently updated the android studio IDE to 0.8 to work with the new android L SDK. To start I imported a finished android project that receives no errors in the older version of android studio. In version 0.8 i lines such as

import android.support.v4.app.Fragment;
get: Support cannot be resolved causing the rest of the code to have errors. The logcat returns 101 instances of

Error:(8, 30) error: package android.support.v4.app does not exist

1 for each time I call the support library in an import statement.

I've tried

  • reinstalling the IDE
  • deleting contents of idea folder
  • re installing all the SDK's - including the support libraries
  • syncing the gradle
  • copying the support library into the libs folder manually
  • rebuilding the project
  • as well as creating a new project to test the library

not entirely sure what's left to do.

CRABOLO
  • 8,322
  • 38
  • 38
  • 66
user3381665
  • 1,051
  • 3
  • 11
  • 16

12 Answers12

111

Ok, so I had the same problem and found a solution in a udacity forum:

In Android Studio:

  1. Right click on your projects "app" folder and click on -> module settings
  2. Click on the "dependencies" tab
  3. Click on the + sign to add a new dependency and select "Library Dependency"
  4. Look for the library you need and add it
Bernhardt Scherer
  • 1,768
  • 3
  • 12
  • 20
  • 1
    Perhaps, didn't work for me, who didn't have an `app` folder after importing from Eclipse. I saw some message about conflicting versions of the support package. Was just copying the newer one over the older one before but I think something got updated. – John Jan 15 '15 at 22:15
  • it works for me..simple but makes us frustrated if we find the issues – muhnizar Feb 03 '15 at 14:49
  • Worked for me as well. Had to include android.support dependency and now all build errors related to android.support.v4.app package not found have vanished. – shivisuper Oct 13 '16 at 22:38
  • In Android Studio 3.6, there was no "Module Settings" option when right-clicking on the "app" folder, but there was an "Open Module Settings" when right-clicking on the top-level project. The shortcut key is F4. However its "Dependencies" tab lists nothing referencing a `support-v4` library. – Silas S. Brown Feb 26 '20 at 17:43
38

@boernard 's answer solves this from the Android Studio IDE, but if you want to understand what's happening under the covers, it's a simple gradle build file update:

You can edit the build.gradle file from within the IDE (left pane: Gradle Scripts -> build.gradle (Module: app)) or use the raw path (<proj_dir>/app/build.gradle) and add/update the following dependency section:

dependencies {
    //
    // IDE setting pulls in the specific version of v4 support you have installed:
    //
    //compile 'com.android.support:support-v4:21.0.3'

    //
    // generic directive pulls in any available version of v4 support:
    //
    compile 'com.android.support:support-v4:+'
}

Using the above generic compile directive, allows you to ship your code to anyone, provided they have some level of the Android Support Libraries v4 installed.

colm.anseo
  • 8,213
  • 1
  • 22
  • 31
17

None of the above solutions worked for me. What finally worked was:

Instead of

import android.support.v4.content.FileProvider;

Use this

import androidx.core.content.FileProvider;

This path is updated as of AndroidX (the repackaged Android Support Library).

Niklesh Lalwani
  • 181
  • 1
  • 4
11

[for some reasons this answer is related to Eclipse, NOT Android Studio!]

Have you tried setting the support libraries to your class path? This link from the Android Developer's website has some info on how to do that.

Try following these steps from the website:

Create a library project based on the support library code:

  • Make sure you have downloaded the Android Support Library using the SDK Manager.
  • Create a library project and ensure the required JAR files are included in the project's build path:

    • Select File > Import.
    • Select Existing Android Code Into Workspace and click Next.
    • Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompat project, browse to /extras/android/support/v7/appcompat/.
    • Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat.
    • In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path.
    • Right-click the library project folder and select Build Path > Configure Build Path.
    • In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files.
    • Uncheck Android Dependencies.
    • Click OK to complete the changes.
  • You now have a library project for your selected Support Library that you can use with one or more application projects.

    • Add the library to your application project:
    • In the Project Explorer, right-click your project and select Properties.
    • In the category panel on the left side of the dialog, select Android.
    • In the Library pane, click the Add button.
    • Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat.
    • In the properties window, click OK.
Draken
  • 3,049
  • 13
  • 32
  • 49
user3799575
  • 219
  • 2
  • 7
  • when i try that i know get Error:Could not find method complie() for arguments [com.android.support:support-v4:18.0.+] on org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler_Decorated@ad93a93. Please install the Android Support Repository from the Android SDK Manager. Open Android SDK Manager – user3381665 Jul 03 '14 at 06:33
9

Delete

/.idea/libraries

Then sync gradle to build project.

Praveen
  • 340
  • 3
  • 6
  • This was the fix for me. The dependency had previously been correctly set up in gradle, but a Kotlin plugin version update *broke everything*, and the fix was to remove `.idea/libraries`, then `Invalidate Caches/Restart` in Android Studio. – x1a4 Sep 17 '18 at 05:18
  • This did not work for me but helped me towards a solution because all the files I was expecting to be the folder did not get re-created. – Paul McCarthy Oct 09 '19 at 23:48
2

tl;dr Remove all unused modules which have a dependency on the support library from your settings.gradle.

Long version:

In our case we had declared the support library as a dependency for all of our modules (one app module and multiple library modules) in a common.gradle file which is imported by every module. However there was one library module which wasn't declared as a dependency for any other module and therefore wasn't build. In every few syncs Android Studio would pick that exact module as the one where to look for the support library (that's why it appeared to happen randomly for us). As this module was never used it never got build which in turn caused the jar file not being in the intermediates folder of the module.

Removing this library module from settings.gradle and syncing again fixed the problem for us.

ubuntudroid
  • 3,068
  • 5
  • 32
  • 54
2

In my case the error was on a module of my project.I have resolved this with adding

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

this dependency in gradle of corresponding module

Jack
  • 1,397
  • 2
  • 14
  • 39
1

IN ECLIPSE LUNA I ve resolved this issue by using contet menu on my Project : ANdroid Tools > Add support Library ...

abn_java
  • 557
  • 2
  • 7
  • 17
0

In my case the problem was solved by appending the string cordova.system.library.2=com.android.support:support-v4:+ to platforms/android/project.properties file

dolcom
  • 1
0

For me the problem was caused by a gradle.properties file in the list of Gradle scripts. It showed as gradle.properties (global) and refered to a file in C:\users\.gradle\gradle.properties. I right-clicked on it and selected delete from the menu to delete it. It deleted the file from the hard disk and my project now builds and runs. I guess that the global file was overwriting something that was used to locate the package android.support

Paul McCarthy
  • 621
  • 8
  • 18
0

My solution was creating a project with Use legacy support library option checked. after the project creation is successfully completed, just delete the src folder in the app directory and copy the src folder from your main project. Finally, Sync project with Gradle files.

Ali Kleit
  • 1,677
  • 2
  • 15
  • 26
0

Add this to build.gradle:

allprojects {
    repositories {
        google()
    }
}
dependencies {
    implementation "com.android.support:support-core-utils:28.0.0"
}

*Must have minSdkVersion 14 (or higher)

Kevin
  • 1,972
  • 15
  • 18