NativeScript / NativeScript/android
Kotlin issues (companion object)
Personne n'a encore pris cette issue.
- Langage dominant
- C++
- Étoiles
- 563
- Forks
- 144
- Merge moyen
- 10 h 46 min
- PR mergées (30 j)
- 14
Description
Environment
Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):
- CLI: 8.6.5
- Cross-platform modules: 8.6.2
- Android Runtime: 8.6.1 (also 8.7.0-alpha.1)
- iOS Runtime (if applicable): -
- Plugin(s): -
Describe the bug
I tried to do some basic stuff with Kotlin stuff inside a NativeScript app (as I have no experience with Kotlin development) and I am experiencing some issues with companion objects.
I added this Kotlin file to App_Resources/Android/src/main/java
// KotlinTest.kt
package com.example
class KotlinTest {
val hello = "Hello from Kotlin!" //working
@JvmField
val instanceTestField : Int = 1234 //working
companion object {
@JvmStatic
fun increment(num: Int): Int { //working
return num + 1
}
@JvmField
val message : String = "Hi!" //not working
const val VERSION = 9 //not working
}
}
And I am trying to access the values like this in the NativeScript app:
const testObject = new com.example.KotlinTest();
console.log(testObject.hello); //working
console.log(testObject.instanceTestField); //working
console.log(com.example.KotlinTest.increment(5)); //working
console.log(com.example.KotlinTest.message); //not working
console.log(com.example.KotlinTest.VERSION); //not working
As far as I can read here about @JvmField annotation and here about const modifier this is valid Kotlin so it also shold work in NativeScript, but I always get undefined for those elements.
To Reproduce
Start the demo app provided below and check the logs in console.
Expected behavior
JvmFields and const values inside companion objects should be accessible in NativeScript.
Sample project
ns-android-kotlin.zip
Additional context
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par l’exemple Kotlin situé dans App_Resources/Android/src/main/java et par le projet d’exemple ns-android-kotlin.zip associé. Exécutez l’application de démonstration et examinez la sortie de la console pour les champs du companion-object, en les comparant aux champs et à la méthode qui fonctionnent. C’est terminé lorsque les valeurs @JvmField et const sont accessibles depuis NativeScript comme prévu.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- android, kotlin
- Domaine
- mobile
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100