Pulltorefresh add to gradle - android-studio

can anyone help me add this library in build.gradle Android Studio.
https://github.com/chrisbanes/Android-PullToRefresh
I know it is deprecated but I want to use it, I would appreciate if someone could help me
what to write in
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:+'
compile '????'
}
as mentioned I want to use the deprecated library not new Actionbar-Pulltorefresh. tried to google it but couldn't find any help.

I suggest you to use ActionBarPullToRefresh (same author).
However, if you would like to use PullToRefresh, you have to clone the lib locally in a folder, and then add it as local dependency. This lib isn't on Central Maven as aar.
root
app
build.gradle
lib
pull
src
res
build.gradle
settings.gradle
In you app/build.gradle you have to add:
dependencies {
// Library
compile project(':lib:pull')
}
In lib/pull/build.gradle you have to define it as library and specify the right sourceset (it is a gist):
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['aidl']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
In settings.gradle:
include ':lib:pull' ,':app'

Easiest way to add ActionBar-PullToRefresh to your project is via Gradle, you just need to add the following dependency to your build.gradle
dependencies {
repositories {
mavenCentral()
}
compile 'com.github.chrisbanes.actionbarpulltorefresh:library:+'
}
Rest gradle will do all work for you.

I've succesfully imported the libproject in Android Studio 1.0. The steps are the following
1.- Download and install PullToRefresh from the official GitHub. Unzip it.
2.- Create an empty Android Studio project. Mine is named "PrjLibDeps"
3.- In project's root folder, create a folder named "libs". Inside libs/, copy a "pulltorefresh" folder containing the unzipped file. Structure remains as shown below:
PrjLibdeps
| settings.gradle
| build.gradle
| libs
| pulltorefresh
| src, res, LICENSE, pom.xml...
| app/
| build.gradle
| src
| ...
4.- Create a build.gradle file inside "pulltorefresh" folder. Copy-paste this sample code and set proper values to compileSdkVersion, buildToolsVersion, minSdkVersion, targetSdkVersion (just copy them from app/build.gradle)
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.- on app/build.gradle
dependencies {
compile project(":PullToRefresh")
}
6.- Now, on project_root/settings.gradle:
include ‘:app', ':PullToRefresh'
project (':PullToRefresh').projectDir = new File('libs/pulltorefresh')
7.- "Sync now"
8.- CMD+F9 (Make project)
Hope it helps!
more detailed info in my blog

Related

Cannot resolve symbol 'GoogleApiClient'

