Could not create task ‘:mainActivity:minifyReleaseWithR8‘.
最近接收了一个老项目,把项目clone下来后,总是报错,无法运行
Build-tool 33.0.1 is missing DX at D:\Android\Sdk\build-tools\33.0.1\dx.bat
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':mainActivity:externalNativeBuildDebug'.
> Could not resolve all dependencies for configuration ':mainActivity:debugRuntimeClasspath'.
> Could not create task ':mainActivity:minifyReleaseWithR8'.
> Installed Build Tools revision 33.0.1 is corrupted. Remove and install again using the SDK Manager.
总是说无法编译,说我的Build Tools revision 33.0.1是异常的无法使用
第一步它说:externalNativeBuildDebug编译失败,所以这一块考虑是NDK没配置,导致的native编译失败,在local.properties配置一下NDK就可以了
接下来它又说:compileDebugAidl失败
Build-tool 33.0.1 is missing DX at D:\Android\Sdk\build-tools\33.0.1\dx.bat
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':doodle:compileDebugAidl'.
> Installed Build Tools revision 33.0.1 is corrupted. Remove and install again using the SDK Manager.
org.gradle.api.internal.tasks.TaskDependencyResolveException: Could not determine the dependencies of task ':doodle:compileDebugAidl'.
这个失败我认为和sdk和ndk版本没关系了,结果查了半天,我们仔细看下报错之前最后执行的那个命令
Build-tool 33.0.1 is missing DX at D:\Android\Sdk\build-tools\33.0.1\dx.bat
要到这个目录下找dx.bat,然而这个目录下并没有dx.bat,只有d8.dat,我们来看下这两个是干什么的
在较新的 Android SDK Build Tools 版本中,d8
取代了旧的 dx
工具,d8
是一个更高效的 Dalvik 字节码转换工具。然而,有些较旧的项目或者构建脚本可能仍然依赖于 dx
工具。当这些旧项目在新的 Build Tools 环境中构建时,就会因为找不到 dx
工具而报错。
怎么解决呢?
通过将 d8
重命名为 dx
,将 d8.jar
重命名为 dx.jar
,可以让旧项目误以为 dx
工具仍然存在,从而能够在新的 Build Tools 环境中继续构建,这是一种临时的兼容性解决方案。不过需要注意的是,这种方法可能会带来一些潜在问题,因为 d8
和 dx
的功能虽然相似,但并不完全相同,在某些情况下可能会导致构建出来的应用出现运行时错误。最好的做法是对旧项目进行升级,使其能够兼容新的 d8
工具
解决步骤:
1.33.0.1下的d8.dat 拷贝重命名为dx.dat
2.33.0.1/d8.jar 拷贝重命名为d8.jar