简体   繁体   English

在Android Studio中添加外部Jar库时出错

[英]Error in adding external Jar libraries in android studio

This is wrt Android Studio 1.3.2 这是Android Studio 1.3.2

So when i try to add the Repo from the Import Module->Import Existing Jar,the library is added as a separate module and included in the settings.gradle. 因此,当我尝试从Import Module-> Import Existing Jar添加Repo时,该库将作为一个单独的模块添加并包含在settings.gradle中。

After this when I try to use the Jar, I get the message Add Library 'x' to the classpath Once i add this to the classpath,I am able to access the classes however the project does not build with the following error, 在此之后,当我尝试使用Jar时,我收到消息Add Library 'x' to the classpath一旦将其添加到类路径中,我就可以访问类,但是该项目未生成,但出现以下错误,

class Xx cannot be found(Xx belongs to the jar) Is there a work-around to this. class Xx cannot be found(Xx belongs to the jar)是否有解决方法。

I can add the jar by creatings a libs folder in the app module and clicking on add as library . 我可以通过在app模块中创建一个libs文件夹并单击“ add as library来添加jar。 However I do not want the jar inside the main module. 但是我不希望罐子放在主模块中。

Do something like this: 做这样的事情:

To import your module: Step-1; 导入模块: 步骤1; Goto File->new->import module. 转到File-> new-> import模块。 Select and import your module. 选择并导入您的模块。

Step-2: In your app's build.gradle add compile project(':yourlibrary') 步骤2:在您应用的build.gradle中添加编译项目(':yourlibrary')

Step-3: Sync your gradle. 步骤3:同步您的Gradle。

Now to add jar in the above module: 现在在上述模块中添加jar:

Step-1 : Copy your jar file into your module's lib folder. 步骤1 :将jar文件复制到模块的lib文件夹中。

Step-2: In your module's build.gradle file add a dependency like compile files('libs/your_jar_file.jar') 第2步:在模块的build.gradle文件中添加一个依赖项,例如编译文件('libs / your_jar_file.jar')

Step-3 Sync your gradle and you are good to go. 步骤3同步您的Gradle,您一切顺利。

When you add any module dependency then it will not automatically added to gradle file. 当您添加任何模块依赖项时,它将不会自动添加到gradle文件中。

You have to add that dependancy to gradle file manually.. 您必须将该依赖项手动添加到gradle文件中。

Now here you are adding module to Android Studio project then, You have to add 现在在这里,您要向Android Studio项目添加模块,然后,您必须添加

  compile project(':module_name') 

So that you module will be attached to your app module. 这样您的模块将被附加到您的应用程序模块。

Hope It will help. 希望会有所帮助。

Thank you.! 谢谢。!

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

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