简体   繁体   English

将 Android Studio 项目作为模块导入

[英]Import Android studio project as module

我的形象

I want to import a android studio project into another android studio project.我想将一个 android studio 项目导入到另一个 android studio 项目中。 so i have imported it as module in the android studio project.所以我将它作为模块导入到 android studio 项目中。 this message project already have module that are used in the project.此消息项目已有项目中使用的模块。 i have imported message project in android studio successfully.我已成功在 android studio 中导入消息项目。 but when i adding a dependency it is not showing this module, so please check image that i have imported and how can i add dependency of message module.但是当我添加一个依赖项时它没有显示这个模块,所以请检查我导入的图像以及如何添加消息模块的依赖项。

I have tried我试过了

implementation project(':message')

But getting a error但得到一个错误

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :message. Show Details Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :message.

Show Details Affected Modules: app

ERROR: Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve project :message. Show Details Affected Modules: app

You should have a structure like this:你应该有一个这样的结构:

   -rootApp
    |--build.gradle
    |--settings.gradle
    |--app
    |----build.gradle

    -rootMessage
    |--build.gradle
    |--settings.gradle
    |--vcard
    |----build.gradle

Inside a project you can refer an external module.在项目中,您可以引用外部模块。

Just use:只需使用:

In rootApp/settings.gradle :rootApp/settings.gradle

include ':app' 
include ':myExternalLib'
project(':myExternalLib').projectDir=new   File('/path-to-project/rootMessage/vcard')

In app/build.gradle :app/build.gradle

dependencies {
    implementation project(':myExternalLib')
}

Pay attention to myExternalLib.注意 myExternalLib。
You have to use the path of the library inside the other project, not the root of the project.您必须使用其他项目中的库路径,而不是项目的根目录。
In your case the path is rootMessage/vcard .在您的情况下,路径是rootMessage/vcard
Also,the rootMessage/settings.gradle will not be read because you are using the rootApp project.此外, rootMessage/settings.gradle将不会被读取,因为您正在使用 rootApp 项目。

Have you added this module name in setting.gradle您是否在setting.gradle添加了此模块名称

Like:喜欢:

First thing第一件事

include ':app', ':message', ':photoviewer', 'vcard'

second thing第二件事

The major issue is that there you applied plugin is com.android.application instead of com.android.library .主要问题是您应用的插件是com.android.application而不是com.android.library

apply plugin: 'com.android.application'

Write down the below line.写下下面的行。

apply plugin: 'com.android.library'

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

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