Upgrading Kotlin to 1.5.0 in Android project fails

After upgrading Kotlin from 1.4.32 to 1.5.0 the build fails.

I have no idea how to solve this. Googling the problem didn’t help, I found nothing. Do you have any idea how to solve this?


Caused by: java.util.NoSuchElementException: Collection is empty. at kotlin.collections.CollectionsKt___CollectionsKt.single(_Collections.kt:562) at org.jetbrains.kotlin.gradle.internal.KotlinDependenciesManagementKt.kotlinTestCapabilityForJvmSourceSet(KotlinDependenciesManagement.kt:283) at org.jetbrains.kotlin.gradle.internal.KotlinDependenciesManagementKt.access$kotlinTestCapabilityForJvmSourceSet(KotlinDependenciesManagement.kt:1) at org.jetbrains.kotlin.gradle.internal.KotlinDependenciesManagementKt$configureKotlinTestDependency$1$1$3.invoke(KotlinDependenciesManagement.kt:226) at org.jetbrains.kotlin.gradle.internal.KotlinDependenciesManagementKt$configureKotlinTestDependency$1$1$3.invoke(KotlinDependenciesManagement.kt:217) at org.jetbrains.kotlin.gradle.internal.KotlinDependenciesManagementKt$sam$org_gradle_api_Action$0.execute(KotlinDependenciesManagement.kt) at org.gradle.internal.ImmutableActionSet$SetWithFewActions.execute(ImmutableActionSet.java:285) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.runDependencyActions(DefaultConfiguration.java:469) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationResolvableDependencies.getDependencies(DefaultConfiguration.java:1666) at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationResolvableDependencies_Decorated.getDependencies(Unknown Source) at com.android.build.gradle.internal.dependency.VariantDependencies.getIncomingRuntimeDependencies(VariantDependencies.java:159) at com.android.build.gradle.tasks.AnalyzeDependenciesTask$CreationAction.configure(AnalyzeDependenciesTask.kt:188) at com.android.build.gradle.tasks.AnalyzeDependenciesTask$CreationAction.configure(AnalyzeDependenciesTask.kt:160) at com.android.build.gradle.internal.tasks.factory.TaskConfigurationActions.postRegisterHook(TaskFactoryUtils.kt:109) at com.android.build.gradle.internal.tasks.factory.TaskFactoryUtils.registerTask(TaskFactoryUtils.kt:44) at com.android.build.gradle.internal.tasks.factory.TaskFactoryImpl.register(TaskFactoryImpl.kt:45) ...

submitted by /u/brain_trapp
[link] [comments]

Continue Reading Upgrading Kotlin to 1.5.0 in Android project fails

kotlinx-datetime 0.2.0 Is Out

Today we’re exploring

kotlinx-datetime

0.2.0 — a new version of our multiplatform library for working with dates and times, which was released along with Kotlin 1.5.0. We published the very first version of the library last summer, and this is our next step on the path to a stable release.

We introduced

kotlinx-datetime

at the Kotlin 1.4 Online Event: you can check out this talk by Ilya Gorbunov to learn more about the design principles and features of the library. Should you have any questions about

kotlinx-datetime

, we’d recommend participating in the upcoming Kotlin 1.5 Online Event and pose them to the Kotlin team.

Register for the Event

Version 0.2.0 comes with a number of improvements:

  • kotlinx.serialization

    support

  • Normalization of
    DateTimePeriod

    components

  • Ability to parse
    Instant

    from a string with a UTC offset

Try it out! – just make sure you have Kotlin version 1.5.0 installed. Let’s take a closer look at the features!

Note that kotlinx-datetime 0.2.0 is still Experimental. The API can change at any time.

kotlinx.serialization

support

kotlinx-datetime

provides its own types for representing date and time: such as

Instant

,

LocalDate

, and

TimeZone

. With version 0.2.0, all of these types are now serializable, as they are supported by the

kotlinx.serialization

library. We provide the set of serializers in the

kotlinx.datetime.serializers

package, which you can find bundled in the library.

Most of the types now have the default serializer. The types that do are

Instant

,

LocalDate

,

LocalDateTime

,

DateTimePeriod

,

DatePeriod

,

TimeZone

, and

