2

I have an aar package, I unzipped it, unzipped the classes.jar file as well, and now have a bunch of .kt and .class files a few of which I would like to edit. But all I see is class and method declaration with their body containing /* compiled code */. Where do I find the Kotlin code so I can edit it like we used to in Java class files?

Now this is my first time handling kotlin and frankly i don't even know the language. I am using android studio to open the files, and i know how to generate a read-only decompiled java version to understand the inner workings. That's how i figured out which file i need to edit.

I have also found some answers on stack that mention how converting kotlin to java and back to kotlin after editing is not a good idea, since the java file is not a perfect decompilation.

Here is the file I want to edit as it appears in AS:

// IntelliJ API Decompiler stub source generated from a class file
// Implementation of methods is not available

package ru.aviasales.screen.results.view

public final class ResultItemView public constructor(context: android.content.Context, attributeSet: android.util.AttributeSet) : ru.aviasales.ui.views.CardView {
    private final val segmentViews: kotlin.collections.MutableList<ru.aviasales.screen.results.view.ResultSegmentItemView> /* compiled code */

    public final fun onFavouritesButtonClicked(onClick: () -> kotlin.Unit): kotlin.Unit { /* compiled code */ }

    protected open fun onFinishInflate(): kotlin.Unit { /* compiled code */ }

    public final fun setData(viewModel: ru.aviasales.screen.results.viewmodel.ResultItem.TicketViewModel): kotlin.Unit { /* compiled code */ }

    private final fun setUpAvailableSeatsCount(seatsCount: kotlin.Int, type: ru.aviasales.screen.results.viewmodel.ResultViewType): kotlin.Unit { /* compiled code */ }

    private final fun setUpFavouritesButton(favoritesEnabled: kotlin.Boolean, addedToFavourites: kotlin.Boolean): kotlin.Unit { /* compiled code */ }

    private final fun setUpPrice(price: kotlin.Long, passengersCount: kotlin.Int): kotlin.Unit { /* compiled code */ }

    private final fun setUpSegments(segments: kotlin.collections.List<ru.aviasales.screen.results.viewmodel.SegmentViewModel>): kotlin.Unit { /* compiled code */ }
}

Is it even possible to edit these type of files ? if yes then Do i need a different editor or is there a different method to open such files ?

  • Maybe [this](https://stackoverflow.com/questions/35538049/kotlin-bytecode-how-to-analyze-in-intellij-idea) is what you need... – Leone Bacciu Sep 07 '19 at 13:45
  • @LeoneBacciu Thanks for the response, but I want to know how to edit the kotlin code. The java decompiled version is read-only. I already mentioned in the question. – Deepon Ghose Roy Sep 07 '19 at 15:07

1 Answers1

0

The simple answer after trying everything I could, is that you can't.

Luckily I was able to circumvent the issue, by creating a new activity. The aar package had its own MainActivity activity which was also kotlin class file. I decompiled the .class file, copy pasted the java code into my new activity and use then call the new activity from application file (since the MainActivity was being called automatically at start). I also faced the problem of some variables not initialising properly because of lateinit. I solved that by simply copying the variables through application from MainActivity using registerActivityLifecycleCallback and then calling my activity.