Android:编译错误:任务 ':app:compileDebugJava'执行失败

标签 android android-gradle-plugin build.gradle android-recyclerview

我遇到了以下错误:

Error:(89, 39) error: incomparable types: CAP#1 and int  
where CAP#1 is a fresh type-variable:  
CAP#1 extends Object from capture of ?Note: Some input files use unchecked or   unsafe operations.  
Note: Recompile with -Xlint:unchecked for details.  
Error:Execution failed for task ':app:compileDebugJava'.  

Compilation failed; see the compiler error output for details.

我的 Gradle 文件如下所示:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.0 rc3"

    repositories {
        maven { url "https://jitpack.io" }
        mavenCentral()
        jcenter()

    }

    defaultConfig {
        applicationId "wishlist.oj.app"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.android.support:recyclerview-v7:21.+'
    compile 'com.android.support:cardview-v7:21.+'
}

错误来 self 的 Recycler View Adapter 文件,它只是将 multiple textviews 膨胀到 recycler view

最佳答案

Error:Execution failed for task ':app:compileDebugJava'.

良好实践

首先启用multiDexEnabled ,然后升级你的support:recyclerview ,support:appcompat ,support:cardview版本

The Android plugin for Gradle available in Android SDK Build Tools 21.1 and higher supports multidex as part of your build configuration. Make sure you update the Android SDK Build Tools tools and the Android Support Repository to the latest version using the SDK Manager before attempting to configure your app for multidex.

将您的应用开发项目设置为使用 multidex 配置需要您对应用开发项目进行一些修改。特别是您需要执行以下步骤:

  1. 更改 Gradle 构建配置以启用 multidex
  2. 修改 list 以引用 MultiDexApplication 类

修改您的应用 Gradle 构建文件配置以包含支持库并启用 multidex 输出。

     android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"

        defaultConfig {
            ...
            minSdkVersion 16
            targetSdkVersion 23
            ...

            // Enabling multidex support.
            multiDexEnabled true
        }
        ...
    }

    dependencies {
      compile 'com.android.support:multidex:1.0.0'
      compile 'com.android.support:appcompat-v7:23.1.1'
      compile 'com.android.support:recyclerview-v7:23.1.1"
      compile 'com.android.support:cardview-v7:23.1.1'
     }

然后Clean-Rebuild-Restart-Sync你的项目

关于Android:编译错误:任务 ':app:compileDebugJava'执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34488349/

相关文章:

android - 断言错误改造Android

java - 是否可以检测您连接的 WiFi 类型?

android - LintOption 基线错误

gradle - 排毒构建错误 : More than one file was found with OS independent path 'lib/x86/libc++_shared.so'

android - 访问远程 gradle 依赖

gradle - 尝试在 IntelliJ 中构建项目时出现同步错误

android - ListView、BaseAdapter、getViewTypeCount() - 如何强制适配器再次检查 getViewTypeCount()?

android - 对Android设备上的文件系统感到困惑

gradle - 它当前正被另一个 Gradle 实例使用

java - 尝试连接到 firebase 时 list 合并失败