我有一个包含 2 个模块的项目:一个具有构建类型
debug
、release
和 enterprise
的应用程序 (Java) 以及应用程序使用的 Kotlin 库(release
和 debug
)。
我正在使用 AndroidX,并且我的
gradle.properties
中有以下内容:
android.useAndroidX=true
android.enableJetifier=true
如果我通过 Gradle 运行该项目,我会收到一堆编译错误(预期)。但如果我尝试在 Android Studio (3.2 Beta 5) 中使用它,特别是在尝试与 Gradle 模型同步时,我会得到以下结果:
Unable to resolve dependency for ':app@debug/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@release/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@enterprise/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
Unable to resolve dependency for ':app@enterpriseUnitTest/compileClasspath': Failed to transform file 'some-lib-release.aar' to match attributes {artifactType=processed-aar} using transform JetifyTransform
我的
settings.gradle
:
include ':app',':some-lib'
project(':some-lib').projectDir = file ('../some-lib/lib')
库模块最终将成为该应用程序和其他应用程序使用的自己的库,但在我开发它时,我将其构建为应用程序的一部分。在我切换到 AndroidX 之前,一切都运行良好。
app
模块将依赖关系声明为:
implementation project(path: ':some-lib', configuration: 'default')
如果我在声明依赖项时省略
configuration: 'default'
位,我会得到:
Unable to resolve dependency for ':app@enterprise/compileClasspath': Could not resolve project :some-lib.
Unable to resolve dependency for ':app@enterpriseUnitTest/compileClasspath': Could not resolve project :some-lib.
关于我在这里做错了什么有什么想法吗?
该错误似乎是由损坏的 Jetified 文件引起的。
仅从 Gradle 缓存文件夹中删除损坏的 .aar:
rm ~/.gradle/caches/modules-2/files-2.1/path-to/some-release.aar
“路径”可能是包名称,例如,
com.example.somerelease
有时可以从错误消息本身获取要删除的文件的路径,并将其剪切并粘贴到终端中以执行
rm
命令。
删除整个文件夹并不是最佳解决方案,因为所有依赖项都需要再次 Jetified。如果你已经拥有了 腐败问题,您可能会再次遇到该问题。
我可以发誓我已经尝试过这个,但是为构建类型指定一组
matchingFallbacks
就达到了目的:
buildTypes {
release {
// blah blah
matchingFallbacks = ['release']
}
enterprise {
// blah blah
matchingFallbacks = ['release']
}
debug {
// blah blah
matchingFallbacks = ['debug']
}
}
更多这里
试试这个:
implementation fileTree(include:[':some-lib'], dir: "../lib/path")
我得到了解决方案..只需将以下几行输入到 build.gradle(app)
compileOptions {
sourceCompatibility '1.8'
targetCompatibility '1.8'
}
当我使用 jdk11 构建应用程序时,这种情况发生在我身上。
切换到jdk8对我来说很有效。
* What went wrong:
Execution failed for task ':****:kaptGenerateStubsDebugKotlin'.
> Could not resolve all files for configuration ':****'.
> Failed to transform coreService.jar (project :coreService) to match attributes {artifactType=android-classes, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.jvm.version=11, org.gradle.libraryelements=jar, org.gradle.usage=java-api, org.jetbrains.kotlin.localToProject=public, org.jetbrains.kotlin.platform.type=jvm}.
> Execution failed for JetifyTransform: ****/build/libs/coreService.jar.
> Failed to transform '****/build/libs/coreService.jar' using Jetifier. Reason: null. (Run with --stacktrace for more details.)
解决此问题的选项(优先级):
(注意:仅当上一个选项不起作用时才进行下一步)
implementation project(path: ':yourLibraryname', configuration: 'default')
Invalidate Caches/Restart
。有效的方法是将我的 gradle 版本更新到最新版本
错误就在这里,
implementation files("libs/open-web-sdk-release")
。我把它替换为,
implementation project(":open-web-sdk-release")
.使用此链接...
https://developer.android.com/studio/build#module-level.
Gradle 用户主页的路径解决了同样的问题:
export GRADLE_USER_HOME=/home/.gradle
摇篮 | Gradle 用户主页:/home/.gradle
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
C:/UserName/.gradle/cashes/gradleVersion
并再次同步我的项目。