Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import a gradle built module as depencency in Android Studio?

I just created my first project in Android Studio and now want to add a third party library (that is also built by gradle) to the project. How can this be done? What I've tried so far is:

  1. File->Import Module-> Choose build.gradle from the library folder.
  2. This displays the text ":build.gradle" right next to "Module name:" as well as the error message: "Project already contains module with this name". The finish button stays disabled until ":build.gradle" is changed.
  3. Changing the ":build.gradle" to "something-else" enables the finish button, but pushing it causes the following error message: FileNotFoundException: /Workspace/AndroidStudio/project/something-else (No such file or directory): /Workspace/AndroidStudio/project/something-else (No such file or directory)

Obviously the wrong approach to import a module as dependency. But how else should it be done? Any advice is appreciated, Thank you!

like image 337
SePröbläm Avatar asked Jan 02 '15 11:01

SePröbläm


People also ask

How do I import build Gradle?

Launch Android Studio, and click File > New > Import Project. Locate your project directory, click the build. gradle file you created above to select it, and then click OK to import your project.

How do I manually add a dependency?

Click the dependency you want to add to your application. You can use Ctrl+click to select multiple non adjacent dependencies, or Shift+click to select multiple adjacent dependencies. Drop the dependencies to the Manual Dependencies folder of the application. Save the application.


2 Answers

I have also ran into same kind of issue. For me the problem is because i already imported the module. When you importing the module first time it will create a folder inside the project directory named which you entered on the importing window. So when i try to import it again using the same name it will produce the error "Project already contains module with this name". Because there is already a folder with the similar name is there. So to resolve this you need to first delete the folder which already imported from the project directory. And its is not the fine way to renaming the build.gradle.

I know the answer is too late. Hope it will help somebody.

like image 107
Mahendran Sakkarai Avatar answered Oct 27 '22 01:10

Mahendran Sakkarai


Faced similar issue issue("Project already contains module with this name") while importing an existing android gradle project as a a new module.

Noting down How do I fixed it(may be helpful to you or somebody else).

Issue: When I import an existing android gradle project to my current android project, its shows "Project already contains module with this name". Yes, the "app" module is present in the current project the importing gradle project.

How to fix it:

  1. Go to New Module->Import Gradle project-> select the gradle project, if current project has "app" module then it says "Project already contains module with this name" enter image description here
  2. Check "import" and edit the module name "app" to "your-module-name" and finish. This will import the gradle project with new module name. enter image description here
  3. Go to the build.gradle of your newly imported module and update the "apply plugin" from,

    apply plugin: 'com.android.application'

    to

    apply plugin: 'com.android.library'

  4. Also, if the newly imported module's build.gradle has the "applicationId", then remove it.Your application ID shall be the main "app" module's application id. Library projects cannot set applicationId. Note: If you have used the applicationId(package name) to start an activity or bind service at the imported project, you have to update it with the the application package name.

  5. Go to the project structure, and import the module as a dependency. then clean project, rebuild. done.

like image 21
Rajesh P Avatar answered Oct 27 '22 00:10

Rajesh P