Google Groups Home
Help | Sign in
Native C "Hello World" working in emulator
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  22 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
TomCooksey  
View profile
(3 users)  More options Nov 13 2007, 12:31 pm
From: TomCooksey <TomCook...@googlemail.com>
Date: Tue, 13 Nov 2007 09:31:27 -0800
Local: Tues, Nov 13 2007 12:31 pm
Subject: Native C "Hello World" working in emulator
I've managed to get a native C application working in the emulator.

For those who are interested, here's how:

1) Create your hello world program:

#include <stdio.h>

int main(int argc, char** argv) {
   printf("hello world\n");
   return 0;

}

2) Compile with an arm cross-compiler toolchain. I used a toolchain I
built with gentoo's crossdev tool, but there are lots out there.
Assuming your c file is hi.c and your cross compiler is called armv6-
vfp-linux-gnueabi-gcc, you can compile using:

armv6-vfp-linux-gnueabi-gcc hi.c -o hi -static

Note the -static. I've not figured out the version of libc etc or the
ABI used yet, so for now, link applications statically.

3) Copy to a running emulator:
adb push hi /system/sbin/hi

4) Run it! From the emulator console:
cd /system/sbin
./hi

5) Smile as you see "hello world" printed on the console. :-)

Next, I'm going to try and get busybox up & running so we can have
access to exciting programs such as "cp"! After that, perhaps dropbear
for remote ssh access? Or maybe a small web server like boa so we can
turn the android emulator into a webserver? Stay tuned.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dimenwarper  
View profile
 More options Nov 13 2007, 12:35 pm
From: dimenwarper <dimenwar...@gmail.com>
Date: Tue, 13 Nov 2007 09:35:22 -0800
Local: Tues, Nov 13 2007 12:35 pm
Subject: Re: Native C "Hello World" working in emulator
Nice work!
The webserver idea is pretty cool...maybe opening way to a sort of
game server for multiplayer game scenarios? (drool)

On Nov 13, 11:31 am, TomCooksey <TomCook...@googlemail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jingtao Wang  
View profile
 More options Nov 13 2007, 12:40 pm
From: Jingtao Wang <jingt...@gmail.com>
Date: Tue, 13 Nov 2007 09:40:04 -0800
Local: Tues, Nov 13 2007 12:40 pm
Subject: Re: Native C "Hello World" working in emulator
Excellent work!

I just noticed that some classes in Android.jar used the keyword
"native". It should be a matter of time to get either offical or
unofficial suport for calling native code from the Dalvik VM.

On Nov 13, 9:31 am, TomCooksey <TomCook...@googlemail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Ardiri  
View profile
(2 users)  More options Nov 13 2007, 12:45 pm
From: "Aaron Ardiri" <ard...@gmail.com>
Date: Tue, 13 Nov 2007 18:45:14 +0100
Local: Tues, Nov 13 2007 12:45 pm
Subject: Re: Native C "Hello World" working in emulator
On Nov 13, 2007 6:40 PM, Jingtao Wang <jingt...@gmail.com> wrote:

> Excellent work!

> I just noticed that some classes in Android.jar used the keyword
> "native". It should be a matter of time to get either offical or
> unofficial suport for calling native code from the Dalvik VM.

this is what i mentioned in an earlier thread (titled JNI: ....)

javah is typically used to build a header file which defines the
native object interface for the compiled native code from java.

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jnie...

native byte[] loadFile(String name);

and using 'javah', the following interface is created:

  /*
   * Class:     ReadFile
   * Method:    loadFile
   * Signature: (Ljava/lang/String;)[B
   */
  JNIEXPORT jbyteArray JNICALL Java_ReadFile_loadFile
    (JNIEnv *, jobject, jstring);

from here, you should be able to compile a shared library, in this
case for ARM that uses Java as an executable launching environment
yet actually runs code natively.

you can also look at System.exec() - which is defined within the
android developer documentation.

having JNI functioning would be all that i would require for my
multi-platform development kit. i can use the Java base to be my
interface to the device and operating system, yet call my code
natively (the code which is not platform dependent)

definately keeping an eye on this.

--
// Aaron Ardiri
Mobile Wizardry
http://www.mobilewizardry.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Ardiri  
View profile
 More options Nov 13 2007, 12:50 pm
From: "Aaron Ardiri" <ard...@gmail.com>
Date: Tue, 13 Nov 2007 18:50:35 +0100
Local: Tues, Nov 13 2007 12:50 pm
Subject: Re: Native C "Hello World" working in emulator
seems there is JNI support within the android emulator:

----
Android Emulator
http://code.google.com/android/reference/emulator.html

