Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] R8 - Missing class io.ktor.client.network... #719

Open
Monabr opened this issue Oct 27, 2024 · 6 comments
Open

[Android] R8 - Missing class io.ktor.client.network... #719

Monabr opened this issue Oct 27, 2024 · 6 comments

Comments

@Monabr
Copy link

Monabr commented Oct 27, 2024

Ktorfit version

2.1.0

What happened and how can we reproduce this issue?

isDebuggable = false
isMinifyEnabled = true

And try to build release android project.

The build fails with big message:

Missing class io.ktor.client.network.sockets.SocketTimeoutException (referenced from: java.lang.Throwable io.ktor.client.engine.cio.ExceptionsKt.mapToKtor(java.lang.Throwable, io.ktor.client.request.HttpRequestData))
Missing class io.ktor.client.network.sockets.TimeoutExceptionsCommonKt (referenced from: java.lang.Object io.ktor.client.engine.cio.Endpoint.makeDedicatedRequest(io.ktor.client.request.HttpRequestData, kotlin.coroutines.CoroutineContext, kotlin.coroutines.Continuation))
Missing class io.ktor.client.plugins.HttpTimeout$HttpTimeoutCapabilityConfiguration (referenced from: kotlin.Pair io.ktor.client.engine.cio.Endpoint.retrieveTimeouts(io.ktor.client.request.HttpRequestData) and 1 other context)
Missing class io.ktor.client.plugins.HttpTimeout$Plugin (referenced from: kotlin.Pair io.ktor.client.engine.cio.Endpoint.retrieveTimeouts(io.ktor.client.request.HttpRequestData))
Missing class io.ktor.client.plugins.HttpTimeout (referenced from: kotlin.Pair io.ktor.client.engine.cio.Endpoint.retrieveTimeouts(io.ktor.client.request.HttpRequestData))
Missing class io.ktor.util.InternalAPI (referenced from: io.ktor.client.engine.cio.CIOEngineContainer and 1 other context)
Missing class io.ktor.util.KtorDsl (referenced from: io.ktor.client.plugins.json.JsonPlugin$Config)
Missing class io.ktor.utils.io.ByteReadChannelJVMKt (referenced from: java.lang.Object io.ktor.client.engine.cio.UtilsKt$withoutClosePropagation$2.invokeSuspend(java.lang.Object) and 3 other contexts)
Missing class io.ktor.utils.io.CoroutinesKt (referenced from: java.lang.Object io.ktor.client.engine.cio.UtilsKt$readResponse$2.invokeSuspend(java.lang.Object) and 9 other contexts)
Missing class io.ktor.utils.io.DelimitedKt (referenced from: java.lang.Object io.ktor.http.cio.MultipartKt$parseMultipart$1.invokeSuspend(java.lang.Object) and 1 other context)
Missing class io.ktor.utils.io.LookAheadSession (referenced from: void io.ktor.http.cio.MultipartKt$skipDelimiterOrEof$3.invoke(io.ktor.utils.io.LookAheadSession) and 5 other contexts)
Missing class io.ktor.utils.io.ReadSessionKt (referenced from: java.lang.Object io.ktor.http.cio.ChunkedTransferEncodingKt.encodeChunked(io.ktor.utils.io.ByteWriteChannel, io.ktor.utils.io.ByteReadChannel, kotlin.coroutines.Continuation))
Missing class io.ktor.utils.io.bits.Memory (referenced from: java.lang.Object io.ktor.http.cio.MultipartInput$fill$1.invokeSuspend(java.lang.Object) and 1 other context)
Missing class io.ktor.utils.io.core.Buffer$Companion (referenced from: java.lang.Object io.ktor.http.cio.ChunkedTransferEncodingKt.encodeChunked(io.ktor.utils.io.ByteWriteChannel, io.ktor.utils.io.ByteReadChannel, kotlin.coroutines.Continuation))
Missing class io.ktor.utils.io.core.Buffer (referenced from: java.lang.Object io.ktor.http.cio.ChunkedTransferEncodingKt.encodeChunked(io.ktor.utils.io.ByteWriteChannel, io.ktor.utils.io.ByteReadChannel, kotlin.coroutines.Continuation))
Missing class io.ktor.utils.io.core.ByteBuffersKt (referenced from: java.lang.Object io.ktor.network.sockets.DatagramSendChannel.trySend-JP2dKIU(io.ktor.network.sockets.Datagram) and 3 other contexts)
Missing class io.ktor.utils.io.core.BytePacketBuilder (referenced from: io.ktor.utils.io.core.BytePacketBuilder io.ktor.http.cio.MultipartKt$parsePreambleImpl$2.$output and 87 other contexts)
Missing class io.ktor.utils.io.core.ByteReadPacket$Companion (referenced from: void io.ktor.network.tls.TLSHandshake.<init>() and 1 other context)
Missing class io.ktor.utils.io.core.ByteReadPacket (referenced from: io.ktor.utils.io.core.ByteReadPacket io.ktor.http.cio.MultipartEvent$Epilogue.body and 83 other contexts)
Missing class io.ktor.utils.io.core.CloseableJVMKt (referenced from: java.lang.Object io.ktor.client.engine.cio.UtilsKt$readResponse$2.invokeSuspend(java.lang.Object) and 2 other contexts)
Missing class io.ktor.utils.io.core.Input (referenced from: io.ktor.utils.io.core.Input io.ktor.http.cio.CIOMultipartDataBase$partToData$3.$input and 22 other contexts)
Missing class io.ktor.utils.io.core.InputArraysKt (referenced from: java.util.List io.ktor.network.tls.ParserKt.readTLSCertificate(io.ktor.utils.io.core.ByteReadPacket) and 1 other context)
Missing class io.ktor.utils.io.core.InputPrimitivesKt (referenced from: io.ktor.network.tls.extensions.NamedCurve io.ktor.network.tls.ParserKt.readCurveParams(io.ktor.utils.io.core.ByteReadPacket) and 8 other contexts)
Missing class io.ktor.utils.io.core.Output (referenced from: java.lang.Object io.ktor.http.cio.MultipartKt$parsePreambleImpl$2.invokeSuspend(java.lang.Object) and 27 other contexts)
Missing class io.ktor.utils.io.core.OutputPrimitivesKt (referenced from: io.ktor.utils.io.core.ByteReadPacket io.ktor.network.tls.RenderKt.buildECCurvesExtension(java.util.List) and 10 other contexts)
Missing class io.ktor.utils.io.core.PreviewKt (referenced from: byte[] io.ktor.network.tls.Digest.doHash-impl(io.ktor.utils.io.core.BytePacketBuilder, java.lang.String) and 1 other context)
Missing class io.ktor.utils.io.core.internal.ChunkBuffer (referenced from: void io.ktor.http.cio.MultipartInput.<init>(java.nio.ByteBuffer, io.ktor.utils.io.ByteReadChannel))
Missing class io.ktor.utils.io.streams.InputKt (referenced from: io.ktor.utils.io.core.Input io.ktor.http.cio.CIOMultipartDataBase$withTempFile$lazyInput$1.invoke() and 1 other context)
Missing class java.lang.management.ManagementFactory (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0())
Missing class java.lang.management.RuntimeMXBean (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0())

