Using android support package

package android.support.v4.app does not exist ; in Android studio 0.8

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

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

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

13 Answers 13

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

@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 (

/app/build.gradle ) and add/update the following dependency section:

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.

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

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

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

Источник

Add support library to Android Studio project

I just installed the new Android Studio and I’m looking for a way to import the support library for Android.

Where is the option for that? In Eclipse that are just two clicks. I googled for it but found nothing. Surely it is too new.

7 Answers 7

Since Android Studio introduce a new build system: Gradle. Android developers can now use a simple, declarative DSL to have access to a single, authoritative build that powers both the Android Studio IDE and builds from the command-line.

Edit your build.gradle like this:

NOTES: Use + in compile ‘com.android.support:support-v4:21.+’ so that gradle can always use the newest version.

Because Android Studio is based on IntelliJ IDEA, so the procedure is just same like on IntelliJ IDEA 12 CE

1.Open Project Structure (Press F4 on PC and Command + ; on MAC) on your project).

2.Select Modules on the left pane.

3.Choose your project and you will see Dependencies TAB above the third Column.

4.Click on the plus sign in the bottom. Then a tree-based directory chooser dialog will pop up, navigate to your folder containing android-support-v4.jar, press OK.

5.Press OK.

I no longer work on Android project for a while. Although the below provides some clue to how an android studio project can be configured, but I can’t guarantee it works flawlessly.

In principle, IntelliJ respects the build file and will try to use it to configure the IDE project. It’s not true in the other way round, IDE changes normally will not affect the build file.

Since most Android projects are built by Gradle, it’s always a good idea to understand this tool.

I’d suggest referring to @skyfishjy’s answer, as it seems to be more updated than this one.

The below is not updated

Although android studio is based on IntelliJ IDEA, at the same time it relies on gradle to build your apk. As of 0.2.3, these two doesn’t play nicely in term of configuring from GUI. As a result, in addition to use the GUI to setup dependencies, it will also require you to edit the build.gradle file manually.

Assuming you have a Test Project > Test structure. The build.gradle file you’re looking for is located at TestProject/Test/build.gradle

Look for the dependencies section, and make sure you have

Below is an example.

You can also add 3rd party libraries from the maven repository

compile group: ‘com.google.code.gson’, name: ‘gson’, version: ‘2.2.4’

The above snippet will add gson 2.2.4 for you.

In my experiment, it seems that adding the gradle will also setup correct IntelliJ dependencies for you.

Источник

Support Library

In this document

See also

Minimum API level supported: 4

The Support Package includes static «support libraries» that you can add to your Android application in order to use APIs that are either not available for older platform versions or that offer «utility» APIs that aren’t a part of the framework APIs. The goal is to simplify your development by offering more APIs that you can bundle with your application so you can worry less about platform versions.

Читайте также:  Тема лексус для андроид

Note: The Support Package includes more than one support library. Each one has a different minimum API level. For example, one library requires API level 4 or higher, while another requires API level 13 or higher (v13 is a superset of v4 and includes additional support classes to work with v13 APIs). The minimum version is indicated by the directory name, such as v4/ and v13/ .

Revisions

The sections below provide notes about successive releases of the Support Package, as denoted by revision number.

Support Package, revision 11 (November 2012)

Support Package, revision 10 (August 2012)

Support Package, revision 9 (June 2012)

Support Package, revision 8 (April 2012)

Support Package, revision 7 (March 2012)

