Android Studio项目整合PullToRefresh的问题记录 – 秋楓

  PullToRefresh下拉刷新在App中应用非常频繁,然而PullToRefresh是在ADT下开发完成的。如果要将其整合到Android Studio目录下的话颇费周折。前面的文章“Android Studio项目引入外部库注意事项(PullToRefresh)”介绍了如何将PullToRefresh的library引入到项目中。如果想直接运用PullToRefresh的例子的话还需要引入extras下的PullToRefreshListFragment和PullToRefreshViewPager两个库。

  然而,PullToRefreshListFragment和PullToRefreshViewPager两个库的引入却大动干戈。其实问题不大,只是对Gradle不熟悉,折腾了好久才知道问题所在。记录如下:

  1、包重复引入

Error:Execution failed for task ‘:app:dexDebug’.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘D:Program FilesJavajdk1.8.0_60binjava.exe” finished with non-zero exit value 2

  将android-support-v4.jar包删除以后又报如下异常:

D:AndroidStudioProjectsAndoridNewsAppPullToRefreshExtrasPullToRefreshListFragmentsrccomhandmarkpulltorefreshextraslistfragmentPullToRefreshBaseListFragment.java
Error:(
19, 30) 错误: 程序包android.support.v4.app不存在
Error:(
28, 106) 错误: 找不到符号
符号: 类 ListFragment
Error:(
32, 2) 错误: 方法不会覆盖或实现超类型的方法
Error:(
34, 17) 错误: 找不到符号
符号: 变量
super
位置: 类 PullToRefreshBaseListFragment
<T>
其中, T是类型变量:
T扩展已在类 PullToRefreshBaseListFragment中声明的PullToRefreshBase
<? extends AbsListView>

  解决办法:

    a、将extrasPullToRefreshListFragmentlibs下的android-support-v4.jar删除

    b、添加包依赖( File –> project structure –> dependencies )

    也可以直接在extrasPullToRefreshListFragmentbuild.gradle中的dependencies下直接添加compile ‘com.android.support:support-v4:23.0.1’

dependencies {
compile fileTree(include: [
‘*.jar’], dir: ‘libs’)
compile project(
‘:PullToRefresh’)
compile
‘com.android.support:support-v4:23.0.1’
}

  2、最小sdk版本

Error:Execution failed for task ‘:PullToRefreshExtras:PullToRefreshListFragment:processDebugAndroidTestManifest’.
> java.lang.RuntimeException: Manifest merger failed : uses-sdk:minSdkVersion 1 cannot be smaller than version 4 declared in library [AndoridNewsApp:PullToRefresh:unspecified] D:AndroidStudioProjectsAndoridNewsAppPullToRefreshExtrasPullToRefreshListFragmentbuildintermediatesexploded-aarAndoridNewsAppPullToRefreshunspecifiedAndroidManifest.xml
Suggestion: use tools:overrideLibrary
=”com.handmark.pulltorefresh.library” to force usage

  在extrasPullToRefreshListFragmentbuild.gradle中最小sdk版本设置

android {
……
//其它配置

defaultConfig {
minSdkVersion
14
targetSdkVersion
23
}

……//其它配置
}

  最终extrasPullToRefreshListFragmentbuild.gradle如下:

apply plugin: ‘com.android.library’
android {
compileSdkVersion
23
buildToolsVersion
“23.0.0”

defaultConfig {
minSdkVersion 14
targetSdkVersion
23
}

sourceSets {
main {
manifest.srcFile ‘AndroidManifest.xml’
java.srcDirs
= [‘src’]
resources.srcDirs
= [‘src’]
aidl.srcDirs
= [‘aidl’]
renderscript.srcDirs
= [‘src’]
res.srcDirs
= [‘res’]
assets.srcDirs
= [‘assets’]
}
}
}

dependencies {
compile fileTree(include: [‘*.jar’], dir: ‘libs’)
compile project(
‘:PullToRefresh’)
compile
‘com.android.support:support-v4:23.0.1’
}

 

本文链接:Android Studio项目整合PullToRefresh的问题记录,转载请注明。



You must enable javascript to see captcha here!

Copyright © All Rights Reserved · Green Hope Theme by Sivan & schiy · Proudly powered by WordPress

无觅相关文章插件,快速提升流量