Results 1 to 2 of 2
  1. #1
    gaurav115 is offline Member
    Join Date
    Apr 2012
    Rep Power

    Default Android with JNI

    I have tried writing a jni call for the simple c code. when i try to install this on the phone running 2.3.3 it doesnt install, sometimes even if it installs then it is being force closed.Please help me with this. the code details are as follows:

    The java code of which i generate the header file.

    package com.hosa;

    public class edgejava{
    public native int main();

    the generated header file is as below

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class com_hosa_edgejava */

    #ifndef _Included_com_hosa_edgejava
    #define _Included_com_hosa_edgejava
    #ifdef __cplusplus
    extern "C" {
    * Class: com_hosa_edgejava
    * Method: main
    * Signature: ()I
    JNIEXPORT jint JNICALL Java_com_hosa_edgejava_main
    (JNIEnv *, jobject);

    #ifdef __cplusplus

    the implementation of native function is as below

    #include "com_hosa_edgejava.h"
    #include <jni.h>
    #include <cv.h>
    #include <highgui.h>

    using namespace cv;

    JNIEXPORT jint JNICALL Java_com_pes_edgejava_main(JNIEnv *, jobject){
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened()) // check if we succeeded
    return -1;

    Mat edges;
    Mat frame;
    cap >> frame; // get a new frame from camera
    cvtColor(frame, edges, CV_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);
    if(waitKey(30) >= 0) break;
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;

    the file

    LOCAL_PATH := $(call my-dir)

    include $(CLEAR_VARS)

    include /home/srijith/android-opencv/OpenCV-2.3.1/share/OpenCV/

    LOCAL_MODULE := edgejava
    LOCAL_SRC_FILES := edgecpp.cpp
    LOCAL_LDLIBS += -llog -ldl



    APP_MODULES := edgejava
    APP_STL := gnustl_static
    APP_CPPFLAGS := -frtti -fexceptions

    the activity file is as follows

    package com.hosa;

    import android.os.Bundle;

    public class Andedge2Activity extends Activity {
    edgejava nativelib;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

    nativelib= new edgejava();
    int i=nativelib.main();
    System.out.println("value returned to andedgeactivity "+i);

    All necessary changes to the manifest has been done like mention of use of camera and permissions has been set.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Android with JNI

    When you have a question, start your own thread. Don't tag on to a thread with a totally unrelated question.

    Split from

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 12-24-2011, 05:41 AM
  2. Android Help
    By fresh83 in forum Android
    Replies: 1
    Last Post: 05-19-2011, 08:44 PM
  3. android sdk
    By aizen92 in forum Android
    Replies: 2
    Last Post: 02-21-2011, 11:28 PM
  4. Android USB
    By Blackberrylerner in forum Android
    Replies: 0
    Last Post: 01-15-2011, 06:05 AM
  5. Android
    By sspkiet in forum Android
    Replies: 1
    Last Post: 09-03-2010, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts