android - 无法将 RecyclerView 添加到 API 级别 19

标签 android android-recyclerview android-gradle-plugin android-support-library

我正在尝试将 RecyclerView 添加到我继承的项目中,该项目是针对 API 19 编译的,无法更高。

在我从支持库添加 RecylerView 后,如下所示:

compile 'com.android.support:recyclerview-v7:+'

该项目不再构建,它开始给出如下所示的 multidex 异常错误:

Error:Execution failed for task ':app:transformClassesWithDexForDevDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' finished with non-zero exit value 3

为了解决这个问题,我做了以下操作

  1. 启用了 multidex 支持,如下所示 multiDexEnabled true
  2. 添加 编译'com.android.support:multidex:1.0.1'
  3. 在 Applciation 类中安装 multidex,如下所示:MultiDex.install(this);

所有这些都没有帮助。这是运行 ./gradlew app:dependencies 的依赖关系图

根据下图,我需要进行哪些更改才能再次构建项目?

compile - Classpath for compiling the main sources.
+--- com.android.support:multidex:1.0.1
+--- org.simpleframework:simple-xml:2.7.1
|    \--- stax:stax:1.2.0
+--- com.squareup.retrofit2:converter-simplexml:2.0.0-beta3
|    +--- com.squareup.retrofit2:retrofit:2.0.0-beta3
|    |    \--- com.squareup.okhttp3:okhttp:3.0.0-RC1
|    |         \--- com.squareup.okio:okio:1.6.0
|    \--- org.simpleframework:simple-xml:2.7.1 (*)
+--- com.crashlytics.sdk.android:crashlytics:2.5.5
|    +--- com.crashlytics.sdk.android:answers:1.3.6
|    |    \--- io.fabric.sdk.android:fabric:1.3.10
|    +--- com.crashlytics.sdk.android:crashlytics-core:2.3.8
|    |    +--- com.crashlytics.sdk.android:answers:1.3.6 (*)
|    |    \--- io.fabric.sdk.android:fabric:1.3.10
|    +--- io.fabric.sdk.android:fabric:1.3.10
|    \--- com.crashlytics.sdk.android:beta:1.1.4
+--- com.crashlytics.sdk.android:crashlytics-ndk:1.1.2
|    +--- io.fabric.sdk.android:fabric:1.3.7 -> 1.3.10
|    \--- com.crashlytics.sdk.android:crashlytics-core:2.3.5 -> 2.3.8 (*)
+--- commons-net:commons-net:3.3
+--- com.github.danysantiago:sendgrid-android:1
|    +--- org.apache.httpcomponents:httpmime:4.3.5
|    |    \--- org.apache.httpcomponents:httpclient:4.3.5
|    |         +--- org.apache.httpcomponents:httpcore:4.3.2
|    |         +--- commons-logging:commons-logging:1.1.3
|    |         \--- commons-codec:commons-codec:1.6
|    \--- org.apache.httpcomponents:httpclient-android:4.3.5.1
+--- com.amazonaws:aws-android-sdk-core:2.2.11
|    \--- com.google.code.gson:gson:2.2.4
+--- com.amazonaws:aws-android-sdk-s3:2.2.11
|    \--- com.amazonaws:aws-android-sdk-core:2.2.11 (*)
+--- com.google.code.ksoap2-android:ksoap2-android:3.6.0
|    \--- com.google.code.ksoap2-android:ksoap2-j2se:3.6.0
|         \--- com.google.code.ksoap2-android:ksoap2-base:3.6.0
|              +--- net.sourceforge.kxml:kxml:2.2.4
|              |    \--- org.xmlpull:xmlpull:1.1.3.3
|              \--- net.sourceforge.kobjects:kobjects-j2me:0.0-SNAPSHOT-20040926-2
+--- com.squareup.retrofit2:retrofit:2.0.0-beta3 (*)
\--- com.android.support:recyclerview-v7:+ -> 24.1.1
     +--- com.android.support:support-v4:24.1.1
     |    \--- com.android.support:support-annotations:24.1.1
     \--- com.android.support:support-annotations:24.1.1

这是完整的 Gradle 输出 https://dl.dropboxusercontent.com/u/15447938/gradle_output.txt

这是完整的构建输出

Information:Gradle tasks [:app:assembleDevDebug]
Warning:Dependency org.apache.httpcomponents:httpclient:4.3.5 is ignored for prodDebug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency org.apache.httpcomponents:httpclient:4.3.5 is ignored for prodRelease as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency org.apache.httpcomponents:httpclient:4.3.5 is ignored for devDebug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
Warning:Dependency org.apache.httpcomponents:httpclient:4.3.5 is ignored for devRelease as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
:app:preBuild UP-TO-DATE
:app:preDevDebugBuild UP-TO-DATE
:app:checkDevDebugManifest
:app:preDevReleaseBuild UP-TO-DATE
:app:preProdDebugBuild UP-TO-DATE
:app:preProdReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72411Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42411Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidAnswers136Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidBeta114Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlytics255Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlyticsCore238Library UP-TO-DATE
:app:prepareComCrashlyticsSdkAndroidCrashlyticsNdk112Library UP-TO-DATE
:app:prepareComGithubDanysantiagoSendgridAndroid1Library UP-TO-DATE
:app:prepareIoFabricSdkAndroidFabric1310Library UP-TO-DATE
:app:prepareDevDebugDependencies
:app:compileDevDebugAidl UP-TO-DATE
:app:compileDevDebugRenderscript UP-TO-DATE
:app:generateDevDebugBuildConfig UP-TO-DATE
:app:generateDevDebugAssets UP-TO-DATE
:app:mergeDevDebugAssets UP-TO-DATE
:app:processDevDebugManifest UP-TO-DATE
:app:fabricGenerateResourcesDevDebug
:app:generateDevDebugResValues UP-TO-DATE
:app:generateDevDebugResources
:app:mergeDevDebugResources
:app:processDevDebugResources
:app:generateDevDebugSources
:app:compileDevDebugJavaWithJavac
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:app:compileDevDebugNdk
:app:compileDevDebugSources
:app:transformClassesWithDexForDevDebug
Warning:Ignoring InnerClasses attribute for an anonymous inner class
(com.bea.xml.stream.util.CircularQueue$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
UNEXPECTED TOP-LEVEL EXCEPTION:
Error:Execution failed for task ':app:transformClassesWithDexForDevDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_91\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 1 mins 10.137 secs
Information:1 error
Information:5 warnings
Information:See complete output in console

最佳答案

自从您添加:

compile 'com.android.support:recyclerview-v7:+'

您使用的是24.1.1版本。
支持库 v24 需要编译 API 24。

android {
    compileSdkVersion 24
    //...

}

您可以使用another version RecyclerView 的版本,但第一个版本是 21.0.0,需要 API21。

关于android - 无法将 RecyclerView 添加到 API 级别 19,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38774887/

相关文章:

android - 单击后如何查看字符串资源中的字符串?

java - VideoView 不在 RecyclerView 中播放视频或音频

android - 在Android中获取加载包装器属性错误

android - Android Studio错误:未知主机 'service.gradle.org'

android - 离线如何在我的Android Studio中安装gradle?

android - 如何使用 Parcel.readBoolean Array()?

java - 使用 Android Gallery 作为自动幻灯片放映

java - android:- 如何更改 recyclerview 列表项的语言?

android - RecyclerView ItemDecoration - 如何为每个 viewHolder 绘制不同的宽度分隔线?

android - 区分http手机浏览器和手机app请求