You've already forked lazarus-ccr
Improvements to the JNI Test
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2165 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project name="AndroidLCLTest" default="help">
|
<project name="AndroidJNITest" default="help">
|
||||||
|
|
||||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||||
It contains the path to the SDK. It should *NOT* be checked into
|
It contains the path to the SDK. It should *NOT* be checked into
|
||||||
|
88
bindings/android-ndk/examples/jnitest/jni/nativetest.lpi
Normal file
88
bindings/android-ndk/examples/jnitest/jni/nativetest.lpi
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
|
<General>
|
||||||
|
<Flags>
|
||||||
|
<MainUnitHasCreateFormStatements Value="False"/>
|
||||||
|
<MainUnitHasTitleStatement Value="False"/>
|
||||||
|
</Flags>
|
||||||
|
<SessionStorage Value="InProjectDir"/>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<UseAppBundle Value="False"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
</General>
|
||||||
|
<i18n>
|
||||||
|
<EnableI18N LFM="False"/>
|
||||||
|
</i18n>
|
||||||
|
<VersionInfo>
|
||||||
|
<StringTable ProductVersion=""/>
|
||||||
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
|
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<Units Count="1">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="nativetest.pas"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="nativetest"/>
|
||||||
|
</Unit0>
|
||||||
|
</Units>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="11"/>
|
||||||
|
<Target>
|
||||||
|
<Filename Value="../libs/armeabi/libnativetest.so"/>
|
||||||
|
</Target>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
<Libraries Value="/home/felipe/Programas/android-ndk-r5/platforms/android-9/arch-arm/usr/lib/;/home/felipe/Programas/android-ndk-r5/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/lib/gcc/arm-eabi/4.4.0/"/>
|
||||||
|
<OtherUnitFiles Value="../../.."/>
|
||||||
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<CodeGeneration>
|
||||||
|
<RelocatableUnit Value="True"/>
|
||||||
|
<TargetCPU Value="arm"/>
|
||||||
|
<TargetOS Value="linux"/>
|
||||||
|
</CodeGeneration>
|
||||||
|
<Linking>
|
||||||
|
<Debugging>
|
||||||
|
<GenerateDebugInfo Value="False"/>
|
||||||
|
<UseLineInfoUnit Value="False"/>
|
||||||
|
</Debugging>
|
||||||
|
<Options>
|
||||||
|
<ExecutableType Value="Library"/>
|
||||||
|
</Options>
|
||||||
|
</Linking>
|
||||||
|
<Other>
|
||||||
|
<CompilerMessages>
|
||||||
|
<UseMsgFile Value="True"/>
|
||||||
|
</CompilerMessages>
|
||||||
|
<CustomOptions Value="-Xd"/>
|
||||||
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
@ -1,7 +1,6 @@
|
|||||||
library nativetest;
|
library nativetest;
|
||||||
{$ifdef fpc}
|
|
||||||
{$mode delphi}
|
{$mode delphi}
|
||||||
{$endif}
|
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils,
|
SysUtils,
|
||||||
@ -11,14 +10,14 @@ uses
|
|||||||
const curClass:JClass=nil;
|
const curClass:JClass=nil;
|
||||||
nativeCodeLoaded:JfieldID=nil;
|
nativeCodeLoaded:JfieldID=nil;
|
||||||
|
|
||||||
function Java_com_bero_nativetest_Main_stringFromJNI(env:PJNIEnv;this:jobject):jstring;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
|
function Java_com_bero_nativetest_Main_stringFromJNI(env:PJNIEnv;this:jobject):jstring; cdecl;
|
||||||
var x:single;
|
var x:single;
|
||||||
begin
|
begin
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI entered');
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI entered');
|
||||||
curEnv^.SetLongField(curEnv,curClass,nativeCodeLoaded,1);
|
curEnv^.SetLongField(curEnv,curClass,nativeCodeLoaded,1);
|
||||||
x:=8;
|
x:=8;
|
||||||
result:=env^.NewStringUTF(env,pchar('Hello from native free pascal code by BeRo to the java world on the android platform ! '+floattostr(x*0.5)));
|
result:=env^.NewStringUTF(env,pchar('Hello from native free pascal code by BeRo to the java world on the android platform ! '+floattostr(x*0.5)));
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI exited');
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI exited');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const NativeMethods:array[0..0] of JNINativeMethod=
|
const NativeMethods:array[0..0] of JNINativeMethod=
|
||||||
@ -26,39 +25,40 @@ const NativeMethods:array[0..0] of JNINativeMethod=
|
|||||||
signature:'()Ljava/lang/String;';
|
signature:'()Ljava/lang/String;';
|
||||||
fnPtr:@Java_com_bero_nativetest_Main_stringFromJNI;));
|
fnPtr:@Java_com_bero_nativetest_Main_stringFromJNI;));
|
||||||
|
|
||||||
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
|
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
||||||
begin
|
begin
|
||||||
curVM:=vm;
|
curVM:=vm;
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','JNI_OnLoad called');
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','JNI_OnLoad called');
|
||||||
if curVM^.GetEnv(curVM,@curEnv,JNI_VERSION_1_6)<>JNI_OK then begin
|
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM=%x', [PtrInt(CurVM)])));
|
||||||
|
if curVM^.GetEnv(curVM,@curEnv,JNI_VERSION_1_6)<>JNI_OK then begin
|
||||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curVM^.GetEnv failed');
|
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curVM^.GetEnv failed');
|
||||||
result:=JNI_ERR;
|
result:=JNI_ERR;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
curClass:=curEnv^.FindClass(curEnv,'com/bero/nativetest/Main');
|
curClass:=curEnv^.FindClass(curEnv,'com/pascal/jnitest/AndroidJNITest');
|
||||||
if not assigned(curClass) then begin
|
if not assigned(curClass) then begin
|
||||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.FindClass failed');
|
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.FindClass failed');
|
||||||
result:=JNI_ERR;
|
result:=JNI_ERR;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
if curEnv^.RegisterNatives(curEnv,curClass,@NativeMethods[0],length(NativeMethods))<0 then begin
|
if curEnv^.RegisterNatives(curEnv,curClass,@NativeMethods[0],length(NativeMethods))<0 then begin
|
||||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.RegisterNatives failed');
|
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.RegisterNatives failed');
|
||||||
result:=JNI_ERR;
|
result:=JNI_ERR;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
nativeCodeLoaded:=curEnv^.GetFieldID(curEnv,curClass,'nativeCodeLoaded','J');
|
nativeCodeLoaded:=curEnv^.GetFieldID(curEnv,curClass,'nativeCodeLoaded','J');
|
||||||
if not assigned(nativeCodeLoaded) then begin
|
if not assigned(nativeCodeLoaded) then begin
|
||||||
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.GetFieldID failed');
|
__android_log_write(ANDROID_LOG_FATAL,'nativetest','curEnv^.GetFieldID failed');
|
||||||
result:=JNI_ERR;
|
result:=JNI_ERR;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
result:=JNI_VERSION_1_6;
|
result:=JNI_VERSION_1_6;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer);{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
|
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
|
||||||
begin
|
begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ public class AndroidJNITest extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
|
||||||
|
|
||||||
TextView tv = new TextView(this);
|
TextView tv = new TextView(this);
|
||||||
tv.setText( stringFromJNI() );
|
tv.setText( stringFromJNI() );
|
||||||
@ -31,4 +30,4 @@ public class AndroidJNITest extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user