ZoneOffset

. They can be used as properties in your serializable classes without explicit annotations:

import kotlinx.datetime.LocalDate
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.encodeToString

@Serializable
class Person(val name: String, val birthDate: LocalDate)

fun main() {
    val harry = Person("Harry", LocalDate(1980, 7, 31))
    println(Json.encodeToString(harry))
    // {"name":"Harry","birthDate":"1980-07-31"}
}

The default serializer is based on an ISO 8601 string representation of a type and uses

toString()

/

parse()

to serialize and deserialize values.

Some of the types have alternative serializers to make it possible to use different serialization strategies that can be more efficient than the default in particular formats. For example,

LocalDate

can be serialized component by component using

LocalDateComponentSerializer

. In order to choose a serializer explicitly, use the regular

@Serializable(with = ...)

annotation. You can also defer this choice to run time using the contextual serializer.

import kotlinx.datetime.LocalDate
import kotlinx.datetime.serializers.LocalDateComponentSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.encodeToString

@Serializable
class Person(
    val name: String,
    @Serializable(with = LocalDateComponentSerializer::class)
    val birthDate: LocalDate
)

fun main() {
    val harry = Person("Harry", LocalDate(1980, 7, 31))
    println(Json.encodeToString(harry))
    // {"name":"Harry","birthday":{"year":1980,"month":7,"day":31}}
}

There are also types that do not have a serializer:

DayOfWeek

and

Month

are supported by

kotlinx.serialization

as plain enums.

Keep in mind that

kotlinx.serialization

is an optional dependency of

kotlinx-datetime

. To use the serialization features, add the

kotlinx-serialization-core

dependency to your project next to

kotlinx-datetime

.

Normalization of

DateTimePeriod

components

The

DateTimePeriod

class represents the period between 2 instants as a combination of various time unit types: years, months, days, hours, minutes, seconds, and nanoseconds. For each of those time unit types, the class has a corresponding property that receives a value from the constructor parameter, for example:

DateTimePeriod(months = 14, minutes = 90)

.

Previously, the components were independent and just held the values passed to the constructor. However, this could lead to cases in which two objects with different component values ​​were not equal but had the same ISO representation. Serializing one such value and then deserializing it back could result in a value different from the original.

In this version, we changed the internal representation of

DateTimePeriod

, adding a component normalization step to its constructor. The components are now internally normalized to a combination of nanoseconds, days, and months, which solves the initial issue and also makes the value returned by the component property getter easy to read even if it is large.

val period1 = DateTimePeriod(months = 14, minutes = 90)
val period2 = DateTimePeriod(years = 1, months = 2, hours = 1, minutes = 30)
println(period1 == period2)  // true
println(period1)             // P1Y2MT1H30M // ISO-8601
println(period2)             // P1Y2MT1H30M // ISO-8601
println(period1.years)       // 1
println(period1.months)      // 2
println(period1.days)        // 0
println(period1.hours)       // 1
println(period1.minutes)     // 30
println(period1.seconds)     // 0
println(period1.nanoseconds) // 0

Parsing

Instant

from a string with a UTC offset

The

Instant

class represents a moment of time. The library lets you parse it from a string with date and time representations that follow the ISO 8601 standard.

Before 0.2.0, we accepted only the format with the

Z

time zone designator at the end, as in

2021-01-02T03:02:01Z

for example, meaning that the time is specified in the UTC+0 offset. From now on, we support non-zero UTC offsets as well:

val instant1 = Instant.parse("2021-01-02T03:02:01Z")
val instant2 = Instant.parse("2021-01-02T06:02:01+03:00")
println(instant1) // 2021-01-02T03:02:01Z
println(instant2) // 2021-01-02T03:02:01Z

Give it a try

kotlinx-datetime

0.2.0 is available from Maven Central. To give it a try in your project:

  • Make sure you have Maven Central set as a repository.
repositories {
    mavenCentral()
}
  • Add
    kotlinx-datetime

    as a dependency (don’t forget to specify a source set if you’re working on a multiplatform project).

dependencies {
    implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.2.0")
}

To get detailed instructions on how to use the library, please refer to our README.

Share your feedback

The library is Experimental, and the API could still change. We are on the way to a stable release and could really use your feedback.

