Import Android studio project as module

Viewed 3447

My Image

I want to import a android studio project into another android studio project. so i have imported it as module in the android studio project. this message project already have module that are used in the project. i have imported message project in android studio successfully. 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
2 Answers

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:

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

In app/build.gradle:

dependencies {
    implementation project(':myExternalLib')
}

Pay attention to 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.
Also,the rootMessage/settings.gradle will not be read because you are using the rootApp project.

Have you added this module name in 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.

apply plugin: 'com.android.application'

Write down the below line.

apply plugin: 'com.android.library'

Related