简体   繁体   English

从Jar导入无法解析

[英]Imports from Jar not resolving

I created a JAR that has two .class files in them. 我创建了一个JAR,其中包含两个.class文件。 I then added the jar to the libs folder and added the dependency into my gradle file by doing this 然后,我将jar添加到libs文件夹,并通过执行此操作将依赖项添加到我的gradle文件中

compile fileTree(dir: 'libs', include: ['*.jar'])

I then run into a strange issue that can be seen in the image below. 然后,我遇到了一个奇怪的问题,可以在下图中看到。 在此处输入图片说明

I can reference the class and use its methods, but then I do a clean/build project I get errors because the imports didnt resolve. 我可以引用该类并使用其方法,但是随后我执行一个清理/构建项目,因为导入无法解析,所以我得到了错误。 I get a Error:(22, 27) error: package com.android.biomini does not exist 我收到Error:(22, 27) error: package com.android.biomini does not exist

the classes inside the jar should be inside a folder hierarchy similar to the package name. jar内的类应位于类似于包名称的文件夹层次结构内。 So inside the jar (which is just a zip) you should have com/android/biomini/BioMiniAndroid.class .. 因此,在罐子(只是一个zip)中,您应该拥有com / android / biomini / BioMiniAndroid.class ..

One other remark, the 'com.android' package is already used by android so try using something else like com.yourcompany.biomini 另一点是,“ com.android”包已被android使用,因此请尝试使用com.yourcompany.biomini之类的东西

Right click the jar file in libs folder and select 'Add as Library'. 右键单击libs文件夹中的jar文件,然后选择“添加为库”。 It will then get added to build.gradle automatically. 然后它将被自动添加到build.gradle中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM