Android Studio: "new module & # 8594; import existing project" and "import module",

What I have:

Four independently working Android modules:

  • MyProjectMainModule , the main container application attached to MyProject

  • MyGradleModule , a library with all the necessary components built into the gradlew process.

  • MyPreGradleModule , a library with src/ , res/ , AndroidManifest.xml and pom.xml , without gradle wrapper

  • MyRawModule , a library with src/ , res/ , AndroidManifest.xml , without pom.xml (usually considered in Ant-based Eclipse projects)

What I would like to achieve:

To import all three modules (i.e. MyGradleModule , MyPreGradleModule , MyRawModule ) into MyProject as dependencies of MyProject . The full project structure should resemble the project structure below:

 MyProject |--MyProjectMainModule |--MyGradleModule |--MyPreGradleModule |--MyRawModule 

Question:

The implementation of all three modules ( MyGradleModule , MyPreGradleModule and MyRawModule ) has different structures. What are the best ways to import each module with minimal effort?

Could you approach one of the following Android Studio menu items with each module in your answer (if you use any):

  • File β†’ Import Module...
  • File β†’ New Module... β†’ Import Existing Project
  • File β†’ New Module... β†’ Android Library
+11
android module android-studio android-gradle project-structure
source share
6 answers

You can add three modules to the same project by creating the settings.gradle file in the MyProject / folder and adding modules to it:

 include ':MyGradleModule' include ':MyPreGradleModule' include ':MyRawModule' 

Then, for each module, configure build.gradle dependencies to reference other modules as needed. For example, add this to MyProjectMainModule so that it uses the output generated by MyGradleModule:

 dependencies { compile project(':MyGradleModule') } 

Finally, if your project has heterogeneous submodules, you can customize their structure using the 'sourceSets' closure. For example, your raw module will have a configuration similar to this:

 android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } androidTest.setRoot('tests') } } 

Check out this section of the plugin's Gradle manual to see what configuration options are available.

+22
source share

This worked for me:

  • Open a project in Android Studio
  • Download the library (using Git or a ZIP archive for unpacking)
  • Go to File> Import Module and import the library as a module
  • Go to File> Project Structure> Modules
  • Find the main module of the project, click on it. It should have several android libraries, such as: support-v4, etc.
  • Click on the greener β€œ+” button on the left> module dependency
  • Choose "your library"
+7
source share

enter image description here To add a module in Android Studio

  1. File>>New>>Import Module>>select module , click on finish

  2. Go to settings.gradle file and add the module name, as shown below, separated by commas, i.e. include ':app', ':payUMoneysdk'

  3. Now the module is added to the project, see the root folder of the application.

  4. Go to the project settings and click on the dependencies, click on the plus ( + ) symbol and select the module, click on ok .

  5. The following module is added to build.gradle with a name implementation project (': payUMoneysdk')

Here I share the image for your reference ... I added the PayUmoney and Mobilehelpsdk modules to my project, it works properly ..

+5
source share

If the above answers are not clear to you or you are not sure, follow these simple steps.

  1. Go to File> New> Import Module ...
  2. Select the source directory where your library or module is located.
  3. Indicate the name of the module or leave it by default, and then click "Finish", and your module will be successfully added.
0
source share

Adding a module to the Settings.Gradle file fixed the problem for me.

include ': application' include ': Other-Module-Folder'

0
source share

have you tried this https://developer.android.com/studio/projects/android-library .

You need to create a library module and convert the application module into a library module, and then add your library as a dependency. Check out Android ANT project for Android Studio

0
source share

All Articles