向 j8 和杰克移动。 Gradle 同步错误

Move toward j8 and Jack. Gradle sync Error

大家好,我想使用 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 会导致错误,但是自从 7 月 dagger2 has became available 开始使用。

我用

请看我的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 目前在项目中不受支持 module,所以你想在项目模块中使用 lambdas - 只是 忘了。
  2. 所以我删除了自己的模块并将整个代码复制到主应用程序模块中
  3. 通过从 app/build.gradle
  4. 中删除以下代码行,我最终成功 gradle 构建

apply plugin: 'com.neenbedankt.android-apt' ... dependency{ apt 'com.google.dagger:dagger-compiler:2.0' // 2.5 causes error }

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

结论

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

有同样的问题。通过使用内置 "annotationProcessor" 而不是 "apt" 插件

解决

删除:

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' 插件的功能相同。