转载

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 Studio项目整合PullToRefresh的问题记录

解决办法:

a、将extras/PullToRefreshListFragment/libs下的android-support-v4.jar删除

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

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

也可以直接在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

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

在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' } 
正文到此结束
Loading...