我的项目没有获取库模块 jar 文件夹中定义的 class 个文件
My project not picking up class files defined in library module jar folder
我已经通过 File-> New ->Import Module
添加了一个库,该库添加成功,在这个导入的模块中添加了大约 8 jar
个文件,但是在我的应用程序模块中我无法访问这些文件。
虽然我可以轻松访问库 src
文件夹中可用的文件。
这些行已添加到库 gradle 文件中。
compile fileTree(dir: 'libs', include: '*.jar')
compile fileTree(dir: "$buildDir/native", include: 'native.jar')
build.gradle(应用程序)
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':myLibrary')
settings.gradle
include ':myLibrary'
如果我在新项目中执行这些步骤,我可以从我的 app module
访问 类 内部 jar 文件,但在我当前的项目中它们不可访问。
我也尝试删除 android studio preference
、invalidate cache and restart
,但似乎没有任何效果。
in my current project they are not accessible.
它们不应该是可访问的,因为那些依赖 jar 不是您的应用程序项目的一部分。
如果您想访问库模块 myLibrary
依赖的那些 jar,您需要在 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 插件版本的附加信息:
只需在此处引用关键解释即可获取有关 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[=48中,它本身实际上只需要它的依赖项在编译类路径中=] 或 .aar。在这种情况下,使用这个库的应用程序需要添加那些依赖于你的库模块的外部 jar,因为你的库模块没有打包它们(通过使用 compileOnly
)。并且您的应用程序需要使用 compile
.
在运行时使用这些外部 jar
我已经通过 File-> New ->Import Module
添加了一个库,该库添加成功,在这个导入的模块中添加了大约 8 jar
个文件,但是在我的应用程序模块中我无法访问这些文件。
虽然我可以轻松访问库 src
文件夹中可用的文件。
这些行已添加到库 gradle 文件中。
compile fileTree(dir: 'libs', include: '*.jar')
compile fileTree(dir: "$buildDir/native", include: 'native.jar')
build.gradle(应用程序)
compile fileTree(dir: 'libs', include: '*.jar')
compile project(':myLibrary')
settings.gradle
include ':myLibrary'
如果我在新项目中执行这些步骤,我可以从我的 app module
访问 类 内部 jar 文件,但在我当前的项目中它们不可访问。
我也尝试删除 android studio preference
、invalidate cache and restart
,但似乎没有任何效果。
in my current project they are not accessible.
它们不应该是可访问的,因为那些依赖 jar 不是您的应用程序项目的一部分。
如果您想访问库模块 myLibrary
依赖的那些 jar,您需要在 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 插件版本的附加信息:
只需在此处引用关键解释即可获取有关 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[=48中,它本身实际上只需要它的依赖项在编译类路径中=] 或 .aar。在这种情况下,使用这个库的应用程序需要添加那些依赖于你的库模块的外部 jar,因为你的库模块没有打包它们(通过使用 compileOnly
)。并且您的应用程序需要使用 compile
.