android - 向 j8 和 jack 移动。 Gradle 同步错误

标签 android android-studio android-gradle-plugin gradle-plugin

大家好,我想使用 Java8 上可用的 lamba 函数,因此我不得不应用新的工具链 Jack。不幸的是,当我做了一些意想不到的错误时。即:

Could not get unknown property 'classpath' for task ':app:transformJackWithJackForProdDebug' of type com.android.build.gradle.internal.pipeline.TransformTask. I'm using in my project library like

在项目中我使用的库是这样的:

  • Dagger
  • RxJava

我知道 dagger 会导致错误,但是从 7 月开始 dagger2 has became available使用。

我用

  • Android Studio 2.1.2
  • Gradle 版本 2.14.1
  • 安卓插件版本 2.2.0-alpha7

请看我的gradle

project/buidl.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0-alpha7'
//        classpath 'com.android.tools.build:gradle:2.2.0-alpha3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app/build.gradle

apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'

android {
    compileSdkVersion 24  
    buildToolsVersion '24.0.0' 

    defaultConfig {
        applicationId "XXX"
        minSdkVersion 19
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

        jackOptions{
            enabled true
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            versionNameSuffix "_debug"
        }
    }
    productFlavors{
        dev{
            minSdkVersion 21
        }
        prod {
            minSdkVersion 19
        }
    }
    compileOptions{
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

ext {
    JUNIT_VERSION = '4.12'
    DAGGER_VERSION = '2.4'
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile "junit:junit:$JUNIT_VERSION"
    compile project(path: ':android_mvp')
    // dependency injection
    apt 'com.google.dagger:dagger-compiler:2.0' // 2.5 causes error
    compile 'com.google.dagger:dagger:2.0'
    provided 'javax.annotation:jsr250-api:1.0'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
    // for new Jack and Jill gradle 2.2.+
    // rx java
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'io.reactivex:rxandroid:1.2.1'
    // RxAndroid providing Android Scheduler
    compile 'io.reactivex:rxjava-joins:0.22.0'
    // view
    compile 'com.android.support:appcompat-v7:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:recyclerview-v7:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    // rest / stream
    compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.0-beta4'
    compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4'
    compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
    compile 'com.squareup.okhttp3:okhttp:3.2.0'
    compile 'com.neovisionaries:nv-websocket-client:1.29'
    // time
    compile 'net.danlew:android.joda:2.9.3'
}

已编辑

  1. 好的,正如我所读Lambda 目前在项目中不受支持 模块,所以你想在项目模块中使用 lambdas - 只是 忘记了。
  2. 所以我删除了自己的模块并将整个代码复制到主应用程序模块中
  3. 通过从 app/build.gradle 中删除以下代码行,我最终成功地进行了 gradle 构建

应用插件:'com.neenbedankt.android-apt' ... 依赖{ apt 'com.google.dagger:dagger-compiler:2.0'//2.5 导致错误 }

  1. 但是与 dagger 相关的错误仍然存​​在,这意味着有时项目能够重建,有时它写了很长的堆栈跟踪。

结论

在第一个 j8 发布 2.5 年后,懒惰的 Android 团队无法集成它。 2,5 年的 IT 时间太长了,所以我的编程技能慢慢被弃用了!我希望他们在 j9 发布之前完成!

最佳答案

遇到了同样的问题。通过使用内置的“annotationProcessor”而不是“apt”插件解决

https://stackoverflow.com/a/39086683/2282051

删除:

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
apply plugin: 'com.neenbedankt.android-apt'
apt 'com.google.dagger:dagger-compiler:2.0'

你已经拥有了

dependencies {
    annotationProcessor 'com.google.dagger:dagger-compiler:2.0'
}

它与“apt”插件的作用相同。

关于android - 向 j8 和 jack 移动。 Gradle 同步错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38770381/

相关文章:

php - Recyclerview MySql int 显示 0

android - 升级安装了 Android-Studio Ubuntu 18.04 的 CMake 版本

android studio Gradle 同步失败 : Failed to find Build Tools revision 28. 0.2

Gradle - 使现有的 android 项目成为其他项目的子项目并运行 "gradlew tasks"

android - 如何实现一个小的静态 map 预览作为列表图标?

java - 尽管之前在 AsyncTask 类中定义过,但 JSON 对象为 null?

java - Android Air Native Extension 安装新的 apk 版本抛出 "no activity found to handle intent"

java - 如何将 csv 文件中的数据打印到第二个 Activity 上?

android - 在 Android gradle 构建开始时根据风格复制文件

android - 如何使用 Gradle 构建系统让 PhoneGap 项目在 Android Studio 中运行