1 2 |
Program type already present: android.support.annotation.AnimRes Message{kind=ERROR, text=Program type already present: android.support.annotation.AnimRes, sources=[Unknown source file], tool name=Optional.of(D8)} |
"Program type already present" 指的是项目内有同名的类, 即 AnimRes 在项目中存在不同的版本;
多处存在同名文件, 一般是依赖库中有重复的依赖(一个包含的依赖可能依赖了其它依赖, 造成库相同但是版本不同);
使用 "./gradlew app:dependencies" 查看 app 这个模块的依赖库需要的依赖库;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
debugAndroidTestCompileClasspath - Resolved configuration for compilation for variant: debugAndroidTest +--- com.android.databinding:baseLibrary:3.1.1 +--- com.android.databinding:library:3.1.1 | +--- android.arch.lifecycle:runtime:1.0.3 -> 1.1.0 | | +--- android.arch.lifecycle:common:1.1.0 | | | \--- com.android.support:support-annotations:26.1.0 -> 27.1.1 | | +--- android.arch.core:common:1.1.0 | | | \--- com.android.support:support-annotations:26.1.0 -> 27.1.1 | | \--- com.android.support:support-annotations:26.1.0 -> 27.1.1 | +--- com.android.support:support-core-utils:26.1.0 -> 27.1.1 | | +--- com.android.support:support-annotations:27.1.1 | | \--- com.android.support:support-compat:27.1.1 | | +--- com.android.support:support-annotations:27.1.1 | | \--- android.arch.lifecycle:runtime:1.1.0 (*) | \--- com.android.databinding:baseLibrary:3.1.1 +--- com.android.databinding:adapters:3.1.1 | +--- com.android.databinding:baseLibrary:3.1.1 | \--- com.android.databinding:library:3.1.1 (*) +--- com.android.support:appcompat-v7:27.1.1 | +--- com.android.support:support-annotations:27.1.1 | +--- com.android.support:support-core-utils:27.1.1 (*) | +--- com.android.support:support-fragment:27.1.1 | | +--- com.android.support:support-compat:27.1.1 (*) | | +--- com.android.support:support-core-ui:27.1.1 | | | +--- com.android.support:support-annotations:27.1.1 | | | +--- com.android.support:support-compat:27.1.1 (*) | | | \--- com.android.support:support-core-utils:27.1.1 (*) | | +--- com.android.support:support-core-utils:27.1.1 (*) | | +--- com.android.support:support-annotations:27.1.1 | | +--- android.arch.lifecycle:livedata-core:1.1.0 | | | +--- android.arch.lifecycle:common:1.1.0 (*) | | | +--- android.arch.core:common:1.1.0 (*) | | | \--- android.arch.core:runtime:1.1.0 | | | \--- android.arch.core:common:1.1.0 (*) | | \--- android.arch.lifecycle:viewmodel:1.1.0 | +--- com.android.support:support-vector-drawable:27.1.1 | | +--- com.android.support:support-annotations:27.1.1 | | \--- com.android.support:support-compat:27.1.1 (*) | \--- com.android.support:animated-vector-drawable:27.1.1 | +--- com.android.support:support-vector-drawable:27.1.1 (*) | \--- com.android.support:support-core-ui:27.1.1 (*) +--- com.android.support.constraint:constraint-layout:1.1.3 | \--- com.android.support.constraint:constraint-layout-solver:1.1.3 +--- org.greenrobot:eventbus:3.1.1 +--- com.android.support:recyclerview-v7:27.1.1 | +--- com.android.support:support-annotations:27.1.1 | +--- com.android.support:support-compat:27.1.1 (*) | \--- com.android.support:support-core-ui:27.1.1 (*) \--- com.ibm.icu:icu4j:60.2 |
AnimRes 包含在 com.android.support:support-annotations 中, 如果是依赖的库存在相互依赖, 造成版本不同, 会出现多个不同版本号的 support-annotations;
如果发现有不同版本号, 可以使用下列方法解决;
1 2 3 4 5 6 7 8 |
android{ // -- } // 在 Module 的 build.gradle 中添加 configurations { compile.exclude group: 'com.android.support', module: 'support-annotations' } |
经过对比, 我发现依赖库的相互依赖没有问题, 查看导入的 jar 包, 发现 jar 中也有一个 "android.support.annotation.AnimRes", 删除掉重复引用即可;
0 Comments