导入AAR报错 Failed to transform file 'xxx.aar' to match attributes {artifactType=jar}

本文详细介绍了在封装SDK库并打包为AAR时遇到的常见错误,如Failed to transform file 'xxx.aar' to match attributes,并分享了解决方案。问题源于asset目录下的中文名文件导致的解析失败,修正后即可成功运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Failed to transform file 'xxx.aar' to match attributes {artifactType=jar}

Failed to transform file 'xxx.aar' to match attributes {artifactType=android-manifest}

在自己封装SDK库的时候想要把自己的库打包成AAR供别人使用,只要把工程变成library就可以编译出AAR

然后在要使用的工程libs里拷贝进xxx.aar 然后在build.gradle 中配置

   repositories {
        flatDir {
            dirs 'libs'
        }
    }

然后依赖引入

dependencies {
    ...
    //加入这个AAR依赖就可以了
    api(name: 'xxx', ext: 'aar')

}

如果AAR没有问题的话这样就完成了。

一般如果报错就是诸如上面的那些错误都是由于自己的打包AAR的工程有错误,一般不会,但是我就遇到了源码依赖可以正常跑起来,但是打包AAR就是跑不起来。经过一天的折腾,采用排除法从最小的项目结构开始构建然后最终定位到是由于asset目录下存在中文名的文件导致工程在依赖AAR时解析失败了。

修正后工程自然就跑起来没问题了

Execution failed for task ':app:checkDebugAarMetadata'. > Could not resolve all files for configuration ':app:debugRuntimeClasspath'. > Failed to transform activity-1.8.0.aar (androidx.activity:activity:1.8.0) to match attributes {artifactType=android-aar-metadata, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}. > Execution failed for JetifyTransform: C:\Users\��ƽ��\.gradle\caches\modules-2\files-2.1\androidx.activity\activity\1.8.0\4266e2118d565daa20212d1726e11f41e1a4d0ca\activity-1.8.0.aar. > Failed to transform 'C:\Users\��ƽ��\.gradle\caches\modules-2\files-2.1\androidx.activity\activity\1.8.0\4266e2118d565daa20212d1726e11f41e1a4d0ca\activity-1.8.0.aar' using Jetifier. Reason: IllegalArgumentException, message: Unsupported class file major version 61. (Run with --stacktrace for more details.) Suggestions: - Check out existing issues at https://issuetracker.google.com/issues?q=componentid:460323&s=modified_time:desc, it's possible that this issue has already been filed there. - If this issue has not been filed, please report it at https://issuetracker.google.com/issues/new?component=460323 (run with --stacktrace and provide a stack trace if possible). > Failed to transform annotation-experimental-1.4.0.aar (androidx.annotation:annotation-experimental:1.4.0) to match attributes {artifactType=android-aar-metadata, org.gradle.category=library, org.gradle.dependency.bundling=external, org.gradle.libraryelements=aar, org.gradle.status=release, org.gradle.usage=java-runtime}. > Execution failed for JetifyTransform: C:\Users\��ƽ��\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation-experimental\1.4.0\c7a2038d831d0cfbfb9a440890b287c2e839ecf\annotation-experimental-1.4.0.aar. > Failed to transform 'C:\Users\��ƽ��\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation-
03-25
failed The 'kotlin-android-extensions' Gradle plugin is deprecated. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.android.com/topic/libraries/view-binding) and the 'kotlin-parcelize' plugin. :app:mergeDebugResources :app:mapDebugSourceSetPaths :app:checkDebugAarMetadata :app:processDebugMainManifest :app:javaPreCompileDebug :app:mergeDebugAssets :app:checkDebugDuplicateClasses :app:mergeDebugNativeLibs :app:dataBindingMergeDependencyArtifactsDebug :JetpackMvvm:compileDebugKotlin :JetpackMvvm:bundleLibRuntimeToJarDebug org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'. org.gradle.api.internal.artifacts.transform.TransformException: Failed to transform agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3) to match attributes {artifactType=android-res, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}. org.gradle.internal.resolve.ArtifactNotFoundException: Could not find agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3). org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'. org.gradle.api.internal.artifacts.transform.TransformException: Failed to transform agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3) to match attributes {artifactType=android-res, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}. org.gradle.internal.resolve.ArtifactNotFoundException: Could not find agentweb-4.1.3.aar (com.just.agentweb:agentweb:4.1.3). org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspa
03-14
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值