I’m trying to enable Compose only on one module of...
# compose
o
I’m trying to enable Compose only on one module of my application, but to do that I need to use the latest version of the Android Gradle plugin. I tried with this:
Copy code
buildscript {
    configurations.all {
        resolutionStrategy { force 'com.android.tools.build:gradle:4.2.0-alpha16' }
    }
}
but didn’t work 😞 Do you know a solution to enable Compose on a single module?
b
Your best bet (and what I’m doing) is to build the entire application with AGP 4.2, but only set
Copy code
android {
  buildFeatures {
    compose true
  }
}
on the one module you want to enable compose for
o
Yes, thanks, I know that works, but, for now, I could not change that. I want to create a sample app inside a bigger project to start to build some “Compose components” from existing “View components”.
b
Unfortunately I don’t believe you can set an AGP version for a single module within a project.
a
you can. Just set it inside its own build.gradle
o
It doesn’t work for a single classpath, probably I should duplicate the whole
buildscript {}
a
why don't you use settings.gradle to setup your plugins resolutions?
That way, you set it only once, and use it in all your gradle modules
j
If you have multiple modules, you can simply in the root build.gradle set the classpath:
Copy code
buildscript {
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.0-alpha16")
    }
}
Good old fashioned non-compose code should still work just fine with this. Then you can enable it per module by setting the build feature
o
Joost I can’t do that because the main app require the stable version of the Android Gradle plugin
a
Use settings.gradle. That is what I use
n
@andylamax could you show here an example to how force canary agp in some modules with plugin resolution
a
in root project directory, add settings.gradle.kts and add as shown here https://github.com/aSoft-Ltd/kotlinx-extensions/blob/master/settings.gradle.kts remember not to apply the agp to your root project 's build.gradle.kts, but apply it only on submodules you need, and add their respective versions there as shown here
Copy code
plugins {
    id("com.android.library") version "4.1.0"
    kotlin("andriid") version "1.4.10"
}
apply plugin: "com.android.library" // wont work
n
@andylamax I have tried but no success. if root project does not have plugin on class path (not in buildscript section and not plugin section with
apply false
) gradle sync will fail with an exception
java.lang.NoClassDefFoundError: com/android/build/gradle/BaseExtension
Adding AGP to root without applying it will fail as well, because you can specify version only once and it ends up with
Error resolving plugin [id: 'com.android.application', version: '4.1.1', artifact: 'com.android.tools.build:gradle:4.1.1']
, looks like I am stuck now =(