I am working on a project where the main codebase ...
# gradle
l
I am working on a project where the main codebase is in a library module (used by other modules and other projects). This module is multiplatform (currently JVM, Linux and JS). The JVM code uses Java 21-specific features and will not compile on Android. Now, I want to implement Android support, so I need to create a
commonJvm
module which the
jvm
and
android
modules can use, so I can break out the Android-specific code while keeping the majority in a single module. Now, the problem: This is not really an Android project, and the toplevel build is not using the Android plugin. So what I have done is to make all the android-specific code conditional on a configuration parameter. My question is, is this a good way to do it? Here is the code that does this: https://codeberg.org/loke/array/src/branch/jvm-android-split-new/array/build.gradle#L44 The key code looks like this:
Copy code
applyDefaultHierarchyTemplate { x ->
        x.group("common") { y ->
            y.group("commonJvm") { z ->
                z.withJvm()
                if (Boolean.parseBoolean(project.getProperty("kap.settings.androidEnabled"))) {
                    z.withAndroid()
                }
            }
        }
    }
e
wouldn't it make more sense to enable/disable the android target?
l
Maybe, but wouldn't that require me to have installed the android gradle plugin?
e
if it does, so does your proposed setup
l
Ah, perhaps I didn't explain my setup correctly. What I'm doing is having the Android project completely separate, and that project will then include the relevant submodules from the former project. As such, the main Android project will have
androidEnabled
set to true, while the project which I linked to will have it false.