How does Convert Java File to Kotlin File work? - android

I'm exploring Kotlin through Kotlin for Android Developers. One of the first steps is to use Convert Java File to Kotlin File to see how the Java and Kotlin files compare.
I'm curious how this feature works.
Is the tool creating an abstract syntax tree from the Java input then transpiling to Kotlin? Or is doing something much simpler?

The tool uses the IntelliJ IDEA PSI interface to parse and analyze the Java source code and then converts the resulting tree into Kotlin text. It's open-source just like everything else related to Kotlin; you can find the implementation here.

Related

Are there any Android NDK examples, on how to pass a file from Java to C++ using JNI?

I am not sure, if this is the right place to ask, but I am curious, if there are any Android NDK examples (apks), on how to read a file with Java and pass it over to C/ C++ using JNI.
Currently I am trying to read pdf or office files (e.g. docx) with C/ C++ and I am trying to understand the concept behind it.
Maybe there are some full apk examples or just some snippets, with which I could extend the hello-jni/ hello-jnicallback examples.
I already found the android ndk samples site https://github.com/android/ndk-samples, but there seems to be no example on how to simply read files.
Thank you for your help.

Android Java Project Converts to Kotlin in Android Studio

I want to convert my java project to Kotlin, there are more than 500 java files. How can I convert it into Kotlin easily?
I know that we can convert one by one java file to Kotlin, But there are many files.
Can I convert it at once?
You can definitely try. You just need to select a module or a folder in the Project navigator and select Code --> Convert Java file to Kotlin file:
You, though, need to keep in mind that the conversion is not perfect. For instance, Android Studio will have to guess whether a whole lot of properties are nullable or not. It will not get them all right... you will get a lot of crashes.
My suggestion would be to batch files in sensible chunks, so you can fix those Kotlinized files without getting swamped with errors.
Note: after converting a file to Kotlin you still will need to review it. A lot of things will be kept in Java for the sake of safety, but now that you have Kotlin you can use collection extensions, default constructor parameters, ...
Select your app folder and go to Code Convert Java File to Kotlin File
Then after you convert the file,it says kotlin not configured.Click the Configure text then select the type of module you want to apply kotlin and it comes with the latest kotlin version press ok
N.B After you convert the code,you must convert some parameters that the compiler found it as a warning or error message.
It's easy, android-studio will do most of the work for you. To convert the existing javacode into kotlin, simply select the src/main/java folder in the project and choose Code->“Convert Java File to Kotlin File”. Android studio will then try as best as it can to convert all your java-code to kotlin-code.

Hide a library source code

I am developing an android library and I want to hide it's code.
I am using other library, and for some of them, when trying to access their code with Android Studio, you only get the list of methods of the class and "/* compiled code*/" inside.
I am using pro-guard, but i can still access the source code of my library. Even if the methods and members names have been modified, the code is still readable and it is possible to read every hard coded strings.
How do I hide my code the same way those libraries do ?
Android Studio replaces the actual code with something like /* compiled code */ only if you don't have the actual source code for the library and the decompiler isn't activated. But it's trivial to either attach the source code or to install a decompiler.
You can display the bytecode of any class using javap. See Is it possible to view bytecode of Class file? for details.
Back to your original question: No, it's not possible to actually hide your code because the code is required to actually execute it. And if the code is there you can see the bytecode and decompile it. The best option you have is to obfuscate the code using Proguard which won't get you very far either regarding hiding your code. See How to avoid reverse engineering of an APK file? and Android ProGuard how to hide/obfuscate source code of exported library.

Can a serialized file created by a program be placed into an Android project and then be read there?

I'm a newbie to Android development and I was wondering if I could create a serialized file (or any file) by a non-Android program and then just move it into an Android project in Eclipse and read it there? Any help would be appreciated! Thanks!
As long as you've got the proper de-serialization code on the android side, yes. There shouldn't be any issue here.
See:
Java serialization - Android deserialization
For potential pitfalls.

C: How to parse XML in android?

I'm working to create a library for my app in C. I want to parse a XML file in my code.
So, how can i do it in C ?
I know its java implementation but how can i parse a XML in my C code ?
What are the libraries that can be used for the purpose ?
I suggest Expat, I've used with many projects and it is very simple to use and has extremely small overhead. Its code base is also quite stable.
Expat is an XML parser library written in C. It is a stream-oriented parser in which an application registers handlers for things the parser might find in the XML document (like start tags).
However with every other external project mentioned, you need to build it yourself.
you should use c library for parsing xmls. here are some famous library links.. you can check
http://www.jclark.com/xml/expat.html
http://www.xmlsoft.org/
http://tibleiz.net/asm-xml/benchmark.html
you can find many other library to parse xml. But if you have any lightweight parsing task then you can use
http://www.minixml.org/
I have used http://www.minixml.org/ so i suggest to use this. Minixml is quite simple and easy to understand and use.
So you can download whole code of minixml and cross compile it for Android using Android toolchain or android NDK. And now Link that library to your jni code and use its API in your c code.
Just refference for includeing 3rd party library in jni code see
How to link any library in ndk application

Categories

Resources