I am trying to upgrade my Google Play Services library so I can use the newest Android Gradle (3.2) and Android SDK version (28). The issue is all of my GMS imports cannot be resolved.
Examples:
import com.google.android.gms.common.api.GoogleApiClient;
and
import com.google.android.gms.games.Games;
I've already looked at various questions that have issues with importing these libraries but none are up-to-date or appear to fix my issue. I've tried invalidating cache/restart, clean/rebuild project. Currently I am importing a google-play-services_lib library, which has the bundled GMS as a dependency: com.google.android.gms:play-services:12.0.1
My project build.gradle:
buildscript {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
}
apply plugin: 'com.android.application'
android {
sourceSets {
main {
manifest.srcFile 'src/main/AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
compileSdkVersion 28
defaultConfig {
applicationId "com.example.exampleapp"
minSdkVersion 14
targetSdkVersion 28
versionCode 34 // increment with every release
versionName '3.0.5' // change with every release
setProperty("archivesBaseName", "example_$versionName")
}
signingConfigs {
release {
keyAlias = "example key alias"
}
}
buildTypes {
release {
minifyEnabled true
}
}
}
dependencies {
implementation project(':google-play-services_lib')
implementation project(':appcompat_v7')
}
repositories {
google()
jcenter()
maven { url 'https://maven.google.com' }
}
My module/app build.gradle:
buildscript {
repositories {
google()
jCenter()
mavenCentral()
maven {
url 'https://maven.google.com/'
name 'Google'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v4:22.0.0'
compile 'com.google.android.gms:play-services:12.0.1'
}
android {
compileSdkVersion 28
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
Hopefully there is a way to resolve these import errors, which seems to be a disconnect between the gradle building of support libraries and the actual project itself...
Found it. For a migration from way-way back (like target API <= 21), get rid of using the bundle/manual library and stick with a newer Gradle version:
Remove the meta tag from Android Manifest that specifies a Google Play Services version (the bundled version)
Remove your google-play-services_lib
Add the necessary GMS dependencies to the project-level build.gradle, whether manually or in File → Project Structure → MyApp Module → Dependencies tab and add library, even if it doesn't show in the new Android Studio's library search.
Example: implementation 'com.google.android.gms:play-services-base:16.0.1'
I know this was fairly obvious but this might be a good post for migrating somewhat-old Android apps that use GMS to newer versions. This at least lets you pick which GMS modules to use rather than the bulky bundle.

Compile two apps, but running only one module with Android Studio

I have two android projects 'East' & 'ChoosePDF' in Eclipse. 'East' is the main app, the other is a pdf library.
I try to export them from Eclipse to Android Studio.
When I try to run 'East' module, there are two apps installed in device. 'ChoosePDF' is also installed as an app, which should be only complied as a library.
In the 'app managerment' setting, it shows as one app. But in device's desktop, these are two same icons.
This is the project's build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
project's settings.gradle is:
include ':ChoosePDF'
include ':East'
Here is module 'East's build.gradle, which is the main project in Eclipse.
apply plugin: 'com.android.application'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':ChoosePDF')
}
android {
compileSdkVersion 21
buildToolsVersion "23.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
And this is the dependency library's build.gradle.
apply plugin: 'com.android.library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 19
buildToolsVersion "23.0.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
I really don't know how it happens. Try to comment out the 'ChoosePDF' in settings.gradle, doesn't work. Try to remove something in 'ChoosePDF's build.gradle, doesn't work.
Really need help to fix it, thanks.

The project is using an unsupported version of the Android Gradle plug-in (0.12.2). The recommended version is 1.3.0 in Android studio 1.4.1

The problem worry me few days, I download the newest Android studio, and import the source code of library project from my old eclipse project, I tried solve the problem by many post, but still bad luck, there is my build.gradle, the content of android block is generate by android studio.
apply plugin: 'android-library'
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0' }
}
android {
compileSdkVersion 20
buildToolsVersion "21.1.2"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
}
This is my gradle-wrapper.properties, the code is generate by Android studio.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
and my AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="es.disegnator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="23" />
It still show the message:
Gradle sync failed: The project is using an unsupported version of the Android Gradle plug-in (0.12.2). The recommended version is 1.3.0.
Please help me solve the problem.

Missing dependencies tab in android studio

Screenshot http://i.imgur.com/2i41Vih.png
My project is named Pudge. When I open Module settings, I select my project and all the tabs (dependencies, etc.) are missing.
This is probably something stupid, but I don't know what.
Edit: adding more info:
The project has a folder named libraries, and in it there is the folder of the library (facebook in my case)
build.gradle of the main project
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
sourceSets {
main {
manifest {
srcFile 'AndroidManifest.xml'
}
java {
srcDir 'src'
}
res {
srcDir 'res'
}
resources {
srcDir 'src'
}
}
test {
java {
srcDir 'tests/src'
}
}
}
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
}
}
dependencies {
compile project(':libraries:facebook')
compile 'com.android.support:appcompat-v7:18.0.0'
compile 'com.google.android.gms:play-services:3.2.25'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
build.gradle of the facebook library
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:13.0.+'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 17
targetSdkVersion 17
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java {
srcDir 'src'
}
res {
srcDir 'res'
}
}
}
}
settings.gradle
include ':Pudge'
include ':libraries:facebook'
As I said in the comments - after I added the library through the gradle files - its working. But the tabs are still missing.
Looking at your main build file, it has the comment in it about being the top-level build file, so it looks like your main module is located at the project root instead of inside a folder. This is probably what's confusing the Project Structure dialog, because when it examines settings.gradle, it expects to see modules in the Pudge and libraries/facebook directories.
If my assumption about your main module being at the project root is correct, if you change your settings.gradle file to this it should work:
include ':'
include ':libraries:facebook'

