I have a simple library for sum of two numbers written in Pascal. In this library I define function test_sum which I want to use in my kotlin code for android application. I then builded this library into .so file for android using delphi 10.4.
library:
library mylib;
uses
SysUtils,
IniFiles,
Classes,
SyncObjs
{$IFDEF Windows}
,Windows
{$ENDIF}
;
{$R *.res}
function test_sum(X: Integer; Y: Integer): Integer; stdcall;
begin
Result:=X+Y;
end;
Exports test_sum;
begin
end.
Based on question in link 1 and its best answer i created folder C:\Users\x\AndroidStudioProjects\testcomm\app\src\main\jniLibs with four subfolders in which I copied created .so file.
I then used "external" keyword for declaring function. After running this app I get error "No implementation found for int com.example.testcomm.MainActivity.test_sum(int, int)" which is unfortunatelly expected.
code in kotlin:
package com.example.testcomm
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
test_sum(1,1)
}
external fun test_sum(a : Int, b : Int) : Int
}
I suspect that i miss some import or link which would say where to look for the function but even after searching for a lot of time I was not able to manage to successfully use test_sum function in my kotlin code. Is it possible? If so please guide me how to achieve it.