How to use AS stable with Compose: <https://marcel...
# compose
c
How to use AS stable with Compose: https://marcellogalhardo.dev/posts/2021/03/30/using-compose-beta-on-as-4-1/ I haven't tried it yet, but it would be nice to get a blessing/official documentation on how to do this. A lot of people I've spoken too have said that they want to adopt compose, but don't want to force canary or AGP 7 if they don't have to.
j
There's a much easier way to add compiler deps. One sec
Copy code
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginKt

dependencies {
  add(KotlinPluginKt.PLUGIN_CLASSPATH_CONFIGURATION_NAME, deps.composeCompiler)
}
Fuck you Slack client fixed best I could edited on desktop. Slack sucks.
πŸ€— 2
πŸ˜„ 2
c
For real though. Why can't slack just let me add my own markdown instead of trying to guess and fail. Thanks for the tip on the compiler deps. Does seem easier.
j
You'll never see this endorsed by Google. It's more headaches for them with no real gain. But just do it! I've been doing it for months!
c
Kinda insane. I've been dealing with AGP 7 issues for months and now I get to just get around that. Suhweeet.
Wish goog had a better story for how to adopt compose without needing canary. Just seems backwards that you want to use a beta framework but you now have to be on bleeding edge canary.
j
Yeah it's just laziness. And I don't mean that in an insulting way. It's just not something worth optimizing for today and there are 1000 more important things to be working on. So it makes total sense to require latest because they can always fix/change things in breaking ways. But it's nice to be able to work around it if you accept the responsibility
πŸ‘ 2
m
Oh, that is a much better way to do it. I will give it a try and update the post accordingly. Thank you a lot @Colton Idle and @jw! πŸ™
j
@Marcello Galhardo do you have an example project using this......getting tripped up here for some reason while updating project that had been based on Canary
I'm probably missing something basic but getting
Unresolved reference: KotlinPluginKt
(after adding that import)
m
@John O'Reilly not open source. 😞 However, I do use it in my current work without issues (we have an internal version of our Design System rewritten in Compose).
c
@John O'Reilly I had the same thing, but make sure you add the dependencies block outside of the Android block for the top snippet.
πŸ‘ 1
Besides that, the only thing I had to remove from my existing impl was the composeOptions block from inside the Android block and remove the compose true build feature. I already had the kotlin options and compile options block.
j
Yeah, have that outside....should this be part of main dependencies block.....seemed from article that there were 2 dependencies blocks for some reason? I get same error in either case
πŸ€” 1
c
Do you use buildSrc by chance?
j
Yeah, I do
m
(I will update the article to make it clear that it should be put into the same dependencies block, sorry the inconvenience - however, this should not cause this problem, and my project also includes a very complex buildSrc).
My project uses buildSrc and so I had to include an additional line in there about kotlin Gradle plugin.
πŸ€” 1
I had to do that before even reading this article. That was a few weeks ago when I couldn't even get compose to work.
Just bringing it up that it might be the cause... Actually. Let me remove it and see if it still works.
j
This particular (Compose) project was working ok before albeit using Canary etc
c
Gotcha. False alarm then. Lol
Either way. Here's my diff from a working compose project, and then moving to this articles impl. Add import at the top of my app level build.gradle Def compose version at the top Add dependencies block at the top but below plugin declaration Remove compose true Remove composeOptions block Changed buildSrc AGP version from 7 to 4.1.3 Did a global search to make sure I'm on beta03 everywhere and kotlin 1.4.31 everywhere Works!
Sorry for writing everything out. Don't have slack on the machine and so I'm on mobile. Lol
j
thanks, will double check setup here again
c
Enjoyed your interview regarding KMM BTW. Looking forward to integrating it into my current project too.
πŸ‘ 1
j
fwiw I created new Compose project (using Canary), then opened it in AS 4.1.3 and made those changes and still seeing same issue for some reason....strange
I'm using
com.android.tools.build:gradle:4.1.3"
btw
c
What's the "issue"? Just that the import doesn't resolve? Does it still compile and run though?
j
no, it won't build
what version of gradle wrapper are you using....not sure if that's a factor?
c
Not on my machine at the moment... But 6.8.2 IIRC?
m
I'm currently using
com.android.tools.build:gradle:4.1.2
, gradle wrapper
6.8.3
, and Kotlin
1.4.31
. πŸ€”
Give some minutes, I will set up a small project and push it publicly with this set up.
πŸ‘ 2
j
got it to work here but for some reason I needed
Copy code
import org.jetbrains.kotlin.gradle.plugin.PLUGIN_CLASSPATH_CONFIGURATION_NAME
and then
Copy code
add(PLUGIN_CLASSPATH_CONFIGURATION_NAME, "androidx.compose.compiler:compiler:${Versions.compose}")
j
Yeah that sounds right for kts files
c
Oh. The guide is for groovy files. I haven't used kts yet so maybe that's the difference @John O'Reilly
m
LOL, I haven't used KTS... it did not even occurred me this would be the case. I will add this detail in the post too. πŸ˜…
c
Wish there was an automated converter. I haven't gone kts yet because I didn't think AS supported it all that well.
j
Just pushed update to https://github.com/joreilly/BikeShare to use this approach.....cool to have this option now!
πŸŽ‰ 3
m
I updated the article to include KTS mention - so other people don't face this problem. Thank you all. πŸ™ https://marcellogalhardo.dev/posts/2021/03/30/using-compose-beta-on-as-4-1/#gradle-kts-differences
πŸŽ‰ 2
πŸ‘ 3
πŸ‘πŸΌ 1
πŸ’― 3
m
Copy code
e: This version (1.0.0-alpha13) of the Compose Compiler requires Kotlin version 1.4.31 but you appear to be using Kotlin version 1.4.32 which is not known to be compatible.  Please fix your configuration (or `suppressKotlinVersionCompatibilityCheck` but don't say I didn't warn you!).
😞
does the above approach unable to use kotlin
1.4.32
? also, the jetpack compose compiler used was it really
(1.0.0-alpha13)
? or just yet not updated error message 😞
fixed by this approach
c
@miqbaldc that error message you got technically would have happened if you tried to enable compose the "normal" way on a kotlin 1.4.32 project anyway. https://kotlinlang.slack.com/archives/CJLTWPH7S/p1614610822307100?thread_ts=1614604384.295200&amp;cid=CJLTWPH7S Compose is seemingly strongly tied to the kotlin version and if you want to get around that and use a newer kotlin version, then you will have to opt into it.
πŸ‘ 2
βž• 1
m
Now unresolved references is occurred 😞 clean & invalidate solves the issue :)))
c
Where? Show code?