compose-samples icon indicating copy to clipboard operation
compose-samples copied to clipboard

[Bug]: project fails to load in Android Studio

Open gramound opened this issue 11 months ago • 9 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Is there a StackOverflow question about this issue?

  • [x] I have searched StackOverflow

Is this an issue related to one of the samples?

  • [x] Yes, this is a specific issue related to this samples repo.

Sample app

Jetcaster

What happened?

The project fails to load in Android Studio (latest stable release 2024.3.1):

Multiple build operations failed.
    Could not create task ':core:data:compileDebugAndroidTestJavaWithJavac'.
    Could not create task ':core:data-testing:compileDebugAndroidTestJavaWithJavac'.
    Could not create task ':core:designsystem:compileDebugAndroidTestJavaWithJavac'.
    Could not create task ':mobile:compileDebugAndroidTestJavaWithJavac'.
Could not create task ':core:data:compileDebugAndroidTestJavaWithJavac'.
Failed to calculate the value of task ':core:data:compileDebugAndroidTestJavaWithJavac' property 'javaCompiler'.
Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=17, vendor=any vendor, implementation=vendor-specific} for MAC_OS on aarch64.
No locally installed toolchains match and toolchain download repositories have not been configured.

I reported a similar issue with tv-samples JetStream back in October. https://github.com/android/tv-samples/issues/192 This works for me, (although not sure about the github actions yml)

git grep -l JDK | xargs sed -i 's/JDK 17/JDK 21/g'
git grep -l java-version | xargs sed -i 's/java-version: 17/java-version: 21/g'
git grep -l jvmToolchain | xargs sed -i 's/jvmToolchain(17)/jvmToolchain(21)/g'
git grep -l jvmTarget | xargs sed -i 's/jvmTarget = "17"/jvmTarget = "21"/g'
git grep -l JavaVersion | xargs sed -i 's/JavaVersion.VERSION_17/JavaVersion.VERSION_21/g'

I'm not doing a pull request, because I don't know enough about why this was hardcoded to java 17 in the first place. Maybe I'm missing something.

Relevant logcat output


Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

gramound avatar Mar 07 '25 17:03 gramound

Did you try re-cloning the project? I've just clone and the project built

JamesDownes5 avatar Mar 09 '25 18:03 JamesDownes5

Re-cloning didn't help for me unfortunately.

Did you install your own java 17? I thought Android Studio used its own from:

% /Applications/Android\ Studio.app/Contents/jbr/Contents/Home/bin/javac -version
javac 21.0.5

gramound avatar Mar 10 '25 04:03 gramound

Have you tried opening each project alone and not the entire project file?

kevinhui98 avatar Mar 18 '25 18:03 kevinhui98

I have the same issue.

kaamel avatar Apr 08 '25 05:04 kaamel

Have you tried opening each project alone and not the entire project file?

Yes, that is what I do. I clone the repo outside of Android Studio and open each project alone in a new window.

  • Jetcaster: fails with "Cannot find a Java installation on your machine matching this tasks requirements: {languageVersion=17, vendor=any vendor, implementation=vendor-specific} for MAC_OS on aarch64."
  • Jetchat: works
  • JetLagged: works
  • JetNews: works
  • Jetsnack: works
  • Reply: works

gramound avatar Apr 08 '25 16:04 gramound

I think I figured it out by comparing with other projects:

In core:data, core:data-testing, core:designsystem and mobile

Replace this (in build.gradle.kts):

kotlin {
    jvmToolchain(17)
}

By this (inside the android { ... } section):

    kotlinOptions {
        jvmTarget = "17"
    }

gramound avatar Apr 08 '25 16:04 gramound

Seems related to #1526

gramound avatar Apr 08 '25 17:04 gramound

replace kotlin { jvmToolchain(17) } with kotlinOptions { jvmTarget = "17" } in build.gradle.kts files. it worked,ths

luciferChou avatar Apr 23 '25 03:04 luciferChou

I was using the old version of Android Studio so it did not work, installed the latest version and it started working

Sarthak7Gautam avatar May 21 '25 07:05 Sarthak7Gautam

Closing this issue based on the recently merged improvement. Please re-open if there's still problems!

JolandaVerhoef avatar Jul 03 '25 14:07 JolandaVerhoef