Why can't I import LinearLayoutManager and RecyclerView? - android

I can import everything else from the Android library except for those two. I'm trying to import them from android.support.v7.widget which doesn't work, but importing fragment and activity classes from android.support.v4.widget does work.
My Gradle Build looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.frisosapps.planner"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
}
Should I add something to this or should I look for the cause elsewhere?

To use RecyclerView, use
compile 'com.android.support:recyclerview-v7:23.1.1'

you'll need to include the RecyclerView dependency as its standalone library
compile "com.android.support:recyclerview-v7:23.1.1"

Related

Android RatingBar Style Small showing error in Android studio

I am using RatingBar in android and want to reduce the size of it , so I added
style="?android:attr/ratingBarStyleSmall"
as Ratting Bar Style attribute. It is working fine but it is showing error in code
below is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion " 22.0.1"
defaultConfig {
applicationId "com.app.xxxx"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
} }
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':vitamio')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:design:22.2.1'
compile 'com.android.support:support-v4:22.2.1'
}
Please help what I am doing wrong..
Thanks In Advance..
Use this instead style="?attr/ratingBarStyleSmall"

Android cannot import RecyclerView & CardView

I'm not able to import RecyclerView & CardView although it seems very trivial. This is the relevant part from gradle.build script:
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "23.0.0"
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java {
srcDir 'src/main/java'
}
resources {
srcDir 'src/../lib'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.1'
compile 'com.android.support:cardview-v7:21.0.+'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.google.android.gms:play-services:7.8.+'
}
The sync & build tasks executes normally so it seems that the dependencies actually downloaded. And when in some activity I try to import android.support.v7.widget.RecyclerView; it's not recognising the package.
Maybe it's SDK API versions issues? Note I need min 11 and target max 22.
Add recent recyclerview which is in your sdk.
right click on app --> Open Module Settings --> Dependencies
then on right side click on plus button. Add library dependency and search recyclerview and then add it.
Hope it will work.
You need to change the buildToolsVersion. See the below code.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
defaultConfig {
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:cardview-v7:22.2.0'
compile 'com.android.support:palette-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:support-v4:21.0.3'
compile files('libs/picasso-2.2.2.jar')
compile project(':Cropper')
compile project(':library')
compile project(':quickScroll')
}

Android studio not recognizing a method?

I'm trying to use the method findFirstVisibleItemPosition() from a LinearLayoutManager. The apis show that this method exists, but it is not recognized nor shown in autocompletion.
Other methods from this layout work (some at least), and android.support.v7.widget.LinearLayoutManager is imported.
What could be wrong?
edit: hereĀ“s my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.skate.socialskate"
minSdkVersion 21
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:cardview-v7:22.1.0'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.android.support:support-v13:22.1.0'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
compile 'org.jsoup:jsoup:1.8.2'
}
You need to add an appcompat to your build.gradle:
compile 'com.android.support:appcompat-v7:22.1.1'

AsyncTask not available in Android Studio

I am using Android Studio 1.2. Every SDK must have AsyncTask , but my Android Studio is not able to recognize the class.Even not showing in import and autoassist.
Similarly if I write no suggestion in Autosuggest
Gradle Script:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.0"
defaultConfig {
applicationId "com.appxperts.printknot2"
minSdkVersion 11
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(':libraries:floatingedittextlibrary')
compile files('libs/gson-2.2.4.jar')
compile 'com.larswerkman:HoloColorPicker:1.5'
compile 'com.doomonafireball.betterpickers:library:1.5.5'
compile 'com.google.android.gms:play-services:3.1.+'
}
I solved it myself.The problem was with Android Studio on Ubuntu.It is not able to automatically import AsycTask.Not even in auto-suggestions.Simply added
import android.os.AsyncTask

Android Studio support v4

I know this question was asked several times, but none of the answers helped me so far...
All I did was generating a preferences screen with Android Studio and now it tells me that NavUtils cannot be found. Even though my build.gradle looks right (I guess):
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.brobox.getyourshitdone"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:palette-v7:+'
compile 'com.android.support:support-v4:20.0.+'
compile files('libs/android-support-v4.jar')
}
I hope someone can help :/
Edit:
Just created a new project on my laptop and generated the SettingsActivity again. This is my gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.brobox.getyourshitdone"
minSdkVersion 14
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v13:20.0.0'
compile 'com.android.support:support-v4:20.0.0'
}
Still got the same error <.<
You have to remove this line implementation files('libs/android-support-v4.jar') and you have to remove this file.
The support library should only be added by gradle. And you have done that in this line implementation 'com.android.support:support-v4:20.0.+'.
YourtargetSdkVersion and your compileSdkVersion are also weird. Those values are not supported with the L developer preview.
compileSdkversionshould be 'android-L', targetSdkVersion should be 'L'.
Press this button, and clean rebuild project.
And add to dependencies :
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:cardview-v7:+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:palette-v7:+'
}
Well some time passed and now it works! I don't know what solved it exactly but I did the following:
I updated to Android Studio 0.8.12 manually, because that was the only way to update it
In a new project I tried to manually add a SettingsActivity and therefore added support-v4 to my repositories
Thanks for all your help on this silly question...

Categories

Resources