What did you expect to happen?

Project builds successfully.

Is there anything else we need to know about?

I tried with

            implementation(libs.ktorfit.lib)
            implementation(libs.ktor.client.serialization)
            implementation(libs.ktor.client.content.negotiation)
            implementation(libs.ktor.serialization.kotlinx.json)

and

            implementation(libs.ktorfit.lib)
            implementation(libs.ktor.client.serialization)
            implementation(libs.ktor.client.content.negotiation)
            implementation(libs.ktor.serialization.kotlinx.json)
            implementation(libs.ktor.client.core) <------------------------- Added this            

and still getting this error.

@Monabr Monabr added the bug Something isn't working label Oct 27, 2024
@Monabr
Copy link
Author

Monabr commented Nov 8, 2024

@Foso Hello. Are there any updates? This is a blocking issue for me.

@Foso Foso removed the bug Something isn't working label Nov 10, 2024
@Foso
Copy link
Owner

Foso commented Nov 10, 2024

Hi @Monabr for me its look all missing classes are related to the Ktor Websockets plugin and not Ktorfit.

Try adding this to your proguard/R8 file:

-keep class io.ktor.client.network.sockets.** { ; }
-keep class io.ktor.client.plugins.
* { ; }
-keep class io.ktor.util.
* { ; }
-keep class io.ktor.utils.io.
* { ; }
-keep class java.lang.management.
* { *; }

@Monabr
Copy link
Author

Monabr commented Nov 10, 2024

Hi @Monabr for me its look all missing classes are related to the Ktor Websockets plugin and not Ktorfit.

