1

im still quite new to gradle. I decided to transfer some code i oft use into an subproject. This subproject is a pure java project, so im using only the apply plugin: 'java' there.

I can build this project and in the build folder is see a jar which contains the compiled classes after the gradle assemble command was invoked.

What really bugs me at the moment is, how can i use the classes in my Android project using Android Studio ?

I tried to use the compile project command:

compile project(':PureJavaSubProject')

And it compiles the Project as expected. But Android Studio is not able to see the artifacts created by the Project ?

I read a bit in the Gradle Docs about Artifacts management but the Doc is not clear for me.

Anyone can point me how i need to declare or setup the gradle build to make it work ?

Kitesurfer
  • 3,438
  • 2
  • 29
  • 47
  • Please be more specific about what you mean that Android Studio can't see the artifacts; please add your settings.gradle and build.gradle files to your question. Also, be aware that Android Studio currently has a limitation that all modules must live under the project's root folder; if your PureJavaSubProject is in an outside directory, you'll have problems. – Scott Barta Feb 11 '14 at 17:02

2 Answers2

0

Are you including the subproject from your root project in your settings.gradle?

include 'PureJavaSubProject'

I can't verify from Android Studio I'm afraid. There is also more doc on multi project builds here:

http://www.gradle.org/docs/current/userguide/multi_project_builds.html

Mark Pope
  • 11,244
  • 10
  • 49
  • 59
0

I had this same issue, and it turned out I had the directory structure for the Java subproject slightly wrong (I had copied it from another existing Eclipse project).

I had:

java-subproject/src/com/example/MyJavaClass.java

...when it should have been:

java-subproject/src/main/java/com/example/MyJavaClass.java

When I changed it to the correct structure, the main Android project then picked up the classes in the Java sub-project fine.

A fully working example of an Android Studio project with a pure Java sub-project can be see here on Github:

https://github.com/barbeau/JavaSubprojectDemo

Sean Barbeau
  • 11,496
  • 8
  • 58
  • 111