android / compose-samples

Official Jetpack Compose samples.
https://developer.android.com/jetpack/compose
Apache License 2.0
20.18k stars 4.8k forks source link

[Bug]: Unresolved reference: libs #1147

Closed theGeekyLad closed 11 months ago

theGeekyLad commented 1 year ago

Is there an existing issue for this?

Is there a StackOverflow question about this issue?

Is this an issue related to one of the samples?

Sample app

Other (bug not related to sample app)

What happened?

I get the Unresolved reference: libs error while trying to perform a Gradle build. Looks like a bunch of libs. ... are used within the build.gradle.kts file but I don't see the definition of these libs variables.

Any thoughts?

Relevant logcat output

No response

Code of Conduct

bentrengrove commented 1 year ago

libs is the gradle version catalog generated by gradle. What version of Android Studio are you using and how are you trying to build the samples? I can't reproduce any issues, the project seems to build fine.

DavidFaermanPendo commented 1 year ago

i get Build file '.../compose-samples/JetNews/app/build.gradle.kts' line: 17

Error resolving plugin [id: 'com.android.application', version: '8.0.2']

The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.

zeeshanali-k commented 1 year ago

Make sure that gradle 8.1 is downloaded and file named "libs.versions.toml" exists under module level gradle folder of JetNews project

joyceHong0524 commented 1 year ago

I set android gradle plugin version 8.0.2 gradle version 8.1

still getting an error like this

org.gradle.api.GradleException: Error resolving plugin [id: 'com.android.application', version: '8.0.2']

joyceHong0524 commented 1 year ago

So this is how I fixed the issue,

  1. libs.versions.toml change androidGradlePlugin, android-application like this. [versions] androidGradlePlugin = "8.0.2" [plugins] android-application = { id = "com.android.application", version = "8.0.2" }

  2. At Project build.gradle.kts, add these lines in plugins {}

plugins { alias(libs.plugins.gradle.versions) alias(libs.plugins.version.catalog.update) // these lines.. alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kapt) apply false alias(libs.plugins.hilt) apply false alias(libs.plugins.secrets) apply false alias(libs.plugins.android.application) apply false alias(libs.plugins.android.test) apply false }

and it started to work.

stale[bot] commented 11 months ago

This issue has been automatically marked as stale because it has not had any recent activity. Please comment here if it is still valid so that we can reprioritize it. Thank you for your contributions.

octoberv29 commented 7 months ago

a simpler way to solve it for me was:

  1. create a new Kotlin Multiplatform project in Android Studio
  2. copy the libs.versions.toml file over to your project
  3. copy the build.gradle.kts (project level) over to your project or just copy the libs you need to add