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

查看:87
本文介绍了如何从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;

现在,Android 无法识别 Foo.

Now, Foo is not recognized by android.

问题,

是否可以仅使用从不同的模块导入类导入语句?

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中,你应该有:include ':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天全站免登陆