`

关于ANDROID NATIVE 的No implementation found for native问题

 
阅读更多

背景:搞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 串口驱动

    android 串口驱动源代码 package android.serialport; import java.io.File; import java.io.FileDescriptor; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; ...

    JavaScript Applications with Node.js, React, React Native and MongoDB

    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, ...

    Bochs - The cross platform IA-32 (x86) emulator

    - 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 ...

    Typed.PHP.Stronger.Types.For.Cleaner.Code.1484221133

    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

    acpi控制笔记本风扇转速

    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 pro v3.10.1

    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...

    Senfore_DragDrop_v4.1

    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...

    Sakemail

    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 ...

    javacv-platform-1.3.3-src

    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...

    DIBSection Class VB

    The implementation is as follows: &lt;br&gt;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

    Using DIB Sections in VB An Easy to Use Class for manipulating DIBSections plus a blindingly quick technique for updating the bits &lt;br&gt; &lt;br&gt; &lt;br&gt; Updated! 17 February 1999 The...

    DebuggingWithGDB 6.8-2008

    4.1 Compiling for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Starting your Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

Global site tag (gtag.js) - Google Analytics