/AppNavigation ).

  • Added NotificationCompat.Builder to provide a compatibility implementation of Android 3.0’s Notification.Builder helper class for creating standardized system notifications.
  • Support Package, revision 6 (December 2011)

    Note: Reference for support library APIs are now available with the framework references, for example: android.support.v4.app .

    Changes for v4 support library:

    • Changes to ViewPager:
      • Added extra decorative view support for ViewPager . Decorative views may be supplied as child views of a pager in XML layout.
      • Added PagerAdapter.getPageTitle() to supply title strings for pages, which defaults to no title for each page.
      • Added PagerTitleStrip , a non-interactive title strip, that can be added as a child of ViewPager. Developers can supply text appearance and color, as well as layout sizing and gravity information.
      • Updated PagerAdapter methods to take ViewGroup objects, rather than View to avoid class casting in adapter implementations.
      • Updated ViewPager to use Launcher-style fling behavior.
      • Bug fixes for user interface interaction and test automation.
    • Support for Fragments:
      • Changed setStartDeferred() method to setUserVisibleHint(boolean) .
      • Added deferred start for off-screen pages to improve performance.
    • Support for Accessiblity APIs:
      • Updated AccessibilityDelegateCompat methods to return empty lists instead of null.
      • Added new APIs needed by the v4 samples.

    Support Package, revision 5 (December 2011)

    Support Package, revision 4 (October 2011)

    Compatibility Package, revision 3 (July 2011)

    These are exactly the same as the APIs added to the v4 support library, but rely on other platform components in Android 3.2. Use this library instead of v4 if you’re developing for Android 3.2 and higher (all other APIs in the v4 library are already available with API level 13).

    Compatibility Package, revision 2 (May 2011)

    Compatibility Package, revision 1 (March 2011)

    Initial release with the v4 library.

    Downloading the Support Package

    The Support Package is provided as a downloadable package from the Android SDK Manager. To install:

      Launch the Android SDK Manager.

    From Eclipse, you can select Window > Android SDK Manager. Or, launch SDK Manager.exe from the / directory (on Windows only) or android from the /tools/ directory.

  • Expand the Android Repository, check Android Support package and click Install selected.
  • Proceed to install the package.
  • When done, all files (including source code, samples, and the .jar files) are saved into the /extras/android/support/ directory. This directory contains each of the different support libraries, such as the library for API level 4 and up and the library for API level 13 and up, each named with the respective version (such as v4/ ).

    Setting Up a Project to Use a Library

    To add one of the libraries to your Android project:

    1. In your Android project, create a directory named libs at the root of your project (next to src/ , res/ , etc.)
    2. Locate the JAR file for the library you want to use and copy it into the libs/ directory.

    For example, the library that supports API level 4 and up is located at /extras/android/support/v4/android-support-v4.jar .

    Add the JAR to your project build path.

    In Eclipse, right-click the JAR file in the Package Explorer, select Build Path > Add to Build Path.

    Your application is now ready to use the library APIs. All the provided APIs are available in the android.support package (for example, android.support.v4 ).

    Tip: To see the library APIs in action, take a look at the sample apps in /extras/android/support/ /samples/ .

    Warning: Be certain that you not confuse the standard android packages with those in android.support library. Some code completion tools might get this wrong, especially if you’re building against recent versions of the platform. To be safe, keep your build target set to the same version as you have defined for your android:minSdkVersion and double check the import statements for classes that also exist in the support library, such as SimpleCursorAdapter .

    Using the v4 Library APIs

    The support library for v4 provides access to several classes introduced with Android 3.0 and beyond, plus some updated version of existing classes, and even some APIs that currently don’t exist in the Android platform. Some of the most useful and notable classes that have counterparts in the v4 support library are:

    For each of the classes above (and others not listed), the APIs work almost exactly the same as the counterparts in the latest Android platform. Thus, you can usually refer to the online documentation for information about the supported APIs. There are some differences, however. Most notably:

    • When creating an activity to use fragments, you must declare your activity to extend the FragmentActivity class (instead of the traditional Activity class).
    • To manage your fragments and loaders, you must use the methods FragmentActivity.getSupportFragmentManager() and FragmentActivity.getSupportLoaderManager() (instead of the getFragmentManager() and getLoaderManager() methods).
    • The ActionBar is not supported by the library. However, when creating your Options Menu, you can declare which items should be added to the Action Bar when it’s available (on Android 3.0 or later). You can do so with the MenuCompat.setShowAsAction() method, for example:

    Also see the Action Bar Compatibility sample for a demonstration of how to use ActionBar on Android 3.0+ and also support action bar functionality on older versions.

    Tip: To enable the Holographic theme on devices running Android 3.0 or higher, declare in your manifest file that your application targets API level 11, for example:

    This way, your application automatically receives the Holographic theme and the Action Bar for each activity when running on Android 3.0 and higher.

    For more information about how you can optimize your application for the latest Android-powered devices, read Optimizing Apps for Android 3.0.

    Reference Docs

    The reference documentation for the Support Packages is included as part of the Android online developer documentation:

    Samples

    If you want to see some code that uses the support libraries, samples are included with the Support Package, inside each support library directory, for example; /extras/android/support/v4/samples/ . You can also view these samples as part of the Android online developer documentation:

    Additionally, the Google I/O App is a complete application that uses the v4 support library to provide a single APK for both handsets and tablets and also demonstrates some of Android’s best practices in Android UI design.

    Источник

    Читайте также:  Как поменять ттл без рут прав андроид
    Оцените статью