android studio, how to exclude packages from build

1 day ago 4
ARTICLE AD BOX

Looks like this question was asked before many times, but I could not find any answer.

I want to use a part of my Java project as a module for Android app.

My settings.gradle include:

rootProject.name = "APref" include ':AndroidPref' include ':JPref' project(':JPref').projectDir = new File('..')

and it's working fine except that I see unwanted packages in apk file. I marked these packages as 'excluded' - no avail.

As somebody recommended, I put in build.gradle:

android { ... sourceSets { main { java { // Exclude entire package from build process exclude '**/com/ab/pref/**' } } } }

No difference at all.

This is my file structure and I want to remove jprefdoc and pref from Android build:

. ├── APref │   ├── AndroidPref │   │   └── src │   │   ├── main ...    │   └── test ... ├── src │   ├── main │   │   ├── java │   │   │   └── com │   │   │   └── ab │   │   │   ├── jpref ... │   │   │   ├── jprefdoc ... │   │   │   ├── pref ... │   │   │   └── util ... │   │   └── resources ... │   └── test │   └── java

I fact, I have no clue how this build has been made because these packages depend on javax.swing and others which is not present on Android at all.

Using Android Studio Otter 3 Feature Drop | 2025.2.3.

Read Entire Article