Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 562 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Android: How to call ndk function from Kotlin?

#1
This code works on Java. But after migration to Kotlin, compiler higlits method `native fun stringFromNative(): String` as error with following text:

> Function without a body must be abstract

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

Toast.makeText(this, stringFromNative(), Toast.LENGTH_LONG).show()
}

companion object {

init {
System.loadLibrary("_ndkkt")
}
native fun stringFromNative(): String
}
}


Thanks @KenVanHoeylandt!

Andswer is:

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

Toast.makeText(this, stringFromNative(), Toast.LENGTH_LONG).show()
}

init {
System.loadLibrary("_ndkkt")
}

external fun getStringFromNative(): String
}

}

If you wish to use this native function in another class you can specify the class which encloses it as in:

val aStringFromNative : String = MainActivity().getStringFromNative()
Reply

#2
Put `external fun stringFromNative(): String` outside of the companion object and into the `MainActivity`.

(I found the answer by looking at

[To see links please register here]

)
Reply

#3
Kotlin :

call method from ndk file
external fun stringFromJNI(): String


load c++ file
companion object {
init {
System.loadLibrary("native-lib")
}
}
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through