目录:
- 情景描述
- 具体解决
- 总结
1. 情景描述
[1] 环境
电脑:Mac
Android Studio : v3.4.1
Gradle: v3.4.2
compileSdkVersion : 28
[2] 添加如下开源库时出现错误
开源库
implementation 'com.jakewharton:butterknife:10.1.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
implementation 'com.google.dagger:dagger:2.10'
annotationProcessor 'com.google.dagger:dagger-compiler:2.10'
implementation("com.squareup.okhttp3:okhttp:4.0.1")
错误消息
implementation 'com.android.support:appcompat-v7:28.0.0' 红色
error
Manifest merger failed with multiple errors, see logs
and also
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processDebugManifest'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
2. 具体解决
2.1 打开 project 根目录下的 build.gradle文件,把 gradle 用最新的版本。
2019-7-252.2 点击 sync now
2019-7-25
2.3 在菜单栏 打开 Refactor ,点击 Migrate to AndroidX...
2019-7-25
2.4 点击 Migrate
2019-7-25
2.5 执行完成后, app 目录下的 build.gradle 被改成如下
2019-7-25
2.6 项目中的 activity 之前 import 的包需要删除旧的,重新导入。
2.7 修改 gradle.properties 文件,如下:
2019-7-252.8 再编译就可以啦。
然而。。。 在 API == 28 的模拟器可以跑起来了,但是在 API == 26 的真机上却编译错误。
错误如下:
Caused by: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/anthony/.gradle/caches/transforms-1/files-1.1/jetified-butterknife-runtime-9.0.0-SNAPSHOT.aar/569bc08afcd3648ae349d40c892ff908/jars/classes.jar
AGPBI: {"kind":"error","text":"Invoke-customs are only supported starting with Android O (--min-api 26)","sources":[{}],"tool":"D8"}
com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/anthony/.gradle/caches/transforms-1/files-1.1/jetified-butterknife-runtime-9.0.0-SNAPSHOT.aar/569bc08afcd3648ae349d40c892ff908/jars/classes.jar
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
...
解决方法: 在 app 目录下 的 build.gradle 文件中添加如下内容,
android{
............
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...................
}
然后在我以为可以了的时候,又出现了如下问题:
ERROR: Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0]
打开 AndroidManifest.xml ,点击 Merged Manifest ,看下错误信息:
2019-7-25解决方法:在 AndroidManifest.xml 文件添加如下一行:
android:theme="@style/AppTheme"
android:appComponentFactory="Core" //add this one
tools:replace="android:appComponentFactory"
再重新编译就可以啦!!!
2019-7-253. 总结
出现问题,一步步往下解决就好,不要心急,路遥知马力~
网友评论