6

Migrating from eclipse to Android Studio. Here is AS's build dir structure

enter image description here

Question 1. Where does gradle put all the compiled .class files? Is it the projectRoot/build/intermediates/classes directory?

The purpose of this question is a Java class is generated at build time (eg: CustomBuildInfo.java) and needs to added to the complied dir so that other src files can use it and packaged correctly within APK.

Note:Previously in Eclipse this generated file use to reside inside projectRoot/gen/<package> directory.

Question 2. Whats the correct location for custom generated Java files? Is it build/generated/r/<buildType>/<package> ? (this is where R.java resides)

Note But this custom generated Java file CustomBuildInfo.java belongs to common source i.e., used by all build types and all flavors

Any help will be appreciated.

Akh
  • 5,961
  • 14
  • 53
  • 82

2 Answers2

14

To answer my own question when using GRADLE build system

  • Java Byte Code location (post-compilation) <projectroot>/build/intermediates/classes/<build-type>/....

  • assets
    <projectroot>/build/intermediates/assets/<build-type>/....

  • res <projectroot>/build/intermediates/res/merged/<build-type>/....

  • JNI libs (configurable) <projectroot>/build/intermediates/jniLibs/<build-type>/....

  • Manifests <projectroot>/build/intermediates/manifests/full/<build-type>/....

  • Java class generated from AIDL <projectroot>/build/generated/source/aidl/<build-type>/....

  • R.java <projectroot>/build/generated/source/r/<build-type>/....

  • BuildConfig.java <projectroot>/build/generated/source/buildConfig/<build-type>/....

  • Test reports HTML <projectroot>/build/reports/tests/<build-type>/index.html

  • APK output files <projectroot>/build/outputs/apk/...

  • Lint Results <projectroot>/build/outputs/...

  • Manifest Merger Report (if using multi-module build) <projectroot>/build/outputs/logs/...

  • Test Results <projectroot>/build/test-results/...

Akh
  • 5,961
  • 14
  • 53
  • 82
  • 1
    For me "../intermediates/classes" is not being generated for an Android project. Any idea what is missing? – Hussain Mansoor Nov 30 '18 at 07:51
  • 5
    Sometimes the intermediates classes are being generated at "../intermediates/javac/debug/compileDebugJavaWithJavac/classes" . What I'm not sure of is what causes it to be generated in the 'javac' vs 'classes' directory. There is also a corresponding release version of the 'javac' dir path. – Tom Rutchik Feb 23 '19 at 21:10
  • Why sometimes? Did you figured out how to make this more deterministic? 10q – Ewoks Apr 30 '19 at 07:03
  • Below link helps to know the classes folder path in runtime. https://stackoverflow.com/questions/36477988/get-compiled-class-output-directory-in-android-gradle-task – Shanker Jun 11 '19 at 13:23
  • I get that error too....how can i run my android code..? it shows that the app module is broke! – Prajwal Waingankar Aug 11 '19 at 00:49
2

Intermediate classes can sometimes be stored at "../build/intermediates/javac/debug/compileDebugJavaWithJavac/classes" for the debug build classes and at "../build/intermediates/javac/relese/compileReleaseJavaWithJavac/classes" for the release build classes. And sometimes they can be stored at "../build/debug" for debug classes and at "../build/release" for release build classes.

I'm not sure what causes them to be in one place or the other. If you look at the ".impl" file (which contains xml) for the module your interested in you will find an entry like this:

  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
    <output url="file://$MODULE_DIR$/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes" />

or an enty like this:

  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
    <output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />

That's what determines where the intermediate classes will be stored for the module. Why it's sometimes in the 'build/intermediate/classes' directory and sometimes in the 'build/intermediate/java' directory has me baffled. I've look for various reasons such as 1.) is it affected by the manisfest, 2.) manifest merging 3.) jdk version 4.) module type (application, android library, java library), 5.) use of instance run. In all my attempts to see what causes it to choice one or the other, I've not been able to determine how that decision is made. If someone knows what factor determines the directory scheme choice , please add the reason.

If you're like me and have a reason want to get access to the intermediate java classes produced, the easiest work around is to see which directory exist. You'll have one or the other, but not both!

Tom Rutchik
  • 1,183
  • 1
  • 12
  • 15
  • Did you find any deterministic solution to get intermediate java classes folder path ? – Shanker May 08 '19 at 12:10
  • 1
    I don't know what causes it to use one location or the other. What I did in my custom gradle plugin was to test for the existence of the directory. If it didn't exist, then it the other directory location was where you'll find them – Tom Rutchik May 11 '19 at 16:59