Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does gradle store all compiled classes for an ANDROID project?

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.

like image 371
Akh Avatar asked Jan 06 '16 02:01

Akh


People also ask

Where are Android Studio classes stored?

You can find them in the build/intermediates/classes/debug/* directory. Save this answer.

Where is Gradle repository stored?

Gradle caches artifacts in USER_HOME/. gradle folder. The compiled scripts are usually in the . gradle folder in your project folder.

Where is the .Gradle file Android?

Located in the project/module directory of the project this Gradle script is where all the dependencies are defined and where the SDK versions are declared. This script has many functions in the project which include additional build types and override settings in the main/app manifest or top-level build.

Where are Gradle files?

gradle file is located inside your project folder under app/build. gradle. for eg: if your project name is MyApplication MyApplication/app/build. gradle.


2 Answers

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/...

like image 178
Akh Avatar answered Sep 27 '22 23:09

Akh


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!

like image 45
Tom Rutchik Avatar answered Sep 28 '22 00:09

Tom Rutchik