加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何从android studio中的另一个模块导入类?

发布时间:2020-12-14 05:26:43 所属栏目:Java 来源:网络整理
导读:我在单个 android项目中创建了两个模块,命名为x和y. Module x有一个类Egg(Package:com.example.x) 模块y有一个类Foo(Package:com.example.y) 现在我想在类Egg中导入Foo类,为此我在类Egg中写下面提到的语句 Import com.example.y.Foo; 现在,Foo不被android
我在单个 android项目中创建了两个模块,命名为x和y.

> Module x有一个类Egg(Package:com.example.x)
>模块y有一个类Foo(Package:com.example.y)

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

Import com.example.y.Foo;

现在,Foo不被android识别.

问题,

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

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

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

解决方法

确保以下内容:

在settings.gradle中,您应该具有:include’:x’,’:y’.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读