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:
sekelsenmat
2011-11-27 08:36:15 +00:00
parent 27bce8924f
commit 694f02d26c
4 changed files with 114 additions and 27 deletions

View File

@ -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

View 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>

View File

@ -1,7 +1,6 @@
library nativetest; library nativetest;
{$ifdef fpc}
{$mode delphi} {$mode delphi}
{$endif}
uses uses
SysUtils, SysUtils,
@ -11,7 +10,7 @@ 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');
@ -26,17 +25,18 @@ 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');
__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 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;
@ -58,7 +58,7 @@ begin
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;

View File

@ -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() );