背景:搞android framework改制,加入一个系统服务。在framework/base/service里
写一个测试程序:
xxxxxx_android_hua_HuaRadio.cpp
#define LOG_TAG "Vehicle-JNI"
#include "JNIHelp.h"
#include "jni.h"
#include <termios.h>
#include <string.h>
#include <fcntl.h>
#include <utils/Log.h>
#define MCU_DEV "/dev/uart-mcu"
using namespace std;
namespace android {
static void xxx_android_hua_HuaRadio_nativeInit
(JNIEnv * env, jobject obj){
jclass cls = env->GetObjectClass(obj);
jmethodID print= env->GetMethodID(cls,"print","()V");
env->CallIntMethod(obj,print);
}
static void xxx_android_hua_HuaRadio_nativeRun
(JNIEnv *, jobject){
LOGE("send data:%d",2222222);
}
static JNINativeMethod HuaRadioMethods [] = {
{"nativeInit","()Z",(void*)xxx_android_hua_HuaRadio_nativeInit},
{"nativeRun","()Z",(void*)xxx_android_hua_HuaRadio_nativeRun},
};
int register_xxx_android_hua_HuaRadio(JNIEnv *env)
{
int res = jniRegisterNativeMethods(env,"cn/com/xxx/android/hua/HuaRadio",
HuaRadioMethods,NELEM(HuaRadioMethods));
return 0;
}
}
HuaRadio.java
package cn.com.xxx.android.hua;
import android.content.Context;
import cn.com.xxx.android.IHuaRadio;
public class HuaRadio extends IHuaRadio.Stub{
private Context context;
public HuaRadio(Context ctx){
System.out.println("HuaRadio init() by hua");
this.context=ctx;
try{
nativeInit();
nativeRun();
}catch(Exception e){
System.out.plintln("hua "+e);
}
}
public void init(){
nativeRun();
}
public void print(){
System.out.println("HuaService print method!!!");
}
public native void nativeInit();
public native void nativeRun();
}
最后编译出现
No implementation found for native问题
为什么呢?
找了许久,发现register_xxx_android_hua_HuaRadio是要自己注册的
在onload.cpp 里加入
namespace android {
int register_android_server_AlarmManagerService(JNIEnv* env);
int register_android_server_BatteryService(JNIEnv* env);
int register_android_server_InputManager(JNIEnv* env);
int register_android_server_LightsService(JNIEnv* env);
int register_android_server_PowerManagerService(JNIEnv* env);
int register_android_server_UsbService(JNIEnv* env);
int register_android_server_VibratorService(JNIEnv* env);
int register_android_server_SystemServer(JNIEnv* env);
int register_android_server_location_GpsLocationProvider(JNIEnv* env);
//加入这个 就OK了
int register_cs2c_android_hua_HuaRadio(JNIEnv* env);
};
哎!!!
分享到:
相关推荐
android 串口驱动源代码 package android.serialport; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; ...
reference and implementation for building three-tier architectures with a Data Layer (MongoDB), Service Layer (Node.js/Express) and Presentation Layer (React/React Native). Learn how to architect, ...
- Added support for VGA graphics mode with 400 lines (partial fix for SF bug #2948724) - NE2K: Fixed "send buffer" command issue on big endian hosts - USB - converted common USB code plus devices ...
Discover how stronger types mean cleaner, more efficient, and optimized PHP applications. This unique book looks at typed PHP: PHP types, strings, regular expressions, and ...Chapter 5: Implementation
Disassembler - fix for error emitted for unknown type for target of scope operator. Now, ignore it and continue. Disassembly of an FADT now verifies the input FADT and reports any errors found. Fix ...
VCLZip supplies a default implementation of this method so for most purposes you won't need your own. - method DefaultFileNameForSplitPart - VCLZip calls this internally if you don't define your own...
been found yet. * Asynchronous targets appears to be broken in the current release. * When TDropFileTarget.GetDataOnEnter is set to True, the component doesn't work with WinZip. Although the file...
Some minor bugs that I don‘t remember fixed.- Added MIME-compliant base64 support (not for use by now). Added examples.0.9.2.1b- Fixed a bug when send a mail and the first line disappear (thanks to ...
since documentation currently lacks, please refer to the Sample Usage section below as well as the sample programs, including two for Android (FacePreview.java and RecordActivity.java), also found in...
The interface defines a standard orientation for reporting device native coordinates. When the user is viewing the device in its normal position, the coordinate origin will be at the lower left of the...
The implementation is as follows: <br>Method Description BytesPerScanLine Returns the number of bytes horizontally, taking into account the bits per pixel and 4 byte boundary padding....
Using DIB Sections in VB An Easy to Use Class for manipulating DIBSections plus a blindingly quick technique for updating the bits <br> <br> <br> Updated! 17 February 1999 The...
4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...