Try adding this to your proguard/R8 file:

-keep class io.ktor.client.network.sockets.** { ; } -keep class io.ktor.client.plugins.* { ; } -keep class io.ktor.util.* { ; } -keep class io.ktor.utils.io.* { ; } -keep class java.lang.management.* { *; }

Hi @Foso. After I added this I still have errors.

Missing class io.ktor.client.network.sockets.SocketTimeoutException (referenced from: java.lang.Throwable io.ktor.client.engine.cio.ExceptionsKt.mapToKtor(java.lang.Throwable, io.ktor.client.request.HttpRequestData))
Missing class io.ktor.client.network.sockets.TimeoutExceptionsCommonKt (referenced from: java.lang.Object io.ktor.client.engine.cio.Endpoint.makeDedicatedRequest(io.ktor.client.request.HttpRequestData, kotlin.coroutines.CoroutineContext, kotlin.coroutines.Continuation))
Missing class io.ktor.client.plugins.HttpTimeout$HttpTimeoutCapabilityConfiguration (referenced from: kotlin.Pair io.ktor.client.engine.cio.Endpoint.retrieveTimeouts(io.ktor.client.request.HttpRequestData) and 1 other context)
Missing class io.ktor.client.plugins.HttpTimeout$Plugin (referenced from: kotlin.Pair io.ktor.client.engine.cio.Endpoint.retrieveTimeouts(io.ktor.client.request.HttpRequestData))
Missing class io.ktor.client.plugins.HttpTimeout (referenced from: kotlin.Pair io.ktor.client.engine.cio.Endpoint.retrieveTimeouts(io.ktor.client.request.HttpRequestData))
Missing class io.ktor.util.InternalAPI (referenced from: io.ktor.client.engine.cio.CIOEngineContainer and 1 other context)
Missing class io.ktor.util.KtorDsl (referenced from: io.ktor.client.plugins.json.JsonPlugin$Config)
Missing class io.ktor.utils.io.ByteReadChannelJVMKt (referenced from: java.lang.Object io.ktor.client.engine.cio.UtilsKt$withoutClosePropagation$2.invokeSuspend(java.lang.Object) and 3 other contexts)
Missing class io.ktor.utils.io.CoroutinesKt (referenced from: java.lang.Object io.ktor.client.engine.cio.UtilsKt$readResponse$2.invokeSuspend(java.lang.Object) and 9 other contexts)
Missing class io.ktor.utils.io.DelimitedKt (referenced from: java.lang.Object io.ktor.http.cio.MultipartKt$parseMultipart$1.invokeSuspend(java.lang.Object) and 1 other context)
Missing class io.ktor.utils.io.LookAheadSession (referenced from: void io.ktor.http.cio.MultipartKt$skipDelimiterOrEof$3.invoke(io.ktor.utils.io.LookAheadSession) and 5 other contexts)
Missing class io.ktor.utils.io.ReadSessionKt (referenced from: java.lang.Object io.ktor.http.cio.ChunkedTransferEncodingKt.encodeChunked(io.ktor.utils.io.ByteWriteChannel, io.ktor.utils.io.ByteReadChannel, kotlin.coroutines.Continuation))
Missing class io.ktor.utils.io.bits.Memory (referenced from: java.lang.Object io.ktor.http.cio.MultipartInput$fill$1.invokeSuspend(java.lang.Object) and 1 other context)
Missing class io.ktor.utils.io.core.Buffer$Companion (referenced from: java.lang.Object io.ktor.http.cio.ChunkedTransferEncodingKt.encodeChunked(io.ktor.utils.io.ByteWriteChannel, io.ktor.utils.io.ByteReadChannel, kotlin.coroutines.Continuation))
Missing class io.ktor.utils.io.core.Buffer (referenced from: java.lang.Object io.ktor.http.cio.ChunkedTransferEncodingKt.encodeChunked(io.ktor.utils.io.ByteWriteChannel, io.ktor.utils.io.ByteReadChannel, kotlin.coroutines.Continuation))
Missing class io.ktor.utils.io.core.ByteBuffersKt (referenced from: java.lang.Object io.ktor.network.sockets.DatagramSendChannel.trySend-JP2dKIU(io.ktor.network.sockets.Datagram) and 3 other contexts)
Missing class io.ktor.utils.io.core.BytePacketBuilder (referenced from: io.ktor.utils.io.core.BytePacketBuilder io.ktor.http.cio.MultipartKt$parsePreambleImpl$2.$output and 87 other contexts)
Missing class io.ktor.utils.io.core.ByteReadPacket$Companion (referenced from: void io.ktor.network.tls.TLSHandshake.<init>() and 1 other context)
Missing class io.ktor.utils.io.core.ByteReadPacket (referenced from: io.ktor.utils.io.core.ByteReadPacket io.ktor.http.cio.MultipartEvent$Epilogue.body and 83 other contexts)
Missing class io.ktor.utils.io.core.CloseableJVMKt (referenced from: java.lang.Object io.ktor.client.engine.cio.UtilsKt$readResponse$2.invokeSuspend(java.lang.Object) and 2 other contexts)
Missing class io.ktor.utils.io.core.Input (referenced from: io.ktor.utils.io.core.Input io.ktor.http.cio.CIOMultipartDataBase$partToData$3.$input and 22 other contexts)
Missing class io.ktor.utils.io.core.InputArraysKt (referenced from: java.util.List io.ktor.network.tls.ParserKt.readTLSCertificate(io.ktor.utils.io.core.ByteReadPacket) and 1 other context)
Missing class io.ktor.utils.io.core.InputPrimitivesKt (referenced from: io.ktor.network.tls.extensions.NamedCurve io.ktor.network.tls.ParserKt.readCurveParams(io.ktor.utils.io.core.ByteReadPacket) and 8 other contexts)
Missing class io.ktor.utils.io.core.Output (referenced from: java.lang.Object io.ktor.http.cio.MultipartKt$parsePreambleImpl$2.invokeSuspend(java.lang.Object) and 27 other contexts)
Missing class io.ktor.utils.io.core.OutputPrimitivesKt (referenced from: io.ktor.utils.io.core.ByteReadPacket io.ktor.network.tls.RenderKt.buildECCurvesExtension(java.util.List) and 10 other contexts)
Missing class io.ktor.utils.io.core.PreviewKt (referenced from: byte[] io.ktor.network.tls.Digest.doHash-impl(io.ktor.utils.io.core.BytePacketBuilder, java.lang.String) and 1 other context)
Missing class io.ktor.utils.io.core.internal.ChunkBuffer (referenced from: void io.ktor.http.cio.MultipartInput.<init>(java.nio.ByteBuffer, io.ktor.utils.io.ByteReadChannel))
Missing class io.ktor.utils.io.streams.InputKt (referenced from: io.ktor.utils.io.core.Input io.ktor.http.cio.CIOMultipartDataBase$withTempFile$lazyInput$1.invoke() and 1 other context)
Missing class java.lang.management.ManagementFactory (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0())
Missing class java.lang.management.RuntimeMXBean (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0())

