gpt4 book ai didi

android - 我的项目没有获取库模块 jar 文件夹中定义的类文件

转载 作者:行者123 更新时间:2023-11-29 23:28:59 25 4
gpt4 key购买 nike

我通过转到 File->New ->Import Module 添加了一个库,该库添加成功,在这个导入的模块中添加了大约 8 个 jar 文件,但在我的应用程序模块中我无法访问这些文件。

尽管我可以轻松访问库 src 文件夹中可用的文件。

这些行添加到库 gradle 文件中。

compile fileTree(dir: 'libs', include: '*.jar')
compile fileTree(dir: "$buildDir/native", include: 'native.jar')

build.gradle(app)

compile fileTree(dir: 'libs', include: '*.jar')
compile project(':myLibrary')

settings.gradle

include ':myLibrary'

如果我在一个新项目中执行这些步骤,我可以从我的 app 模块 访问 jar 文件中的类,但在我当前的项目中它们是不可访问的。

我还尝试删除 android studio preference使缓存无效并重新启动,但似乎没有任何效果。

最佳答案

in my current project they are not accessible.

它们不应该是可访问的,因为那些依赖 jar 不是您的应用项目的一部分。

如果你想访问你的库模块所依赖的那些 jar myLibrary ,您需要在 app 中指定它们项目使用

compile fileTree(dir: '../myLibrary/libs', include: '*.jar')
compile fileTree(dir: "../myLibrary/native", include: 'native.jar')

并更改您的 myLibrary设置为

provided fileTree(dir: 'libs', include: '*.jar')
provided fileTree(dir: "$buildDir/native", include: 'native.jar')

通过执行上述操作,您应该能够从您的应用程序模块访问您的 jar,并且不会有任何重复的类导致冲突。

也许将您的 Android Gradle 插件升级到 3.0+ 会更好。

关于 android gradle 插件版本的附加信息:

  1. > https://stackoverflow.com/a/51392464/8034839
  2. > https://developer.android.com/studio/build/dependencies

只需在此处引用关键解释即可获取有关 provided 的信息和 compileOnly :

Gradle adds the dependency to the compile classpath only (that is, it is not added to the build output). This is useful when you're creating an Android module and you need the dependency during compilation, but it's optional to have it present at runtime.

对于你的库模块,如果你不把它们打包到你的库中,它本身实际上只需要它的依赖项在编译类路径.jar.aar 。在这种情况下,使用这个库的应用程序需要添加那些依赖于你的库模块的外部 jar,因为你的库模块没有打包它们(通过使用 compileOnly)。并且您的应用程序需要使用 compile 使这些外部 jar 在运行时可用。 .

关于android - 我的项目没有获取库模块 jar 文件夹中定义的类文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53029520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com