Some jar(v4 support, ActionBarSherlock and etc.) import error in Android Studio

来源:互联网 发布:网络推广需要多少钱 编辑:程序博客网 时间:2024/04/30 03:51

How to configure ActionBarSherlock with Intellij IDEA

[Original URL:http://android-wtf.com/2012/09/how-to-configure-actionbarsherlock-with-intellij-idea/]

Introduction

This tutorial will guide you through the steps to set up ActionBarSherlock (ABS from now on) with your Android project created using Intellij IDEA. Just for the record, I’m using ABS version 4.1.0 and IDEA version 11.1.3.

Requirements

  • You must target API level 14 (Android 4.0) or higher
  • You must install the Android Support Library using SDK Manager, since ABS depends on it

As a rule, you should always target the latest API version to avoid enabling unnecessary compatibility behaviors, to take advantage of the latest platform improvements and optimizations. ABS, in turn, will use the platform’s native ActionBar implementation instead of it’s own backport. As far as ABS is concerned, minimum SDK version can be as low as 7 (Android 2.1).

Step 1: Download ActionBarSherlock

Download and extract ActionBarSherlock, preferably to the same directory where your projects reside. By default, it is C:\Users\<Name>\IdeaProjects on Windows 7.

If you prefer Git, clone and checkout the latest stable version.

Step 2: Create a module with Intellij IDEA

  1. Switch to IDEA
  2. Open File > Project Structure
  3. Select Modules on the left pane
  4. Click on the plus sign above the second column, and choose Module
  5. Add Module window will appear. Select the Create module from existing sources option
  6. Click on the button right next to the textbox
  7. A tree-based directory chooser dialog will pop up. Within the dialog navigate to the ABS directory, and choose the library subdirectory
  8. Click OK to dismiss the dialog
  9. Back in the Add Module window, click Next as many times as needed
  10. Click Finish
  11. Select your application module in the Modules pane
  12. Activate the Dependencies tab, then click on the plus sign on the right, and select Module dependency...
  13. Select the ABS library and click OK
  14. Finally click OK to close the Project Structure window

Step 3: Add Android Support Library

  1. Copy the jar file <sdk>\extras\android\support\v4\android-support-v4.jar to your project’s libs directory (create one if it doesn’t exist)
  2. Switch to IDEA
  3. Open File > Project Structure if you have closed it
  4. Select Libraries from the left pane
  5. Click on the plus sign above the second column, and choose Java
  6. From the file-chooser popup, navigate to your project’s libs directory
  7. Choose the jar you copied earlier, and click OK
  8. A popup titled Choose Modules will appear
  9. Select both modules, and click OK
  10. Click OK to apply the changes in the Project Structure window

Conclusion

That’s it. You should now be able to use ActionBarSherlock in your project. Just don’t forget to extend the SherlockActivity class instead of the native Activity class. If anything goes wrong, let me know in the comments.

原创粉丝点击