简体   繁体   English

将Android项目引用到另一个android项目

[英]referring Android project to another android project

I have a Android project A which is not a library project. 我有一个不是库项目的Android项目A。 I have another Android Project Main with refers project A (by:Project properties -> Java build path -> projects tab -> Add). 我有另一个Android Project Main,其中包含了引用项目A(作者:项目属性-> Java构建路径->项目标签->添加)。 So I can access all the classes (Fragments, Activity) of Project A from Main Project. 因此,我可以从主项目访问项目A的所有类(片段,活动)。 However while running the project Main it throws an run time exception of java.lang.noclassdeffounderror . 但是,在运行项目Main时,它将引发java.lang.noclassdeffounderror的运行时异常。 Is there any way to resolve the issue without making the Project A as library project. 有没有解决方法,而无需将Project A作为库项目解决。

I am using roboguice in both of my project. 我在两个项目中都使用了roboguice So If I will make project A as library, all the resources created inside R.java file in project A will become non-final and they will not be constants any more. 因此,如果我将项目A设为库,那么在项目A的R.java文件内部创建的所有资源将变为非最终资源,它们将不再是常量。 Moreover I am using Roboguice in both of my projects.So declaring @InjectView(R.id.view_di) will give compile error in this case as it needs constants. 而且我在两个项目中都使用了Roboguice ,所以在这种情况下声明@InjectView(R.id.view_di)会产生编译错误,因为它需要常量。 On top of this we have one annotation interface which sets the header name and header background in each fragments which takes only constants as parameter. 最重要的是,我们有一个注释接口,该接口在每个片段中设置标头名称和标头背景,仅使用常量作为参数。

If we want to add library project or sub projects in Android studio project, we have to follow these steps, 如果要在Android Studio项目中添加库项目或子项目,则必须执行以下步骤,

  1. File - Project structure 文件-项目结构
  2. Click green color plus button at top left corner to add new module to project. 单击左上角的绿色加号按钮以将新模块添加到项目中。
  3. We have to select import existing project, so that other project is added as separate module. 我们必须选择导入现有项目,以便将其他项目添加为单独的模块。 If you need to add as library project, 如果您需要添加为库项目,
  4. Select Dependencies - Click green color plus button at top right corner - Select module dependency from drop dox. 选择依赖关系-单击右上角的绿色加号按钮-从下拉菜单中选择模块依赖关系。

So that we can add library project to main project. 这样我们就可以将库项目添加到主项目中。

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

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