V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
nicegoing
V2EX  ›  Android

android studio 2.2 设置支持 java8,dagger2 就会报错,求解决办法?

  •  
  •   nicegoing · 2016-10-07 09:56:45 +08:00 · 7572 次点击
    这是一个创建于 2729 天前的主题,其中的信息可能已经有所发展或是发生改变。
    其他的库都兼容,我用 dagger2.7 就是编译不过,我感觉是Jack Toolchain的问题。请问大家怎么解决的。
    7 条回复    2016-10-12 12:54:50 +08:00
    wenLiangcan
        1
    wenLiangcan  
       2016-10-07 11:27:49 +08:00 via Android
    在 buildscript.dependencies 里加入 guava
    CFO
        2
    CFO  
       2016-10-07 15:30:04 +08:00 via Android
    引用了 apt 吗?
    xingda920813
        3
    xingda920813  
       2016-10-09 16:49:08 +08:00
    如果启用了 Jack 的话( jackOptions.enabled = true ), project build.gradle classpath 中的 apt 要去掉, module build.gradle 中的 apply plugin: 'apt' 也要去掉, dependencies 中的 apt 要改为 annotationProcessor 。

    如果没有启用 Jack 编译器,把日志贴上来看看。
    xingda920813
        4
    xingda920813  
       2016-10-09 17:14:09 +08:00
    project build.gradle :

    classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

    module build.gradle :

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

    compile 'com.google.dagger:dagger:+'
    provided 'org.glassfish:javax.annotation:+'
    provided 'com.google.dagger:dagger-compiler:+'
    nicegoing
        5
    nicegoing  
    OP
       2016-10-10 09:24:41 +08:00
    @xingda920813
    启用的是 Jack ,报这个错误:
    com.android.jack.ir.JNodeInternalError: java.lang.Exception: java.lang.NoClassDefFoundError: org/eclipse/osgi/util/NLS
    有人提出了这个问题 https://code.google.com/p/android/issues/detail?id=210882 ,应该还没修复。
    xshengcn
        6
    xshengcn  
       2016-10-12 11:26:08 +08:00   ❤️ 1
    不需要引用 apt
    apply plugin: 'com.android.application'

    android {

    defaultConfig {

    jackOptions {
    enabled true
    }
    }

    compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
    }
    }

    dependencies {
    // dagger2
    compile 'com.google.dagger:dagger:2.7'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.7'
    provided 'javax.annotation:jsr250-api:1.0'
    }
    nicegoing
        7
    nicegoing  
    OP
       2016-10-12 12:54:50 +08:00
    @xshengcn 用你的配置,还是那个问题 NoClassDefFoundError: org/eclipse/osgi/util/NLS 。暂时不用 Jack 了,等成熟了再看看。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3377 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.