1

A 类引用 B 类。它们在同一个包中。所以A没有导入B。也没有出现编译错误。但是当我得到一个类对象并调用 ClassA.getDeclaredMethods 时,会发生异常:

java.lang.NoClassDefFoundError: xxx.xxx.B ?

但是当我在A中导入B类的父接口并同时清楚地将A的方法返回类型从B更改为B的父接口时。没关系。

我尝试了两个android设备并且都发生了错误。

为什么?

PS:我从日志中得到了这个原因

04-21 21:31:25.005 W/dalvikvm(21707): Class resolved by unexpected DEX: Lxxx/xxxx/xxxx/methods/FieldsConfig;(0x42a18bd8):0x76e66000 ref [Lxxx/xxxx/xxxx/ITelephonyManagerInterface$IFieldsConfig;] Lxxx/xxxx/xxxx/ITelephonyManagerInterface$IFieldsConfig;(0x42a18bd8):0x76d17000
04-21 21:31:25.005 W/dalvikvm(21707): (Lxxx/xxxx/xxxx/methods/FieldsConfig; had used a different Lxxx/xxxx/xxxx/ITelephonyManagerInterface$IFieldsConfig; during pre-verification)
04-21 21:31:25.005 W/dalvikvm(21707): Link of class 'Lxxx/xxxx/xxxx/methods/FieldsConfig;' failed

我从两个 dex 加载一个类。

    compile project(":base")

    androidTestCompile project(':AAAA')  // only androidTest
    androidTestCompile project(':BBBB')
    androidTestCompile project(':CCCC') {
        exclude project(":base")  //how I exclude one project??
    }//only androidTest

现在另一个问题来了。如何从 androidTestCompile project(':CCCC') 中排除 project(":base") ?

4

0 回答 0