简体   繁体   中英

How to import external library in android studio?

I struggle to import library 'PageSlidingTapStrip'( https://github.com/astuetz/PagerSlidingTabStrip ).

I found this question( How to import eclipse library project from github to android studio project? ), and I follow this solution.

cf)I'm using win 8.1 , android studio version 0.3.6

First, build new project like this condition. 在此输入图像描述

Second, go to File -> New Module click, create new module as android library and make condition like this.( Unchecked create custom launcher icon, activity )

在此输入图像描述

And this part I got a first question. Which version should I choice version about 'Minimum required SDK' , 'Target SDK', 'Compile with'? Just Follow project version? (image show default value when I create this window first.)

Anyway, I progress under condition ' Minimum required SDK : API 9 / Target SDK : API 19 / Compile with : API 19 '

Third, delete files under 'Project/PageSlidingTabStrip/src/main/' and copy folder&file under external library 'res', 'src', 'AndroidManifest.xml' and move into 'Project/PageSlidingTabStrip/src/main/' then renamed src to java.

And then project & folder become like this. (what I followed question as , told me copy and move file 'ic_launcer-web.png' apart from 'res', 'src', 'manifest' , but I can't find that file)

在此输入图像描述

Fourth, go to 'File -> Project setting -> Module -> click project module -> '+' button -> select Module dependency' then apply. 在此输入图像描述

After that, I face this error and cannot resolve R. 在此输入图像描述 And I can't go next step, can't finish import library. What should I do?

Is there any other solution?

Thanks for seeing long question. I hope to get a solution!

I also use the PagerSlidingTabStrip Project in my app and everything works fine. I'm not sure if it's already possible to add a library project via the IDE (-> without any problems). Please try to add the library project by editing the gradle files like this:

  • first delete your module PagerSlidingTabStrip
  • then create a folder in your root project directory (-> NewOne ) named 'libs'
  • copy the complete folder 'library' of the PagerSlidingTabStrip project on git into 'libs'
  • rename the folder 'library' that you just copied to eg "PagerSlidingTabStripLibrary" (just to avoid confusion) -> after the renaming you should have the path: "NewOne/libs/PagerSlidingTabStripLibrary"
  • now add this library in your settings.gradle with the following command:

     include ':libs:PagerSlidingTabStripLibrary' 
  • go to your build.gradle file of your AppProject aps and add the following line to your 'dependencies':

     compile project(':libs:PagerSlidingTabStripLibrary') 
  • at least you have to sync your gradle files: Tools -> Android -> Sync Project with Gradle Files

Please try this. If you get errors please post the log file.

For update up to Android Studio 1.2.1.1

There are basically three types of dependencies which we have to add in project of android Studio

Add Normal Dependencies like Support files

  1. Right click on project->open module settings
  2. Select dependencies->Now press right "+" icon button ->Select library Dependencies
  3. Enter Name and Search
  4. Select file and press ok button.

Add Git Hub Dependencies

Find the dependencies of git repository for example compile 'com.jakewharton:butterknife:6.1.0' from https://github.com/JakeWharton/butterknife

A. open build.gradle(module:app) file
B. Add lines compile 'com.jakewharton:butterknife:6.1.0'

OR

Follow as describe above in Normal Dependencies Step by just enter dependencies in search bar

Add Jar files Dependencies

  1. Right click on project->open module settings
  2. press left "+" icon (insert new Module) button -> Select import Jar or .AAR package->browse Jar file and finish
  3. Now select dependencies-> press right "+" icon button ->Select module Dependencies->select jar files->press ok button.

对于它的价值,我遇到了这个问题并最终通过在项目中使用相同的sdk版本和构建工具来解决它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM