我一直在使用android.support.v7.widget
包 - 特別是RecyclerView
類(除其他外,但這是問題所在)。Gradle不使用最新版本的支持庫?
這是工作正常,直到今天早些時候它隨機似乎默認爲包的早期版本現在。我這樣說是因爲:
- 當我嘗試打電話
myRecyclerView.addOnScrollListener(myScrollListener)
,myRecyclerView.getChildAdapterPosition(myView)
等Android Studio中給出了編譯錯誤Cannot resolve method ...
。 - 如果我將其更改爲
myRecyclerView.setOnScrollListener(myScrollListener)
(即使用set
而不是add
),它工作正常,並且不顯示已棄用的錯誤,應該因爲該方法已被棄用。
我不知道爲什麼它的顯示現在,當我一直在使用,並已能夠與早期的這些方法來編譯錯誤 - 它看起來就像它的使用android.support.v7.widget
庫的早期版本,但我沒有知道爲什麼它會或如何解決它...
編輯:我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.myapp.app"
minSdkVersion 15
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.android.support:support-v4:21.0.3'
compile 'com.balysv:material-ripple:1.0.2'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.github.castorflex.smoothprogressbar:library-circular:1.0.1'
compile 'com.github.rey5137:material:1.1.1'
compile 'com.android.support:design:22.2.0'
compile 'com.joooonho:selectableroundedimageview:1.0.1'
compile 'com.rengwuxian.materialedittext:library:2.1.3'
}
確實不是Android Studio。這是您的gradle構建文件,可以確定您的庫版本。您在支持庫的Gradle文件中有什麼? – Knossos
新的Android V7支持'22.2.0',你可以將它從'dependencies' – YenMinh
我有一些自定義的依賴關係,在'V7改變:21.0.3'程序兼容性庫和'V4:21.0.3'支持庫。 (我可以添加一個屏幕截圖,如果你想) – ujvl