Android Studio removes modules falsely identified as not backed by Gradle

I have a problem with Android Studio 0.3.0 and my project folder containing a plain old java library project, two Android library projects, and three Android apps. It's all built with Gradle.
The problem is that the initial import into Android Studio works fine (using Android Studio's Import Project..., then choosing my settings.gradle file), but when I press the refresh button in the Gradle sidebar, I get the message "The modules below are not backed by Gradle anymore. Check those to be removed from the ide project too:", and then it lists ALL my modules for removal. Everything builds fine from the terminal.
Output of gradle projects is (with edited names):
------------------------------------------------------------
Root project
------------------------------------------------------------
Root project 'root'
+--- Project ':android-lib1'
+--- Project ':android-app1'
+--- Project ':android-app2'
+--- Project ':android-app3'
+--- Project ':android-lib2'
\--- Project ':java-lib'
In the root folder, I have settings.gradle:
include ':java-lib'
include ':android-lib1'
include ':android-lib2'
include ':android-app1'
include ':android-app2'
include ':android-app3'
My build.gradle in the root folder:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
allprojects {
repositories {
mavenCentral()
ivy {
name 'repo'
artifactPattern 'http://repo.example.com:8081/artifactory/libs-release-local/[organisation]/[module]/[revision]/[type]s/[artifact].[ext]'
credentials {
username 'example'
password 'example'
}
}
}
}
task wrapper(type: Wrapper) {
gradleVersion = '1.8'
}
build.gradle for java-lib:
apply plugin: 'java'
apply plugin: 'eclipse'
compileJava.options.encoding = 'UTF-8'
group 'example'
version '0.1.0'
status 'release'
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
dependencies {
compile 'com.google.protobuf:protobuf-java:2.5.0'
compile 'com.google.guava:guava:15.0'
compile 'org.slf4j:slf4j-api:1.7.5'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
uploadArchives {
repositories {
add project.repositories.repo
}
}
build.gradle for the two Android libs (they are the same apart from dependencies and version numbers:
apply plugin: 'android-library'
dependencies {
compile project(':java-lib')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
versionCode 1
versionName '0.1.0'
minSdkVersion 9
targetSdkVersion 18
}
}
And finally, build.gradle for the Android apps (again, almost identical):
apply plugin: 'android'
dependencies {
compile project(':android-lib1')
compile project(':android-lib2')
}
android {
compileSdkVersion 18
buildToolsVersion "18.1.1"
defaultConfig {
versionCode 1
versionName '0.1.0'
}
signingConfigs {
release
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
if (project.hasProperty('storeFile')) {
android.signingConfigs.release.storeFile = file(storeFile)
}
if (project.hasProperty('storePassword')) {
android.signingConfigs.release.storePassword = storePassword
}
if (project.hasProperty('keyAlias')) {
android.signingConfigs.release.keyAlias = keyAlias
}
if (project.hasProperty('keyPassword')) {
android.signingConfigs.release.keyPassword = keyPassword
}
Perhaps it's a bug in Android Studio 0.3.0? I didn't experience it in earlier versions, but I want to make sure it's not just something in my build files.
Thanks a bunch for reading!
This was a bug which has now been fixed (working for me since Android Studio 0.3.5): https://code.google.com/p/android/issues/detail?id=61453
Also got this or very similar error (don't know if I did refresh) I see you posted bug at code.google.com and agree it must be their bug. My work around fix was just to cancel out of "not backed by Gradle" message and then I ran gradle build from command line. Then everything worked.

Resources