Why ".kt" extension is sometimes visible and sometimes not? - android

In on of my Android Studio Kotlin projects, sometimes .KT is shown and sometimes not, in the Project explorer, in the Activity folder.
What is the criteria used by Android Studio to show or hide the .KT extension ?
Thanks

If a kotlin file has exactly one outer class/object/interface as the name of the file, then Android studio just shows the name without extension.

This could happen if activity does not meet one or more of these points:
One activity file should contain only one class.
One activity file class name declaration must correspond to the good filename (filename must equals class name).
There are no top-level declarations (constants, variables).

Solution :
One activity file should contain only one class.
One activity file class name declaration must correspond to the good filename (filename must equals class name).

Related

How does Realm determine two files are the same RealmObject? (package changes)

What is the criteria Realm uses in android to tell two different files are the same RealmObject?
Is it just the class name or the whole package name?
More specifically.
Say that I have com.company.MyRealmObject.kt and I refactor it to com.company2.MyRealmObject.kt.
Say that I have com.company.MyRealmObject.kt in Gradle module :app and I move it to Say that I have com.company.MyRealmObject.ktin Gradle module:library_db`
Would those action make Realm consider that MyRealmObject before and after the change are different RealmObjects hence requiring a migration, or would they be considered the same RealmObjects regardless of package and file as they have the same simple class name?
Thank you.
From my experiments, as long as the name of the class is the same, Realm will consider it the same RealmObject.
The name of the package of file in the project is not relevant, it's all down to the name of the class.
This seems to be in line with this comment: https://github.com/realm/realm-java/issues/6403#issuecomment-454427296
Our proxy classes encode the package path as part of the final class
name, but moving classes should be fine since the simple name is the
same, so it should translate to the same simple name in the Realm
file.

Kotlin classes with underscores

Please explain me what is the purpose and meaning of classes like StringsKt__StringsKt (i.e. doubled class name with one or more underscores in between) and, similarly, StringsKt__StringsJVMKt?
Strings are not the only example, there are many others too. I see them when looking into the structure of the classes.dex file in my .apk.
screenshot here
I'm asking because I faced a situation where I had to explicitly state some of them in my proguard-rules. The app crashed without it.
It is a generated file. A file like that will be generated if there are several Kotlin files named with same JvmName.
Let's take Strings.kt and StringNumberConversions.kt as an example:
// StringNumberConversions.kt
#file:kotlin.jvm.JvmMultifileClass
#file:kotlin.jvm.JvmName("StringsKt")
...
// Strings.kt
#file:kotlin.jvm.JvmMultifileClass
#file:kotlin.jvm.JvmName("StringsKt")
...
Both of them have #file:kotlin.jvm.JvmName("StringsKt"), so StringsKt and StringsKt__StringNumberConversionsKt are generated to distinguish them.

AndroidStudio not recognizing .java file

For some unknown reason, android studio decided not to recognize the .java file. Any idea how to resolve this?
I've tried deleting the file and recreating it, but it still results in the same issue. When recreating the file, some error came up and the file is automatically recreated
public class SubmitDealAsyncTask extends AsyncTask<Void, Void, String> {
...
}
It turns out that there's a wrong file association entry which associate that particular filename as a JavaFX file.
Look in the Preferences > Editor > File Types under Java files, the name of SubmitDealAsyncTask.java file is there and all I needed to do is to remove it.
Check your java file name and Class name.
class SubmitAsyncTask {}
should be saved in "SubmitAsyncTask.java"
Go to Preferences > Editor > File Types > Java, and then under each of the listed file types (Yes, unfortunately you have to look through all of them), and scroll down at the bottom of the to see if there is an entry for you file, and then click on it and the click the - sign.
How did you include this file? I had problems just copying java classes in Android Studio, so maybe you might want to create a new java class and copy the content of the desired file into it. Then there should be no problem.
Try to copy all the code from this file and paste it inside your package(where you paint over you name with blue lines).
Android Studio will create new .java file for you there.
#root I created the class by right clicking on the package folder(com.example.tttt) in the project view and then new java class and naming it SubmitAsyncTask and then using the prototype you provided to create a dummy class and it worked for me as you can see below so if this doesn't solve it then you are missing something in the code its no longer an IDE problem :

Android Eclipse - package folder not "normal" in src folder

Someone please fix my title. This problem is so weird that I have no idea what to call it.
Here is what my src folder should, and usually does, look like in my Package Explorer view:
Here is what is looks like now:
I don't remember what I did to do this (Eclipse is the most buggy program I've ever used in my life). I think it might have happened when I was attempting to create a JAR file with my classes.
The problem with this is:
My app always crashes on startup.
I don't have error messages. I could write iynbiun in my classes and there would be no red underline. It will always let me run (therefore compile my classes) my app even with uncompilable code.
How can I make it go back to the way it was in the first image?
A little help for you.
Just create a new package named as com.mikeyaworski.calculator as it before(make sure same package name is inside gen folder).
Then drag the calculator folder from com.mikeyaworski to com.mikeyaworski.calculator.
I think after this step you just have to rename the package because after dragging of calculator folder the package should be renamed as com.mikeyaworski.calculator.calculator.
So just rename it as usual and delete the empty com.mikeyaworski package.
As my knowledge if our package name is com.mikeyaworski.abcd then all activities are saved inside com folder -> mikeyaworski folder -> abcd folder .
Sometimes due to some changes the package path destroys and all our android related classes becomes plane java files. So if we reconstruct the package path and put all java classes inside this it must be as before.

generate blank aidl file

This may sound stupid but for some reason I can't find anywhere on Eclipse that lets me generate blank .aidl files... Does anyone know how?
You could make a copy form this:
http://developer.android.com/guide/developing/tools/aidl.html
and than use something liek th ecode2code eclips eplugin to generate code from the template you have created..
There is no option (yet, I guess) to create a aidl file. You should just create a file (right click on the package -> new file ) and give it name with .aidl extension. Then in this file you should just add several lines:
The name of the package, for instance package com.test;
And just declare interface IYourName { }
So as you can do only several things with android interface, there is no need to make a separate template for this.

Categories

Resources