Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 297
Beyond4D Avatar asked May 22 '13 20:05

Beyond4D


People also ask

How do you exclude a class in build gradle?

Just specify the group , the module and the version , like you do for dependencies. If you just want to exclude one class for a dependency jar, take a look at the jar jar links tool and its Gradle plugin. It allows you to alter included jars, e.g. to change packages or remove classes.

How to exclude package Android Studio?

Open Project Structure ( Ctrl + Alt + Shift + S in Linux) → Modules → Sources tab. However, if you would like to exclude only one class, use the Gradle build file.

What is minify in Android?

minify is an Android tool that will decrease the size of your application when you go to build it. It's extremely useful as it means smaller apk files! It detects any code or libraries that aren't being used and ignores them from your final apk.

What is R8 in Android?

What is R8? R8 is an app shrinking tool that is used to reduce the size of your application. This tool present in Android Studio works with the rules of Proguard. R8 will convert your app's code into optimized Dalvik code.


2 Answers

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'         }      }   }  } 
like image 91
robotoaster Avatar answered Sep 20 '22 17:09

robotoaster


Works fine with Android Studio v3.0

apply plugin: 'com.android.application'  android {     defaultConfig {...}     buildTypes {...}     sourceSets {         main {             java {                 exclude 'com/example/full/package/path/MainActivity.java'             }         }     } } 
like image 45
Kirill Vashilo Avatar answered Sep 16 '22 17:09

Kirill Vashilo