com.handmark.PullToRefresh is an excellent library. A pity it’s no longer being maintained, and has no gradle dependency.
Luckily, we can import the libproject “as it is” and compile it using Gradle. These are the steps.
1.- First of all, you need to download the libproject clicking on the “download ZIP” button found in the project’s GitHub site.
2.- Create an empty Android Studio project, let’s name it “PrjLibDeps”. Make sure it compiles succesfully and shows the “Hello World, PrjLibDeps” text before going to next step.
3.- In the project’s root folder, create a folder called “libs”, and place the “pulltorefresh” folder inside. The structure must remain as follows:
PrjLibdeps | settings.gradle | build.gradle | libs | pulltorefresh | src, res, LICENSE, pom.xml... | app/ | build.gradle | src | ...
4.- Now, inside “pulltorefresh” folder, create a file named “build.gradle”. If there is one, replace it. Copy and paste this dummy content we’re going to change later:
apply plugin: 'com.android.library' dependencies { compile 'com.android.support:support-v4:21.0.3' } android { compileSdkVersion 20 buildToolsVersion "20.0.0" defaultConfig { minSdkVersion 9 targetSdkVersion 20 } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] res.srcDirs = ['res'] } } }
5.- Now replace compileSdkVersion, buildToolsVersion, minSdkVersion, and targetSdkVersion with values that are valid in your Android SDK installation. The easiest way is to set the same values found in app/build.gradle file.
6.- Now edit app/build.gradle, and add these dependencies.
dependencies { compile project(":PullToRefresh") // Leave the previous dependencies (if any) unmodified }
7.- Edit settings.gradle, located in the project’s root directory. Add these lines
include ‘:app', ':PullToRefresh' project (':PullToRefresh').projectDir = new File('libs/pulltorefresh')
8.- A yellow message saying “Gradle files have changed since las project sync …” might appear on the upper right. Click on “Sync now” to make gradle synchronize all resources.
9.- After gradle sync has finished, press CMD+F9 to Make the whole project. If you’ve done all steps correctly, you might get success 🙂 At least I could make it work with these exact steps. More import examples can be found at: SO question 1, SO question 2.
Let me know any issues.
Have a nice coding day!!