Colton Idle
12/20/2020, 4:08 AMbuildFeatures {
compose = true
}
composeOptions {
kotlinCompilerVersion '1.4.21'
kotlinCompilerExtensionVersion '1.0.0-alpha09'
}
kotlinOptions with useIR = true and jvmTarget set to 1.8
What else could be going wrong? I'm getting a crash at runtime. Everything in the IDE (latest canary) looks fine.
Gist: Latest everything. No compile issues. Runtime issue when just hitting setContent
and nothing else.
Edit: Only other thing I can think of is that I use some dependency that is forcing an older version of kotlin? I tried to use ./gradlew dependencies to figure out, but everything looks like its 1.4.21
Another edit: There literally has to be a better way to get a better error message. Literally have no idea whats going on 😭 I already have been able to get compose working in past projects. I quadruple checked that I followed these steps correctly https://developer.android.com/jetpack/compose/setup#add-compose (except that I'm using kotlin 1.4.21, alpha09 of compose, and Canary 3 of AS. Could really use any bump in the right direction. Thanks!Javier
12/20/2020, 9:06 AMsetContent
, I think it is in the ui
artifactjim
12/20/2020, 9:33 AMjavap -v
) for the class containing your setContent
call and paste it here, that might help to narrow down . Specifically, I would be looking for the bytecode signature of the setContent
call as invoked in your bytecode. Also, use reflection at runtime (where your setContent call would have been) to print the info (method names, method parameter types, method return values) about all methods on your WrapperKt
class. You may spot the problem while doing this, or at the very least it will help point us in the right direction.Colton Idle
12/20/2020, 3:42 PMjavap -v rt-app/build/tmp/kotlin-classes/bigideasStandardDebug/com/rollertoaster/app/userfacing/MainActivity.class
and the above is the result. ^^^
I'm going to try to run the command on an app that I have working with compose and see if I find anything.WrapperKt::class.declaredMemberProperties
?
If so, then maybe that's part of my problem because writing out WrapperKt::class underlines WrapperKt as unresolved reference.
If I do a search in android studio in "All Places" for WrapperKt I get two hits.
WrapperKt.class in
/Users/coltonidle/.gradle/caches/transforms-3/6aecffe2d086391121cf64b1fda3073c/transformed/jetified-ui-1.0.0-alpha09/jars/classes.jar!/androidx/compose/ui/platform/WrapperKt.class
and Wrapper.kt in
/Users/coltonidle/.gradle/caches/modules-2/files-2.1/androidx.compose.ui/ui/1.0.0-alpha09/2dab184f5cebeb6dc4856de8f4c0dc63b02900b8/ui-1.0.0-alpha09-sources.jar!/androidx/compose/ui/platform/Wrapper.kt
jim
12/20/2020, 11:10 PMClass.forName("androidx.compose.ui.platform.WrapperKt")
to get the Java class object and grab the methods off that.Colton Idle
12/20/2020, 11:14 PMjim
12/20/2020, 11:28 PMsetContent$default
function in your bytecode is of type Function0
and the matching functions in the class require the third parameter to be of type Function2
- which at least explains the NoSuchMethodError
.
This means the problem is not a result of tree shaking. I think this means the transform is not running (due to either configuration issue or bug) on your MainActivity.kt
. Still digging, give me a couple minutes.Colton Idle
12/20/2020, 11:32 PMjim
12/20/2020, 11:39 PMMainActivity.kt
file:
fun foo() { bar() }
@Composable fun bar() {}
And then try to compile. If the plugin is installed, the compiler frontend should complain and give you an error when compiling foo()
and refuse to perform the build.Colton Idle
12/20/2020, 11:39 PMjim
12/20/2020, 11:42 PMColton Idle
12/20/2020, 11:43 PMjim
12/20/2020, 11:44 PMColton Idle
12/20/2020, 11:45 PMe: MyActivity.kt: (19, 5): Functions which invoke @Composable functions must be marked with the @Composable annotation
e: MyActivity.kt: (20, 5): @Composable invocations can only happen from the context of a @Composable function
Broken project... compiled fine. 🤯jim
12/20/2020, 11:52 PMjps -m
and then kill anything that looks like a Gradle daemon or a Kotlin daemon?Colton Idle
12/20/2020, 11:53 PMjim
12/20/2020, 11:53 PMjps -m
returns:
11685 GradleDaemon 6.8-rc-1
12138 KotlinCompileDaemon --daemon-runFilesPath /Users/jsproch/Library/Application Support/kotlin/daemon --daemon-autoshutdownIdleSeconds=7200 --daemon-compilerClasspath /Users/jsproch/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-compiler-embeddable/1.4.20/fc1d26586910b32d676480c75acd3e922e5e81fa/kotlin-compiler-embeddable-1.4.20.jar:/Users/jsproch/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.4.20/411fc46e908bfa9c034f52b0d31b2e1f61f06127/kotlin-reflect-1.4.20.jar:/Users/jsproch/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.4.20/9be77b243a362b745e365f286627b8724337009c/kotlin-stdlib-1.4.20.jar:/Users/jsproch/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/1.4.20/9793d2f6b262847a2d8127951c5786cf907cc7b1/kotlin-script-runtime-1.4.20.jar:/Users/jsproch/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-daemon-embeddable/1.4.20/a051291fb01bf2397759625626fec670cd57b3f0/kotlin-daemo
Then you would do a kill -9 11685
and kill -9 12138
Colton Idle
12/20/2020, 11:58 PMjim
12/20/2020, 11:58 PMColton Idle
12/20/2020, 11:59 PMjim
12/20/2020, 11:59 PMColton Idle
12/21/2020, 12:00 AMjim
12/21/2020, 12:00 AMColton Idle
12/21/2020, 12:01 AMjim
12/21/2020, 12:01 AM--no-daemon
flag wouldn't hurt./gradlew assembleRollerStandardBetaDebug --no-daemon
Colton Idle
12/21/2020, 12:01 AMjim
12/21/2020, 12:04 AM./gradlew assembleRollerStandardBetaDebug --no-daemon
to somewhat rapidly test your configuration now (better than needing to deploy to an emulator and run the code for each test).Colton Idle
12/21/2020, 12:09 AMjim
12/21/2020, 12:11 AMColton Idle
12/21/2020, 12:17 AM./gradlew assembleRollerStandardBetaDebug --no-daemon --no-build-cache
and it still compiled fine.dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-alpha03'
inside the dependencies block^^.
Well my team hasn't used that dependencies block in root level build.gradle in like 2 years because we've been using buildSrc.
In buildSrc dir we have a dependencies block and that dependencies block houses the agp plugin.
For more info on how this looks like in practice see "Step 1: Setting up your project specific Gradle Plugin"
https://quickbirdstudios.com/blog/gradle-kotlin-buildsrc-plugin-android/
dependencies {
/* Example Dependency */
/* Depend on the android gradle plugin, since we want to access it in our plugin */
implementation("com.android.tools.build:gradle:3.5.0")
We've used essentially that method for 2 years and never had a problem, but it looks like in this case, compose compiler doesn't know?
You know what's funny, like 2 days ago when I was also banging my head against a wall I actually added
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-alpha03'
to my root build.gradle but even that does not fix it.
To fix my issue I need to add
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0-alpha03'
and remove the
dependencies {
implementation("com.android.tools.build:gradle:7.0.0-alpha03")
in my buildSrc build.grade.kts
The only issue that exists is that I have other plugins in buildSrc that actually require
dependencies {
implementation("com.android.tools.build:gradle:7.0.0-alpha03")
to be defined.
So yeah, I'm basically in a weird situation. I wonder if there's like a classpath type thing that I can put in my buildSrc. SOmething like this
dependencies {
classpath("com.android.tools.build:gradle:7.0.0-alpha03")
that would satisfy everything. But yeah. Let me know if you have any pointers (gradle is very much something that requires a phd to understand it seems), but that seems to be the root issue. Phewimpl...
from buildSrc/build.gradle.kts I need a solution to somehow keep that impl, but also to add the classpath...
to root build.gradle and actually have it picked up. Let me know if you know of any gradle magic here. I've been reading a whole bunch of forum posts and SO posts but I also suck at gradle so maybe I'm missing something obvious.
Anyway. Im going to bed. Thank you so much for the help @jim One step closer to my team using compose.jim
12/21/2020, 5:47 PMColton Idle
12/21/2020, 5:48 PMjim
12/21/2020, 5:53 PMColton Idle
12/21/2020, 7:13 PM