如何在Android Studio中抑制“无法解析对应的JNI函数”错误?

huangapple go评论70阅读模式
英文:

How to suppress "Cannot resolve corresponding JNI function" in Android Studio?

问题

我正在在Android Studio中创建一个本地方法,该方法在库加载时使用JNI_OnLoad中的RegisterNatives进行注册。问题是我想加密方法名和签名字符串,但如果我这样做,Android Studio不允许我编译应用程序,因为出现以下错误:“无法解析对应的JNI函数Java_my_app_Native_initializeApplication。”
如何抑制此错误?

英文:

I am creating a native method in Android Studio which is registered using RegisterNatives in JNI_OnLoad when the library is loaded. The problem is that I want to encrypt the method name and signature strings, but if I do that Android Studio doesn't let me compile the app because of this error: "Cannot resolve corresponding JNI function Java_my_app_Native_initializeApplication."
How can I suppress this?

答案1

得分: 1

点击快速修复按钮会弹出一个窗口,要求添加@Suppress("KotlinJniMissingFunction")注解到类或文件中。您可以将其保留在那里,或者将其移至所有方法,例如:

@Suppress("KotlinJniMissingFunction")
external fun initializeApplication()

或者

@Suppress("KotlinJniMissingFunction")
class Native : AppCompatActivity() {
...
}

对于Java,相应的注解是@SuppressWarnings("JavaJniMissingFunction")

英文:

Clicking the quick fix button gave me a pop up to add a @Suppress("KotlinJniMissingFunction") annotation to either the class or the file. You can keep it there or move it to all your methods, eg:

@Suppress("KotlinJniMissingFunction")
external fun initializeApplication()

or

@Suppress("KotlinJniMissingFunction")
class Native : AppCompatActivity() {
...
}

The equivalent annotation for Java is @SuppressWarnings("JavaJniMissingFunction").

huangapple
  • 本文由 发表于 2023年6月8日 01:34:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76425800.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定