当前位置:网站首页>NDK learning notes (V)
NDK learning notes (V)
2022-06-11 05:33:00 【Come and go】
List of articles
1.android studio After the code is generated, Mr , Avoid missing the specified class
stay android studio You may need to delete the generated code and regenerate it , The original code prompts the specified class that cannot be found at runtime , Not working properly . Can you test the code , Yes. .
edit app Of build.gradle, Add the following configuration
project.afterEvaluate {
javaPreCompileDebug.dependsOn externalNativeBuildDebug
}
2. Call from native code java
(1) Create a class
A.h
extern int getuid();
class MyAsync {
public:
MyAsync() {
}
virtual ~ MyAsync() {
}
void get() {
onUid(getuid());
}
virtual void onUid(int uid) {
}
};
A.cpp
#include "A.h"
int getuid() {
return 3000;
}
(2) Enable directors
SWIG use directors Features provide support for cross language polymorphism . To call... In native code java To prepare .
/* Module name see*/
%module(directors = 1) See;
/* For the class MyAsync Virtual method generation director in */
%feature("director") MyAsync;
// Include the customized code in the generated file , For example, the header file needed to compile the generated code
%{
#include "A.h"
#include "A.cpp"
%}
%include "A.h"
(3) Override callback method
stay java Create classes in and inherit MyAsync
public class JavaAsync extends com.example.ndk2.jni.MyAsync {
private final TextView textView;
public JavaAsync(TextView textView) {
this.textView = textView;
}
@Override
public void onUid(int uid) {
textView.setText(uid + "");
}
}
(4) Use
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = findViewById(R.id.sample_text);
JavaAsync javaAsync = new JavaAsync(tv);
javaAsync.get();
}
(5) effect 
边栏推荐
- Carrier coordinate system inertial coordinate system world coordinate system
- Common methods of tool class objectutil
- Section III: structural characteristics of cement concrete pavement
- 项目-智慧城市
- Use acme SH automatically apply for a free SSL certificate
- Reverse thinking: making cartoon photos real
- Getbackgroundaudiomanager controls music playback (dynamic binding of class name)
- Deep search + backtracking
- 【入门级基础】Node基础知识总结
- Course design summary
猜你喜欢

Bert knowledge distillation

Analyze while doing experiments -ndk article -jni uses registernatives for explicit method registration

Wechat applet uploads the data obtained from database 1 to database 2

Customize the layout of view Foundation

Wechat applet text built-in component newline character does not newline reason

Sealem finance builds Web3 decentralized financial platform infrastructure

1.使用阿里云对象OSS(初级)

如何让灯具智能化,单火、零火智能开关怎么选!

自定义View基础之Layout

Oh my Zsh correct installation posture
随机推荐
Recursively process data accumulation
NVIDIA SMI has failed because it could't communicate with the NVIDIA driver
[entry level basics] node basic knowledge summary
Preliminary test of running vins-fusion with zed2 binocular camera
Section I: classification and classification of urban roads
Swap numbers (no temporary variables)
Wechat custom component - style - slot
Intercept file extension
MySQL circulates multiple values foreach, XML writing method
Analysis while experiment - a little optimization of memory leakage in kotlin
About custom comparison methods of classes and custom methods of sort functions
WinForm (I) introduction to WinForm and use of basic controls
Sealem finance builds Web3 decentralized financial platform infrastructure
Traversal of binary tree -- restoring binary tree by two different Traversals
How to make lamps intelligent? How to choose single fire and zero fire intelligent switches!
如何让灯具智能化,单火、零火智能开关怎么选!
微信小程序text内置组件换行符不换行的原因-wxs处理换行符,正则加段首空格
jvm调优五:jvm调优工具和调优实战
Paper recommendation: relicv2, can the new self supervised learning surpass supervised learning on RESNET?
Tightly coupled laser vision inertial navigation slam system: paper notes_ S2D. 66_ ICRA_ 2021_ LVI-SAM