is it safe to migrate whole android project in kotlin at once? - android

We have one mobile project fully developed in native android using android sdk.
we want to migrate the code base to kotlin completely. So wanted to know what are
main things to keep in mind while migrating to Kotlin.

Before you convert your project from Java to Kotlin keep things in your mind.
Converting from Java to Kotlin will may cause your git track. Refer to avoid this problem
Android studio provide easy way to convert Java code into Kotlin in a automate way [Press Ctrl+Alt+Shift+K]. But it may arise some conflicts like "Some code in the rest of your project may require corrections after performing this conversion. Do you want to find such code and correct it too?". For example in your java file contains static variables. Because kotlin didn't support static. In this case you have to manually correct it. It took some time.
While developing you may maintain many branches. If you converted one file from Java to Kotlin will affect other branch.

I don't recommend to switch full code automatically to Kotlin.
The tool for converting to Kotlin is great but you have to review all code generated by the tool. Sometimes code generated are not really readable.
Java and Kotlin can be use together. You can convert files one by one. You have time to check and clean the converted code.

Related

Rewriting android java project in kotlin language

I have some concern regarding the creation of existing android project written in Java language to kotlin language:
Can I create it from scratch.
Can I use same package name with same keystore and play console account.
Can I use same firebase config file for using firebase services.
I am asking all this because when I was recreating the project in debug mode it say uninstall the previous version to continue.
Thanks.
1)Yes, but you don't need to. Kotlin code can call java code, and java code can call Kotlin code. So you can convert 1 file or 1 part of your app at a time.
2)Yes. In fact I'd suggest it, unless you want to lose all your old users. The play store doesn't care if the language changes.
3)Yes, none of those services care about the language the app is written in.
A brief answer to all of your questions is "yes, you can. Absolutely!".
And for the configurations and stuff, Android Studio itself can handle it for you. Also, if you have already had a project, so you just don't need to re-create it from scratch in order to use Kotlin. You can just use a feature that Kotlin already has, which is interoperability (in this case, with JVM libraries or frameworks). So you can call Kotlin code from Java (in your current project) without an issue.

How to convert Kotlin project to Kotlin Multiplatform Mobile after the project completion?

I have built a code in Android Studio with Kotlin. I initially haven't set it up as a Kotlin Multiplatform Mobile project and I would like to bring it now also on iOS. Is there a way to "convert" it to a Kotlin Multiplatform Mobile at this stage? Thanks
This is a multi-step process:
You'll need to adapt your build configuration - change build.gradle.kts to a KMM setup. Examples you can find at PeopleInSpace and KaMPKit repos
You have to make your Android code platform agnostic in order to share pieces with iOS
The changes you need to make depends on how many Android dependencies you have, how much platform-specific code you wrote and how much you want to share with iOS.
I wouldn't underestimate how big of a refactor this might need, as there are loads of platform-specific things that as an Android devs can overlook (JUnit, File, Dates are just a few examples, where we commonly used JVM libs)
I'd recommend starting small, creating a shared module with a KMM configuration, then step-by-step moving things to shared
Reach out if you have more questions
Checkout this detailed video that explains this process https://www.youtube.com/watch?v=X6ckI1JWjqo
You would need to switch using Kotlin native libraries for common shared code, so depending on that, you might have more or less work to do.
On top of that, you would need to use strategies around dependency injection, common view model layer etc.

Where is the code generated by #Compose located in an android project folder structure?

i'm studying jatpack Compose and trying to read some source code of it. Noticed the Compose annotation is critical in this framework so i want to read the code generated by it to check what is actually done within it. However i cant find where the code locate, and since it's a quit new stuff, nothing could be found through out the internet. Beg for your idea, thanks!
That is a big topic.
The #Composable annotation is not processed by an Annotation Processor that generates source code. Instead Google had built a Kotlin Compiler Plugin that processes the annotation and weaves its magic into the compiled code directly.
Leland Richardson is the engineer that works on this and has explained a lot of what happens behind the curtains. For example, start here:
http://intelligiblebabble.com/compose-from-first-principles/

Code injection for Android

I want to write an ORM for Android as my final project.
My first idea is to inject code for each get and set.
Unfortunately I found a lot of posts saying there is no way to inject code in Android.
On the other hand I found "Dexmaker" to generate code on runtime.
My question is: Is it possible to somehow inject code in Android (by "Dexmaker" or anything else)?
If not how to do it ?
I also thought about reflections but I am afraid that it will be to slow.
Thanks in advance.
Edit
Simon:
Yes by ORM I ment object relational mapping.
I want to create a general framework. How else I could do this than not by code injection ?
You can inject code using Dexmaker. The project site has a HelloWorldMaker example that generates a class and then loads it.
You may find the performance of runtime code generation to be unsatisfying however. Projects like Dagger have had better success metaprogramming with code generation.

Are there Android compatible alternatives to Property Utils?

Is there a handy-dandy equivalent to org.apache.commons.beanutils.PropertyUtils on Android?
I can't seem to use bean utils in my android app due to some dependencies on PropertyDescriptor,and IndexedPropertyDescriptor. So I'm wondering if there are any alternatives?
Basically all I want to do is use a method name as a string "someMethod" and feed that into setMethod(anObject, "someMethod", value), much like PropertyUtils does; but without having to resort to the nasties of reflection...
Or are my hands tied and I need to use Reflection?
There is bridge library which works on Android: android-java-air-bridge.jar. Just include into project path and use all apache beanutils features in your Android project as you could use in ordinary java application. Moreover, there are lot of other classes which moved to this Android supporting library. Look at the list.
There is a possibilty to use libraries or write own code depending on the PropertyUtils. But it sure isn't dandy. You can get the general idea about what has to be done in this thread.
There are apparently some projects who have successfully solved the issue, so you can study thier solution. Take a look at Drawingpad-base and libgdx. You can find PropertyUtils in the package com.madrobot.beans in the first project and com.badlogic.gdx.beans in the second.

Categories

Resources