使用QandroidJniObject未调用的三个函数之一

One of three functions not being called using QAndroidJniObject

本文关键字:三个 函数 QandroidJniObject 调用 使用      更新时间:2023-10-16

这是从我的自定义Java类调用三个函数的代码:

QAndroidJniObject datafile = QAndroidJniObject::fromString(path);
QAndroidJniObject password = QAndroidJniObject::fromString("asimpletest");
QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                          "AESCryptInit",
                                          "(Ljava/lang/String;Ljava/lang/String;)V;",
                                          password.object<jstring>(),
                                          datafile.object<jstring>());

QAndroidJniObject decrypted_data = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                                                             "decrypt",
                                                                             "()Ljava/lang/String;");

QAndroidJniObject fname = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                                                   "getFilename",
                                                                   "()Ljava/lang/String;");
QAndroidJniObject status = QAndroidJniObject::callStaticObjectMethod("org/qcolocrypt/AESCrypt",
                                                                   "getStatus",
                                                                   "()Ljava/lang/String;");

这是其中三个功能的Java代码:

不工作的一个:

public static void AESCryptInit (String passwd, String datafile){
    // Initializing variables.
    rawdata = null;
    status = "";
    fileName = datafile;
    Log.i("[QCOLOCRYPT]","The filename is " + datafile);
    // Transforming the passwd to 16 bytes.
    try {
        MessageDigest digester = MessageDigest.getInstance("MD5");
        InputStream in = new ByteArrayInputStream(Charset.forName(encoding).encode(passwd).array());
        byte[] buffer = new byte[NCHARS];
        int byteCount;
        while ((byteCount = in.read(buffer)) > 0) {
            digester.update(buffer, 0, byteCount);
        }
        keyBytes = digester.digest();
    }
    catch(Exception e){
        status = "Error in key generation: " + e.toString();
    }
    // Initilizing the crypto engine
    try {
        cipher = Cipher.getInstance(algorithm);
    }
    catch(Exception e){
        status = "Error in intialization: " + e.toString();
    }
    secretKeySpec = new SecretKeySpec(keyBytes, "AES");
    ivParameterSpec = new IvParameterSpec(keyBytes);
}

和两个工作的

// Getting status
public static String getStatus(){return status;}
public static String getFilename() {
   Log.i("[QCOLOCRYPT]","Getting the file name");
   return "The Filename is: " + fileName;
}

当我收到日志消息和其他两个的返回值时,没有打印其调试消息,因此未调用非工作函数。logcat似乎没有显示任何错误,所以我很茫然。我叫错吗?

好的,所以这并不是一个答案。这更像是一个解决方法,我可以使用功能,但是我唯一可以做的方法是返回字符串。我已经尝试使用(参数)i的整数;作为签名,但我遇到了同样的问题。我修改了Java函数以返回状态字符串,更改了签名以反映这一点,一切正常。虽然很奇怪。