mardi 18 août 2015

Loading a static void C function via AndroidfromJNI another Package

I am trying some things out with JNI and by that I found the following problem:

If I want to use a native function in Java I load the needed lib, in which the needed function is stored, via

static{
     System.loadLibrary("lib");
}

and use

native private static int calculate(byte[] numberArray);

to declare the native method in the java file. During the program itself I can use this function to calculate something with:

int result = calculate(array);

This works only if I compiled the shared object with the header-file created by javah so that each function is named on c side as:

static void Java_com_packagename_File_calculate(const void* array, void* result){
    code[...]
}

If I delete the reference in the java code ("native [...] calculate[...]")to this c function; is there any possibility to access / execute the still existing c-code via java (of course without editing the exisiting file ;-)) for example via reflections or inheritance? Or is there something possible like:

public class NewClass{

  public int nativeCheater(){
    System.loadLibrary("lib");
    native private static int Java_com_packagename_File_calculate;
  }        
}

It is important that I want to use a whole new class without any relations to the prior used package com.packagename.(File).

Thanks in advance :-)





Aucun commentaire:

Enregistrer un commentaire