You want to just run the c program without launching any application?

I don't think you can do that.

Kumar Bibek
http://techdroid.kbeanie.com
http://www.kbeanie.com



On Wed, Jan 12, 2011 at 3:31 PM, nelsonchung <chihchun.ch...@gmail.com>wrote:

> I write some code by c language and build it for arm platform - imx51.
> I can run this file under command line like this.
>
> start machine.
> adb push ./hello /
> adb shell
> ./hello
>
> and I can see the following information
> Hello World!
>
> I write some code on JNI.
>
> #include <jni.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <utils/Log.h>
>
> JNIEXPORT void JNICALL
> Java_rtk_main_atp_BrakeDetect_RunJniBrakeDetect(JNIEnv *env, jobject
> jobj)
> {
>        int ret = execv("/hello", (char *)NULL);
>
>        char buff[100];
>        memset(buff, 0, sizeof(100));
>        sprintf(buff, "[libhello] Hello %d \n", ret );
>        LOGD( buff );
>
> }
>
> but it must have something wrong, because I can't get any result from
> logcat.
>
> I got follow message
> AndroidRuntime( 2688):
> D/AndroidRuntime( 2688): >>>>>>>>>>>>>> AndroidRuntime START
> <<<<<<<<<<<<<<
> D/AndroidRuntime( 2688): CheckJNI is OFF
> D/dalvikvm( 2688): creating instr width table
> D/AndroidRuntime( 2688): --- registering native functions ---
> I/ActivityManager( 2136): Start proc com.android.defcontainer for
> service com.android.defcontainer/.DefaultContainerService: pid=2696
> uid=10013 gids={1015, 2001}
> D/dalvikvm( 2696): GC_EXPLICIT freed 742 objects / 54664 bytes in
> 53ms
> D/PackageParser( 2136): Scanning package: /data/app/vmdl13306.tmp
> D/dalvikvm( 2136): GC_FOR_MALLOC freed 6299 objects / 286008 bytes in
> 105ms
> I/PackageManager( 2136): Removing non-system package:rtk.main.atp
> I/ActivityManager( 2136): Force stopping package rtk.main.atp
> uid=10034
> D/dalvikvm( 2136): GC_FOR_MALLOC freed 1619 objects / 115552 bytes in
> 104ms
> D/PackageManager( 2136): Scanning package rtk.main.atp
> I/PackageManager( 2136): /data/app/rtk.main.atp-2.apk changed;
> unpacking
> I/PackageManager( 2136): Package rtk.main.atp codePath changed from /
> data/app/rtk.main.atp-1.apk to /data/app/rtk.main.atp-2.apk; Retaining
> data and using new
> D/installd( 2069): DexInv: --- BEGIN '/data/app/rtk.main.atp-2.apk'
> ---
> D/dalvikvm( 2718): creating instr width table
> D/dalvikvm( 2718): DexOpt: load 14ms, verify 6ms, opt 0ms
> D/installd( 2069): DexInv: --- END '/data/app/
> rtk.main.atp-2.apk' (success) ---
> D/PackageManager( 2136):   Activities: rtk.main.atp.BrakeDetect
> I/ActivityManager( 2136): Force stopping package rtk.main.atp
> uid=10034
> W/PackageManager( 2136): Code path for pkg : rtk.main.atp changing
> from /data/app/rtk.main.atp-1.apk to /data/app/rtk.main.atp-2.apk
> W/PackageManager( 2136): Resource path for pkg : rtk.main.atp changing
> from /data/app/rtk.main.atp-1.apk to /data/app/rtk.main.atp-2.apk
> D/dalvikvm( 2136): GC_FOR_MALLOC freed 1695 objects / 115832 bytes in
> 96ms
> I/installd( 2069): move /data/dalvik-cache/
> d...@app@rtk.main.atp-2....@classes.dex -> /data/dalvik-cache/
> d...@app@rtk.main.atp-2....@classes.dex
> D/PackageManager( 2136): New package installed in /data/app/
> rtk.main.atp-2.apk
> D/dalvikvm( 2136): GC_FOR_MALLOC freed 1253 objects / 92008 bytes in
> 100ms
> I/ActivityManager( 2136): Force stopping package rtk.main.atp
> uid=10034
> D/dalvikvm( 2296): GC_EXPLICIT freed 3866 objects / 240360 bytes in
> 104ms
> W/RecognitionManagerService( 2136): no available voice recognition
> services found
> D/dalvikvm( 2136): GC_FOR_MALLOC freed 1961 objects / 121864 bytes in
> 117ms
> I/ActivityManager( 2136): Start proc com.svox.pico for broadcast
> com.svox.pico/.VoiceDataInstallerReceiver: pid=2720 uid=10014 gids={}
> D/dalvikvm( 2136): GC_EXPLICIT freed 412 objects / 21232 bytes in
> 81ms
> I/ActivityThread( 2720): Publishing provider
> com.svox.pico.providers.SettingsProvider:
> com.svox.pico.providers.SettingsProvider
> I/installd( 2069): unlink /data/dalvik-cache/
> d...@app@rtk.main.atp-1....@classes.dex
> D/AndroidRuntime( 2688): Shutting down VM
> D/jdwp    ( 2688): Got wake-up signal, bailing out of select
> D/dalvikvm( 2688): Debugger has detached; object registry had 1
> entries
> D/AndroidRuntime( 2731):
> D/AndroidRuntime( 2731): >>>>>>>>>>>>>> AndroidRuntime START
> <<<<<<<<<<<<<<
> D/AndroidRuntime( 2731): CheckJNI is OFF
> D/dalvikvm( 2731): creating instr width table
> D/AndroidRuntime( 2731): --- registering native functions ---
> I/ActivityManager( 2136): Starting activity: Intent
> { act=android.intent.action.MAIN
> cat=[android.intent.category.LAUNCHER] flg=0x10000000
> cmp=rtk.main.atp/.BrakeDetect }
> D/AndroidRuntime( 2731): Shutting down VM
> D/jdwp    ( 2731): Got wake-up signal, bailing out of select
> D/dalvikvm( 2731): Debugger has detached; object registry had 1
> entries
> I/ActivityManager( 2136): Start proc rtk.main.atp for activity
> rtk.main.atp/.BrakeDetect: pid=2749 uid=10034 gids={}
> D/dalvikvm( 2749): No JNI_OnLoad found in /system/lib/
> libBrakeDetect.so 0x46123a68, skipping init
> I/ActivityManager( 2136): Process rtk.main.atp (pid 2749) has died.
> I/ActivityManager( 2136): Displayed activity android/
> com.android.internal.app.ResolverA
>
> after I modify some code under JNI
>
> #include <jni.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <utils/Log.h>
>
> JNIEXPORT void JNICALL
> Java_rtk_main_atp_BrakeDetect_RunJniBrakeDetect(JNIEnv *env, jobject
> jobj)
> {
>        int ret = 55;//execv("/hello", (char *)NULL); //fail
>
>
>        char buff[100];
>        memset(buff, 0, sizeof(100));
>        sprintf(buff, "[libhello] Hello %d \n", ret );
>        LOGD( buff );
>
> }
>
> I got follow message.
>
> D/AndroidRuntime( 2819):
> D/AndroidRuntime( 2819): >>>>>>>>>>>>>> AndroidRuntime START
> <<<<<<<<<<<<<<
> D/AndroidRuntime( 2819): CheckJNI is OFF
> D/dalvikvm( 2819): creating instr width table
> D/AndroidRuntime( 2819): --- registering native functions ---
> I/ActivityManager( 2136): Starting activity: Intent
> { act=android.intent.action.MAIN
> cat=[android.intent.category.LAUNCHER] flg=0x10000000
> cmp=rtk.main.atp/.BrakeDetect }
> D/AndroidRuntime( 2819): Shutting down VM
> I/ActivityManager( 2136): Start proc rtk.main.atp for activity
> rtk.main.atp/.BrakeDetect: pid=2828 uid=10034 gids={}
> D/dalvikvm( 2819): Debugger has detached; object registry had 1
> entries
> D/dalvikvm( 2828): No JNI_OnLoad found in /system/lib/
> libBrakeDetect.so 0x46123a68, skipping init
> D/        ( 2828): [libhello] Hello 55
> I/ActivityManager( 2136): Displayed activity
> rtk.main.atp/.BrakeDetect: 335 ms (total 335 ms)
> init: starting 'ril-daemon'
> - Show quoted text -
>
> and can get the message - "Hello 55" that I want to print to logcat.
>
> Something wrong with execv function?
> or
> Does anyone know how to launch executable file under JNI level?
>
> --
> 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
> android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to