Android Studio Exclude Class from build?

Beyond4D picture Beyond4D · May 22, 2013 · Viewed 54.2k times · Source

I've been learning Android over the past few months and have been using Eclipse Juno as my IDE.

I am trying to migrate to Android-Studio and wonder how I can "exclude from build path" some of the classes I have yet to complete?

In Eclipse, it was straight forward right click. I can't find any reference to it in Studio.

Answer

robotoaster picture robotoaster · May 23, 2013

AFAIK IntelliJ allows to exclude packages. Open Project Structure (Ctr+Alt+Shift+S in Linux) > Modules > Sources Tab.

However if you would like to exclude only one class use Gradle build file.

Android Studio uses Gradle so in build.gradle file add inside android configuration custom SourceSet that excludes your class e.g:

android {
  compileSdkVersion 19
  buildToolsVersion "19.0.3"

  defaultConfig {
     minSdkVersion 19
     targetSdkVersion 19
     packageName "org.homelab.lab"
     testPackageName "org.homelab.lab.test"

  }
  sourceSets {
     main {
         java {
             exclude '**/SomeExcludedClass.java'
         }
     }
     androidTest {
         java {
             exclude '**/TestSomeExcludedClass.java'
        }
     }
  }
 }