Android Gradle Module Requirements

I had a problem creating an Android project using Gradle.

I have a project structure as follows:

root settings.gradle build.gradle - Project 1 (android studio "module") build.gradle - Project 2 (android studio "module") build.gradle 

If I select project 1 and compile it, it will work. If I select project 2 and compile it, it will also work.

Now I would like to have a dependency on project 2 on project 1, to reuse some of my logical applications.

Following the document, I am trying to add build.gradle to project 2

 dependencies { compile project(':Project1') } 

but that will not work.

My .gradle settings contain:

 include ':Project1', ':Project2' 
+1
source share
2 answers

You must apply the android-library plugin in your library project (project1):

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.+' } } apply plugin: 'android-library' android { compileSdkVersion 17 } 

Link to the Gradle documentation on creating library projects.

+1
source

If you want to reuse some of the logic from Project1, you must create the Project3-lib library project. Move your reusable code into this new project and let Project1 and Project2 depend on it.

Here's how you can do it:

settings.gradle

 include ':Project3-lib', ':Project1', ':Project2' 

In Project1 and Project2 you add your new lib project

 dependencies { compile project(':Project3-lib') } 

In the top level file gradle.build (so you do not need it in all project build files)

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5.6' } } 

In the new Project3-lib project, you should use the android-library plugin, not the Android plugin.

 apply plugin: 'android-library' 
0
source

Source: https://habr.com/ru/post/1484908/


All Articles