Try out

kotlinx-datetime

0.2.0 and share your experience with us! Report any issues you encounter to the project’s issue tracker and ask any questions you have in our Slack (you can get an invite here).

Continue Reading kotlinx-datetime 0.2.0 Is Out

Articles & News from Kt. Academy

Hello, Kt. Academy here 👋

In today’s newsletter you’ll find:
➡️ New article published on our blog!
➡️ Article private comment function.
➡️ New articles for our polish audience.
➡️ Places to buy the Effective Kotlin book.

Enjoy!

Data modifier is a powerful tool 💪
If you want to learn how it works as well as what are its perils and dangers, read the article written by Marcin Moskala 👇
Use the data modifier to represent a bundle of data.

We want our audience to have an impact on what we publish and so that you can share your thoughts or concerns, and be able to leave us any other feedback about our articles!

That’s why we’ve added the article private comment function to our blog 🥳

To leave us your comments click on a small chat icon on the right side 💬, write what you think and send it straight to us — exactly as shown in the video below 👇

To our Polish audience 🇵🇱

There are 2 new articles about JavaScript on our polish blog:
👉 Tablice w JavaScript
👉 Iteracja po tablicy w JavaScript

As always, you can leave us your comments or become our reviewer directly from the article page.

❗️Here’s a quick reminder that the Effective Kotlin book is still on sale❗️

✅ paper book available worldwide on Amazon
✅ ebook available on Amazon Kindle and LeanPub
✅ the polish versions — in paper and ebook — available on Helion 👉 now on sale! 🤩

Thanks and see you soon!

Kt. Academy Team

www: kt.academy
Blog: blog.kotlin-academy.com
Twitter EN: @KtDotAcademy
Twitter PL: @ktdotacademyPL
FB: @KtDotAcademy
LinkedIn: @Kt. Academy


Articles & News from Kt. Academy was originally published in Kt. Academy on Medium, where people are continuing the conversation by highlighting and responding to this story.

Continue Reading Articles & News from Kt. Academy

Kotlin 1.5 Online Event

The first major release of 2021 is here! Let’s celebrate the occasion together at the Kotlin 1.5 Online Event, where the team will answer your questions about the recent updates and anything else Kotlin-related.

Join us May 25 at 4:00 pm CEST. 

More information about the event, the Reddit AMA, how to post questions, and how to win a t-shirt can be found below. 

Register

What are we preparing for you?

After the last Kotlin event, we received lots of feedback saying that the Q&A sessions are the most interesting and useful. That is why this time we will mostly focus on answering your questions.

We will live stream the event on our YouTube channel. Two of our developer advocates – Svetlana Isakova and Sebastian Aigner – will host the show, opening it with highlights of what’s new in Kotlin 1.5.0 and speaking with Roman Elizarov about the future of Kotlin. Join in to listen to this and other interesting conversations!

How to participate in the event Q&A and the Reddit AMA

To make the most of the event, send your questions to the team in advance. You can do this while registering for the event, or you can post them on Twitter using our hashtag #kotlin15ask. A YouTube Live chat will be available as well. So even if you don’t have anything to ask now, you will still be able to post questions as they come to you during the stream.

We will try to cover all pre-posted and live questions. If there are any unanswered questions at the end of the event, we will go through them during the Ask Me Anything (AMA) session on May 27–28 on Reddit. The team will also answer new questions that are raised there. To receive notifications about the AMA, check the box in the registration form or join on the r/Kotlin subreddit.

Additional materials and raffle

Check out our release materials to learn more about Kotlin 1.5.0 and to get inspiration for your questions:

  1. The Kotlin 1.5.0 release blog post and what’s new page.
  2. The 1.5.0 Release playlist on YouTube, with a number of videos explaining the most significant updates in Kotlin 1.5.0. Subscribe to our channel, as more Kotlin 1.5.0 videos will be released soon.

We will give away 10 Kotlin t-shirts to participants who send their questions to us in advance. The winners will be announced during the event, and we will contact them individually to arrange the delivery of their prize. 

Take part in the Kotlin 1.5 Online Event and send in your questions for the Kotlin team! 

Register

Continue Reading Kotlin 1.5 Online Event

End of content

No more pages to load