Fork me on GitHub

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 Files\Java\jdk1.8.0_60\bin\java.exe'' finished with non-zero exit value 2

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

D:\AndroidStudioProjects\AndoridNewsApp\PullToRefreshExtras\PullToRefreshListFragment\src\com\handmark\pulltorefresh\extras\listfragment\PullToRefreshBaseListFragment.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、将extras\PullToRefreshListFragment\libs下的android-support-v4.jar删除

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

    也可以直接在extras\PullToRefreshListFragment\build.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:\AndroidStudioProjects\AndoridNewsApp\PullToRefreshExtras\PullToRefreshListFragment\build\intermediates\exploded-aar\AndoridNewsApp\PullToRefresh\unspecified\AndroidManifest.xml
    Suggestion: use tools:overrideLibrary="com.handmark.pulltorefresh.library" to force usage

  在extras\PullToRefreshListFragment\build.gradle中最小sdk版本设置

android {
    ......//其它配置

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
    }

    ......//其它配置
}

  最终extras\PullToRefreshListFragment\build.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'
}

 

扫描公众号,关注更多信息

---------------------------------------------------------------------------------我是分割线--------------------------------------------------------------------------

to be a better me, talk is cheap show me the code

版权所有,转载请注明原文链接。

文中有不妥或者错误的地方还望指出,以免误人子弟。如果觉得本文对你有所帮助不妨【推荐】一下!如果你有更好的建议,可以给我留言讨论,共同进步!

再次感谢您耐心的读完本篇文章。

----------------------------------------------------------------------------------------------------------------------------------------------------------------------
posted @ 2015-10-22 22:30  秋楓  阅读(9852)  评论(0编辑  收藏  举报