-nojni          Disable JNI checks in the Dalvik runtime.

// Aaron Ardiri
Mobile Wizardry
http://www.mobilewizardry.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ali Akbar  
View profile
 More options Nov 13 2007, 12:56 pm
From: Ali Akbar <ali.ak...@gmail.com>
Date: Tue, 13 Nov 2007 17:56:00 -0000
Subject: Re: Native C "Hello World" working in emulator
well done!  thx for posting

On Nov 13, 8:31 pm, TomCooksey <TomCook...@googlemail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Akeem A.  
View profile
(1 user)  More options Nov 13 2007, 12:57 pm
From: "Akeem A." <akeem.aden...@gmail.com>
Date: Tue, 13 Nov 2007 17:57:26 -0000
Local: Tues, Nov 13 2007 12:57 pm
Subject: Re: Native C "Hello World" working in emulator
I am thinking just a bit down the future. So we have our .so files and
we have Android. How will we gain access to the boot loader in order
to install the libraries? When I worked at a mostly Microsoft OEM
Jtags were used but this may not be an option.

On Nov 13, 12:50 pm, "Aaron Ardiri" <ard...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jingtao Wang  
View profile
 More options Nov 13 2007, 12:58 pm
From: Jingtao Wang <jingt...@gmail.com>
Date: Tue, 13 Nov 2007 09:58:52 -0800
Local: Tues, Nov 13 2007 12:58 pm
Subject: Re: Native C "Hello World" working in emulator
Yeah, I know it's JNI ;-)

What I was trying to say is - after looking at some of the compiled
bytecode in Android.jar, it's obvious that some functions in the
current SDK were implemented in native code,

e.g.     public static final native int getCallingPid(); in class
android.os.BinderNative

I'm not sure whether this native interface is 100% compatible with
Sun's JNI definations through.

On Nov 13, 9:45 am, "Aaron Ardiri" <ard...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aghi Holl  
View profile
 More options Nov 13 2007, 1:18 pm
From: "Aghi Holl" <aghionandro...@gmail.com>
Date: Tue, 13 Nov 2007 14:18:15 -0400
Local: Tues, Nov 13 2007 1:18 pm
Subject: Re: Native C "Hello World" working in emulator
Hi Tom,

 That seems nice, can you list the first steps, since running the
emulator until the "create hello world program"

Thanks.

On Nov 13, 2007 1:31 PM, TomCooksey <TomCook...@googlemail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aaron Ardiri  
View profile
 More options Nov 13 2007, 1:24 pm
From: "Aaron Ardiri" <ard...@gmail.com>
Date: Tue, 13 Nov 2007 19:24:13 +0100
Local: Tues, Nov 13 2007 1:24 pm
Subject: Re: Native C "Hello World" working in emulator
On Nov 13, 2007 6:57 PM, Akeem A. <akeem.aden...@gmail.com> wrote:

> I am thinking just a bit down the future. So we have our .so files and
> we have Android. How will we gain access to the boot loader in order
> to install the libraries? When I worked at a mostly Microsoft OEM
> Jtags were used but this may not be an option.

why can the .so files not be shipped with the .apkg files?

the shared libraries may be shared, but honestly they only need to
be avalable to the application that we install. the could be like a
normal resource, we just have to make sure that loadLibrary()
allows for searching of the .so files within the application path.

the question is what is the android equivalent to javah and the
include files necessary to build the JNI binaries.

i am yet to install the SDK yet (been very busy today) - but, i am
sure when we have dug around deep enough we will find all
of these things. what we then need is:

a) detect cpu architecture at runtime (load alternative library)
b) the ability to put .so files in our .apkg files
c) simply use the android launcher to load our application

i used to do a lot of JNI work back in 1997/1998 where i cross
compiled a lot of image processing stuff between windows, linux
and solaris. its not a question os how, its when :)

--
// Aaron Ardiri
Mobile Wizardry
http://www.mobilewizardry.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
TomCooksey  
View profile
 More options Nov 13 2007, 1:33 pm
From: TomCooksey <TomCook...@googlemail.com>
Date: Tue, 13 Nov 2007 10:33:58 -0800
Local: Tues, Nov 13 2007 1:33 pm
Subject: Re: Native C "Hello World" working in emulator

>  That seems nice, can you list the first steps, since running the
> emulator until the "create hello world program"

0.1) Download the SDK into e.g. ~/Android

0.2) Unpack the sdk:
unzip android_sdk_linux_m3-rc20a.zip

0.3) cd into ~/Android/android_sdk_linux_m3-rc20a/tools

0.4) launch emulator with console enabled
./emulator -console

That should do it. :-)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the