如何从android studio中的另一个模块导入类? [英] How to import class from another module in android studio?

查看:168
本文介绍了如何从android studio中的另一个模块导入类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在单个android项目中创建了两个模块,命名为x和y。

I created two modules in single android project, named it x and y.


  1. 模块x有一个类Egg(包:com .example.x)

  2. 模块y有一个类Foo(包:com.example.y)

现在我想在Egg类中导入类Foo,为此我在类Egg中写下了下面提到的语句

Now I want to import class Foo in the class Egg, for which I wrote the statement mentioned below in class Egg

Import com.example.y.Foo;

现在,foo不被android识别。

Now, Foo is not recognized by android.

问题,


是否可以仅使用
import语句从其他模块导入Class?

Is it possible to import Class from a different module using just import statement?

我是否需要创建模块y的库,然后将创建的
库导入模块x?

Do I need to create library of Module y and then import created library into module x?

或者解决方案可能是别的。

Or may the solution is something else.

推荐答案

确保以下内容:

在settings.gradle中,您应该:包含':x',':y'

In settings.gradle, you should have: include ':x', ':y'.

在x / build.gradle中,您应该添加y作为依赖项:

In x/build.gradle, you should add y as a dependency:

dependencies {
        compile project(':y')
        // other dependencies
}

这篇关于如何从android studio中的另一个模块导入类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