Android AAR库-资源链接失败 [英] Android AAR lib - resource linking failed

查看:618
本文介绍了Android AAR库-资源链接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Android应用程序转换为lib模块,而不复制源代码. 我做到了(修改了build.gradle文件),它进行了同步和构建,但是当我将对生成的AAR文件的依赖关系添加到另一个项目(我要使用此lib的项目)中时,构建失败并且资源链接失败.

我不明白为什么:

  • 原始应用程序会生成并运行

  • lib模块(从应用程序转换而来)构建

  • 使用该库中的AAR的
  • 项目无法生成,并在此AAR中发现错误.

例如,可能的错误之一是:

Android resource linking failed
error: resource style/TextAppearance.Design.Tab (aka bv.dev.aarlibtester:style/TextAppearance.Design.Tab) not found.
error: failed linking references.

因此它表示未找到资源,并指向我在该lib中使用的依赖项(在本示例中为design)

我创建了测试项目,以在简单的示例上进行演示.

Github

  • aar-res-app是使用design依赖项

  • 的简单应用程序项目
  • aar-res-lib是从此项目创建的库(已转换)

  • aar-res-lib-tester是使用该库的简单应用程序项目.


当前,我将库包重命名为与应用程序包不匹配,并使用jar而不是aar.

我使用Gradle -> root -> Tasks -> Other -> createFullJarRelease创建它.

结果在Build > Intermediates > Full_jar > Release > CreateFullJarRelease > full.jar

解决方案

真正的问题是,以这种方式创建的aarjar不包含它们所依赖的库.如果以这种方式添加库,则需要将其所有依赖项添加到使用它的项目中.

在我的示例中为implementation 'com.android.support:design:28.0.0'.

如果项目包含很多此类依赖项,则应添加所有这些依赖项.但是您仍然可以遇到清单合并失败"之类的问题.

或者您可以尝试将lib部署到maven或jitpack,但是您需要正确设置它,以确保将生成具有所有必需依赖项的pom文件,以便能够轻松使用此库.

I'm trying to convert Android app to lib module, without copying source. I did it (modified build.gradle file), and it syncs and builds, but when I add dependency to resulting AAR file into another project (where I want to use this lib) build fails and resource linking fails.

I can't understand why:

  • original app builds and runs

  • lib module (converted from app) builds

  • project that uses AAR from that lib does not builds, and finds error in this AAR.

For example, one of the possible errors is:

Android resource linking failed
error: resource style/TextAppearance.Design.Tab (aka bv.dev.aarlibtester:style/TextAppearance.Design.Tab) not found.
error: failed linking references.

So it says that resources not found, and point to dependencies that I used in that lib (in this example it's design)

I created test project to demonstrate this on simple example.

Github

  • aar-res-app is simple app project that uses design dependency

  • aar-res-lib is library created from this project (converted)

  • aar-res-lib-tester is simple app project that uses that lib.


Currently I renamed library package to do not match with application package, and using jar instead of aar.

I create it using Gradle -> root -> Tasks -> Other -> createFullJarRelease.

Result is in Build > Intermediates > Full_jar > Release > CreateFullJarRelease > full.jar

解决方案

So real problem is that aar and jar created this way do not contain libraries on which them depend. If adding library this way, you need to add all its dependencies to project that uses it.

In my example it is implementation 'com.android.support:design:28.0.0'.

If project contains a lot of such dependencies, you should add all of them. But you still can run in problem like "manifest merger failed" and other problems.

Or you can try to deploy your lib to maven or jitpack, but you need to setup this correctly to ensure that pom file will be generated with all needed dependencies, to be able to use this library easily.

这篇关于Android AAR库-资源链接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