[android-developers] Re: Android JNI

2008-08-26 Thread ccf2000

Hi,all:
I think JNI is supported in 0.9 Beta. Because I wrote a
helloworld's jni application in 0.9 beta,and it seem running
successfully.
but i encounter a trouble, I can not do any writing operation,
like remove/rename file.
Next is JNI C code:
JNIEXPORT void JNICALL Java_jprint_print(JNIEnv *env, jobject obj)
{
remove(/data/a.log);
rename(/data/b.log, /data/c.log);
printf(hello jni===\r\n);
}

JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved)
{
JNIEnv *env;
JNINativeMethod meth;
jclass k;
jint r;

r = (*vm)-GetEnv (vm, (void **) env, JNI_VERSION_1_4);
k = (*env)-FindClass (env, com.android.helloactivity.jprint);

meth.name = print;
meth.signature = ()V;
meth.fnPtr = Java_jprint_print;
r = (*env)-RegisterNatives (env, k, meth, 1);
return JNI_VERSION_1_4;
}

JNIEXPORT void JNI_OnUnload(JavaVM *vm, void *reserved)
{
JNIEnv *env;
jclass k;
jint r;
r = (*vm)-GetEnv (vm, (void **) env, JNI_VERSION_1_2);
k = (*env)-FindClass (env, com.android.helloactivity.jprint);
(*env)-UnregisterNatives(env, k);
}

It is very important to call RegisterNatives() to register native
interface. It will show error information Not Implemention  if you
do not register it.

Next is Jave Code:
public class jprint
{
public native void print();

static
{
try {
Log.i(JNI, Trying to load jni .so);
 
System.out.println(System.getProperty(java.library.path));
System.load(/data/libjnilibs.so);
}
catch (UnsatisfiedLinkError ule) {
Log.e(JNI, ule.getMessage());

}
}
}

Add code to Android OnCreate():
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

jprint p = new jprint();
p.print();
...
}
It is also very important to call System.load(/data/libjnilibs.so)
in java instead of System.loadLibrary(), because System.loadLibrary()
always load library from /system/lib directory.

