Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

Android Studio Exclude Class from build?

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.

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'
        }
     }
  }
 }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...