@Monabr
Copy link
Author

Monabr commented Nov 10, 2024

@Foso
After switching from
de.jensklingenberg.ktorfit:ktorfit-lib

to
de.jensklingenberg.ktorfit:ktorfit-lib-light

the errors reduced to

Missing class io.ktor.util.KtorDsl (referenced from: io.ktor.client.plugins.json.JsonPlugin$Config)
Missing class io.ktor.utils.io.core.Input (referenced from: java.lang.Object io.ktor.client.plugins.json.JsonPlugin$Plugin$install$2.invokeSuspend(java.lang.Object) and 2 other contexts)
Missing class java.lang.management.ManagementFactory (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0())
Missing class java.lang.management.RuntimeMXBean (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0()) 

@Monabr
Copy link
Author

Monabr commented Nov 10, 2024

@Foso
After switching from
de.jensklingenberg.ktorfit:ktorfit-lib-light

to
de.jensklingenberg.ktorfit:ktorfit-lib-light-ktor-3.0.0

the errors reduced to

Missing class java.lang.management.ManagementFactory (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0())
Missing class java.lang.management.RuntimeMXBean (referenced from: boolean io.ktor.util.debug.IntellijIdeaDebugDetector.isDebuggerConnected_delegate$lambda$0())

I still have rule
-keep class java.lang.management.** { *; }

But it does not help

@IsaacSkevington
Copy link

IsaacSkevington commented Dec 11, 2024

@Monabr Have you tried

-dontwarn io.ktor.**

That worked for me with the same error

If there are still more errors, proguard should generate a file in app/build/outputs/mapping/<your_app_name>/missing_rules.txt with the rules you need to add to your proguard file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants