简体   繁体   English

无法在Intellij IDEA的项目中包含源库

[英]Can not include source library in project in Intellij IDEA

I've created library project in IDEA with common helpers , which I use in my android applications. 我已经在IDEA中使用常见的助手创建了库项目,并在我的android应用程序中使用了它。

Then I've created android application and included in it my library project like this tutorial said . 然后,我创建了android应用程序,并将其包含在我的库项目中(如本教程所述)

Everything seemed okay, code autocomplete worked fine, IDEA recognize that library and all classes and methods in it. 一切似乎都还好,代码自动完成工作正常,IDEA识别出该库以及其中的所有类和方法。

But then I compiled application and saw error " 'org.my.helperlibrary' does not exist ". 但是随后我编译了应用程序,并看到错误“ 'org.my.helperlibrary'不存在 ”。 However as I said IDEA acts like everything okay before making/launching project. 但是正如我所说的,IDEA在进行/启动项目之前表现得还不错。

Here is similar question , but answer is trivial, of course my library has checked " Is Library Project " option but I still can not launch my application which use my library. 这是一个类似的问题 ,但是答案是微不足道的,当然我的图书馆已经选中了“ 是图书馆项目 ”选项,但是我仍然无法启动使用我的图书馆的应用程序。

Updated: 更新:

I've just saw an error: " UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added: Lorg/my/helperlibrary/Helper; " when I removed all usages of library in my android application. 我刚刚看到一个错误:“当我在android应用程序中删除了所有的库用法时,“ 意外的最高级别例外:java.lang.IllegalArgumentException:已经添加:Lorg / my / helperlibrary / Helper; ”。 So it's just included in my app and not used. 因此,它只是包含在我的应用程序中而不被使用。

It turned out that I should not add dependency manually in that window 原来,我不应该在该窗口中手动添加依赖项

在此处输入图片说明

I rather should add new module in my Project window at the left 我宁愿在左侧的“项目”窗口中添加新模块

在此处输入图片说明在此处输入图片说明在此处输入图片说明

Then I should choose iml file in the root folder of android library project I want to use 然后我应该在我要使用的android库项目的根文件夹中选择iml文件

在此处输入图片说明

Then I pressed finish and from that point I had two modules in my project 然后我按完成,从那时起,我的项目中有了两个模块

在此处输入图片说明

After that when using classes I can press Alt+Enter on any class from SampleLibrary and tell IDEA to add module dependency 之后,在使用类时,我可以在SampleLibrary中的任何类上按Alt + Enter,并告诉IDEA添加模块依赖项

在此处输入图片说明

Then I could see that IDEA made all I need without me. 然后我可以看到IDEA在没有我的情况下满足了我的所有需求。 I can now use SampleLibrary from SampleApplication! 我现在可以使用SampleApplication中的SampleLibrary!

在此处输入图片说明

Try to select library project, then click Build -> Compile <your library project name> . 尝试选择库项目,然后单击Build -> Compile <your library project name> Then back to you project which use this library and click Build -> Rebuild Project . 然后回到使用该库的项目,然后单击Build -> Rebuild Project After that try to run project again. 之后,尝试再次运行项目。

Hope it helps. 希望能帮助到你。

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

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