because /system/bin is readonly file system. so you can push .so file
to /data.
1.build out .so file using arm-eabi compiler
2.push .so to /data directoy: adb push d:/libjnilibs.so /data.(I use
windows's emulator and tool)
3.run java application, you will see(via adb logcat):

I/JNI (  524): Trying to load jni .so
I/System.out(  524): /system/lib
D/dalvikvm(  524): Trying to load lib /data/libjnilibs.so 0x433f22d0
D/dalvikvm(  524): Added shared lib /data/libjnilibs.so 0x433f22d0
I/ActivityManager(   50): Displayed activity com.android.helloactivity


No, the native interface print() will be called from Jave application.
But It can not  remove file in JNI. I think it is limited by java's
security management.
JNIEXPORT void JNICALL Java_jprint_print(JNIEnv *env, jobject obj)
{
remove(/data/a.log);
rename(/data/b.log, /data/c.log);
printf(hello jni===\r\n);
}
I do not know how to solve this problem. who can tell me and
suggestion?

On Aug 26, 5:01 am, hackbod [EMAIL PROTECTED] wrote:
 Native code is not supported in 1.0.

 On Aug 25, 11:15 am, Tyler Ernst [EMAIL PROTECTED] wrote:



  Thanks, that was exactly what we needed.  We realize JNI is not
  supported, but Java code is just too slow to do the things we need...

  On Aug 25, 2:23 am, Volker Gropp [EMAIL PROTECTED] wrote:

   On Aug 22, 9:30 pm, Tyler Ernst [EMAIL PROTECTED] wrote:

Also since the 0.9 beta has been released I have been unable to copy
the .so to the /system/lib directory of the emulator.  If anyone has
found a way to do this that would be greatly appreciated.

   Hi,

   you have to mount the system rw. To do so run `adb remount` before you
   push your .so. And keep in mindJNIwill not be supported, or did you
   find a way to deploy your native lib with a .apk?

   Volker Gropp- Hide quoted text -

 - Show quoted text -

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Android JNI

2008-08-26 Thread hackbod

On Aug 25, 8:36 pm, ccf2000 [EMAIL PROTECTED] wrote:
     I think JNI is supported in 0.9 Beta. Because I wrote a
 helloworld's jni application in 0.9 beta,and it seem running
 successfully.

Native code is NOT SUPPORTED in 1.0.  Anything you do here is a hack,
which will not be supported across any particular builds of the
platform, will run into any number of arbitrary bugs or limitations
that may be different across each release of the platform, etc.

Feel free to hack away at this stuff if you want, but you have to
understand that these are not things a normal application can do, and
anything you do here will probably result in your application breaking
in future  releases (possibly every release) of the platform.  As
such, all of the discussion about this should be moved to the android-
internals group.

As far as writing files, applications are not allowed to write outside
of their dedicated data directories, as described here:
http://code.google.com/android/devel/security.html

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Android JNI

2008-08-25 Thread Volker Gropp

On Aug 22, 9:30 pm, Tyler Ernst [EMAIL PROTECTED] wrote:
 Also since the 0.9 beta has been released I have been unable to copy
 the .so to the /system/lib directory of the emulator.  If anyone has
 found a way to do this that would be greatly appreciated.

Hi,

you have to mount the system rw. To do so run `adb remount` before you
push your .so. And keep in mind JNI will not be supported, or did you
find a way to deploy your native lib with a .apk?

Volker Gropp

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Android JNI

2008-08-25 Thread Tyler Ernst

Thanks, that was exactly what we needed.  We realize JNI is not
supported, but Java code is just too slow to do the things we need...

On Aug 25, 2:23 am, Volker Gropp [EMAIL PROTECTED] wrote:
 On Aug 22, 9:30 pm, Tyler Ernst [EMAIL PROTECTED] wrote:

  Also since the 0.9 beta has been released I have been unable to copy
  the .so to the /system/lib directory of the emulator.  If anyone has
  found a way to do this that would be greatly appreciated.

 Hi,

 you have to mount the system rw. To do so run `adb remount` before you
 push your .so. And keep in mindJNIwill not be supported, or did you
 find a way to deploy your native lib with a .apk?

 Volker Gropp
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Android JNI

2008-08-25 Thread Ahmet A. Akin

Blame the Dalvik, not java :P

On Mon, Aug 25, 2008 at 2:15 PM, Tyler Ernst [EMAIL PROTECTED] wrote:

 Thanks, that was exactly what we needed.  We realize JNI is not
 supported, but Java code is just too slow to do the things we need...

 On Aug 25, 2:23 am, Volker Gropp [EMAIL PROTECTED] wrote:
 On Aug 22, 9:30 pm, Tyler Ernst [EMAIL PROTECTED] wrote:

  Also since the 0.9 beta has been released I have been unable to copy
  the .so to the /system/lib directory of the emulator.  If anyone has
  found a way to do this that would be greatly appreciated.

 Hi,

 you have to mount the system rw. To do so run `adb remount` before you
 push your .so. And keep in mindJNIwill not be supported, or did you
 find a way to deploy your native lib with a .apk?

 Volker Gropp
 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Android JNI

2008-08-25 Thread hackbod

Native code is not supported in 1.0.

On Aug 25, 11:15 am, Tyler Ernst [EMAIL PROTECTED] wrote:
 Thanks, that was exactly what we needed.  We realize JNI is not
 supported, but Java code is just too slow to do the things we need...

 On Aug 25, 2:23 am, Volker Gropp [EMAIL PROTECTED] wrote:

  On Aug 22, 9:30 pm, Tyler Ernst [EMAIL PROTECTED] wrote:

   Also since the 0.9 beta has been released I have been unable to copy
   the .so to the /system/lib directory of the emulator.  If anyone has
   found a way to do this that would be greatly appreciated.

  Hi,

  you have to mount the system rw. To do so run `adb remount` before you
  push your .so. And keep in mindJNIwill not be supported, or did you
  find a way to deploy your native lib with a .apk?

  Volker Gropp
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Android JNI

2008-08-22 Thread vol

Actually, the errors stemmed from some compile-related
incompatabilities.

Is it possible to do this from win32, or do I have to do it from
Linux?

On Aug 22, 11:36 am, vol [EMAIL PROTECTED] wrote:
 I'm having trouble building the JNI example 
 athttp://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-meth...
 .

 First up, is it possible to actually do this from windows? Do I have
 to do this in a linux environment? I would think that doing this from
 windows is possible, but I don't have jdk/include/linux, just jdk/
 include/win32, so that's throwing me.

 Second, I am at step 6, and am attempting to use arm-none-linux-
 gnueabi-gcc.
 $ arm-none-linux-gnueabi-gcc  -I/cygdrive/c/Program\ Files/Java/
 jdk1.6.0_04/include/ -I/cygdrive/c/Program\ Files/Java/jdk1.6.0_04/
 include/win32/  -fpic -c org_apache_NativeAdd.c

 In file included from org_apache_NativeAdd.c:1:
 org_apache_NativeAdd.h:2:17: error: jni.h: No such file or directory
 In file included from org_apache_NativeAdd.c:1:
 org_apache_NativeAdd.h:15: error: expected '=', ',', ';', 'asm' or
 '__attribute__' before 'jlong'
 org_apache_NativeAdd.c:3: error: expected '=', ',', ';', 'asm' or
 '__attribute__' before 'jlong'

 Ok. Cygwin + arm-none-linux-gnueabi-gcc didn't want to seem to include
 anything like that, so I just flat out copied over the contents, and
 it was happy to include them. Unfortunately, it didn't want to build
 them, giving me other errors like those seen above.

 What do I have set up incorrectly for building JNI?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---



[android-developers] Re: Android JNI

2008-08-22 Thread Tyler Ernst

You are getting those errors because you are building for linux, but
using the windows jni includes.  This is because the compiler does not
recognize the __int64 microsoft extension.  You can build this in a
windows environment, but you'll have to get the include files from the
linux environment.

Also since the 0.9 beta has been released I have been unable to copy
the .so to the /system/lib directory of the emulator.  If anyone has
found a way to do this that would be greatly appreciated.

Thanks

On Aug 22, 10:46 am, vol [EMAIL PROTECTED] wrote:
 Actually, the errors stemmed from some compile-related
 incompatabilities.

 Is it possible to do this from win32, or do I have to do it from
 Linux?

 On Aug 22, 11:36 am, vol [EMAIL PROTECTED] wrote:



  I'm having trouble building the JNI example 
  athttp://davanum.wordpress.com/2007/12/09/android-invoke-jni-based-meth...
  .

  First up, is it possible to actually do this from windows? Do I have
  to do this in a linux environment? I would think that doing this from
  windows is possible, but I don't have jdk/include/linux, just jdk/
  include/win32, so that's throwing me.

  Second, I am at step 6, and am attempting to use arm-none-linux-
  gnueabi-gcc.
  $ arm-none-linux-gnueabi-gcc  -I/cygdrive/c/Program\ Files/Java/
  jdk1.6.0_04/include/ -I/cygdrive/c/Program\ Files/Java/jdk1.6.0_04/
  include/win32/  -fpic -c org_apache_NativeAdd.c

  In file included from org_apache_NativeAdd.c:1:
  org_apache_NativeAdd.h:2:17: error: jni.h: No such file or directory
  In file included from org_apache_NativeAdd.c:1:
  org_apache_NativeAdd.h:15: error: expected '=', ',', ';', 'asm' or
  '__attribute__' before 'jlong'
  org_apache_NativeAdd.c:3: error: expected '=', ',', ';', 'asm' or
  '__attribute__' before 'jlong'

  Ok. Cygwin + arm-none-linux-gnueabi-gcc didn't want to seem to include
  anything like that, so I just flat out copied over the contents, and
  it was happy to include them. Unfortunately, it didn't want to build
  them, giving me other errors like those seen above.

  What do I have set up incorrectly for building JNI?- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~--~~~~--~~--~--~---