編輯:關於Android編程
android4.4系統解決“ERRORcouldn't find native method”方法
今天筆者在移植一個tv模塊從android4.2到android4.4系統的設備上,同樣的代碼,同樣的方法,就是運行不起來。大概方法就是上層寫一個apk,調用一個靜態的java庫,java庫加載調用JNI的庫文件,這一套代碼在4.2上都是好好的,正常能跑,移到4.4上編譯也都沒有問題,運行會出下面的問題:
/*****************************************************************************************************/
聲明:本博內容均由http://blog.csdn.net/edsam49原創,轉載請注明出處,謝謝!
/*****************************************************************************************************/
錯誤信息如下:
07-01 20:57:29.200 I/ActivityManager( 1613): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.softwinner.cvbs/.CVBS} from pid 2139 07-01 20:57:29.320 I/ActivityManager( 1613): Start proc com.softwinner.cvbs for activity com.softwinner.cvbs/.CVBS: pid=2878 uid=10022 gids={50022} 07-01 20:57:29.420 I/PackageManager( 1613): Running dexopt on: com.softwinner.cvbs 07-01 20:57:29.540 D/dalvikvm( 2891): DexOpt: load 14ms, verify+opt 41ms, 273740 bytes 07-01 20:57:29.570 V/PhoneStatusBar( 1691): setLightsOn(true) 07-01 20:57:29.800 E/dalvikvm( 2878): ERROR: couldn't find native method 07-01 20:57:29.800 E/dalvikvm( 2878): Requested: Lsoftwinner/tv/TVDecoder;.connect:(IIII)I 07-01 20:57:29.800 E/dalvikvm( 2878): JNI posting fatal error: RegisterNatives failed for 'softwinner/tv/TVDecoder'; aborting... 07-01 20:57:29.800 I/dalvikvm( 2878): "main" prio=5 tid=1 NATIVE 07-01 20:57:29.800 I/dalvikvm( 2878): | group="main" sCount=0 dsCount=0 obj=0x41533c90 self=0x4146c580 07-01 20:57:29.800 I/dalvikvm( 2878): | sysTid=2878 nice=0 sched=0/0 cgrp=apps handle=1073873236 07-01 20:57:29.810 I/dalvikvm( 2878): | state=R schedstat=( 0 0 0 ) utm=11 stm=6 core=1 07-01 20:57:29.820 I/dalvikvm( 2878): #00 pc 000012f6 /system/lib/libcorkscrew.so (unwind_backtrace_thread+29) 07-01 20:57:29.820 I/dalvikvm( 2878): #01 pc 000604ec /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+31) 07-01 20:57:29.820 I/dalvikvm( 2878): #02 pc 000544e8 /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+395) 07-01 20:57:29.820 I/dalvikvm( 2878): #03 pc 00054556 /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25) 07-01 20:57:29.820 I/dalvikvm( 2878): #04 pc 00048f90 /system/lib/libdvm.so 07-01 20:57:29.820 I/dalvikvm( 2878): #05 pc 00001fd2 /system/lib/libnativehelper.so (jniRegisterNativeMethods+81) 07-01 20:57:29.820 I/dalvikvm( 2878): #06 pc 00000ac6 /system/lib/libtvdecoder_jni.so (JNI_OnLoad+41) 07-01 20:57:29.820 I/dalvikvm( 2878): #07 pc 0004feba /system/lib/libdvm.so (dvmLoadNativeCode(char const*, Object*, char**)+465) 07-01 20:57:29.820 I/dalvikvm( 2878): #08 pc 00067590 /system/lib/libdvm.so 07-01 20:57:29.820 I/dalvikvm( 2878): #09 pc 00026f60 /system/lib/libdvm.so 07-01 20:57:29.820 I/dalvikvm( 2878): #10 pc 0002deec /system/lib/libdvm.so (dvmMterpStd(Thread*)+76) 07-01 20:57:29.820 I/dalvikvm( 2878): #11 pc 0002b598 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184) 07-01 20:57:29.820 I/dalvikvm( 2878): #12 pc 0006041e /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+337) 07-01 20:57:29.820 I/dalvikvm( 2878): #13 pc 00060442 /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, ...)+19) 07-01 20:57:29.820 I/dalvikvm( 2878): #14 pc 0006ba88 /system/lib/libdvm.so (dvmInitClass+1019) 07-01 20:57:29.820 I/dalvikvm( 2878): #15 pc 00021e5c /system/lib/libdvm.so (dvmAsmSisterStart+412) 07-01 20:57:29.820 I/dalvikvm( 2878): #16 pc 0002deec /system/lib/libdvm.so (dvmMterpStd(Thread*)+76) 07-01 20:57:29.820 I/dalvikvm( 2878): #17 pc 0002b598 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184) 07-01 20:57:29.820 I/dalvikvm( 2878): #18 pc 00060700 /system/lib/libdvm.so (dvmInvokeMethod(Object*, Method const*, ArrayObject*, ArrayObject*, ClassObject*, bool)+391) 07-01 20:57:29.820 I/dalvikvm( 2878): #19 pc 0006866e /system/lib/libdvm.so 07-01 20:57:29.820 I/dalvikvm( 2878): #20 pc 00026f60 /system/lib/libdvm.so 07-01 20:57:29.820 I/dalvikvm( 2878): #21 pc 0002deec /system/lib/libdvm.so (dvmMterpStd(Thread*)+76) 07-01 20:57:29.820 I/dalvikvm( 2878): #22 pc 0002b598 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+184) 07-01 20:57:29.820 I/dalvikvm( 2878): #23 pc 0006041e /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+337) 07-01 20:57:29.820 I/dalvikvm( 2878): #24 pc 00049bda /system/lib/libdvm.so 07-01 20:57:29.820 I/dalvikvm( 2878): #25 pc 0004ce80 /system/lib/libandroid_runtime.so 07-01 20:57:29.820 I/dalvikvm( 2878): #26 pc 0004dba6 /system/lib/libandroid_runtime.so (android::AndroidRuntime::start(char const*, char const*)+353) 07-01 20:57:29.830 I/dalvikvm( 2878): #27 pc 0000105a /system/bin/app_process 07-01 20:57:29.830 I/dalvikvm( 2878): #28 pc 0000e3e8 /system/lib/libc.so (__libc_init+47) 07-01 20:57:29.830 I/dalvikvm( 2878): at java.lang.Runtime.nativeLoad(Native Method) 07-01 20:57:29.830 I/dalvikvm( 2878): at java.lang.Runtime.doLoad(Runtime.java:421) 07-01 20:57:29.830 I/dalvikvm( 2878): at java.lang.Runtime.loadLibrary(Runtime.java:362) 07-01 20:57:29.830 I/dalvikvm( 2878): at java.lang.System.loadLibrary(System.java:526) 07-01 20:57:29.830 I/dalvikvm( 2878): at softwinner.tv.TVDecoder.(TVDecoder.java:11) 07-01 20:57:29.830 I/dalvikvm( 2878): at com.softwinner.cvbs.CVBS.onCreate(CVBS.java:-1) 07-01 20:57:29.830 I/dalvikvm( 2878): at android.app.Activity.performCreate(Activity.java:5243) 07-01 20:57:29.830 I/dalvikvm( 2878): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 07-01 20:57:29.830 I/dalvikvm( 2878): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140) 07-01 20:57:29.830 I/dalvikvm( 2878): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.j
很悲劇,老老實實查了幾遍,包引用,native名稱,jin名稱映射,編譯這些看起來都沒有問題,為什麼呢?筆者也Google了一遍,還好有一些同道中人啊!都是proguard惹的禍!因為它可能會優化掉這些jni native類,在編譯靜態java庫的時候,如果不特別指定proguard的話,會出問題,下面看看build系統的 java_library.mk文件:
ifeq ($(LOCAL_PROGUARD_ENABLED),disabled) LOCAL_PROGUARD_ENABLED := endif
ifeq ($(LOCAL_IS_STATIC_JAVA_LIBRARY),true) # No dex; all we want are the .class files with resources. $(common_javalib.jar) : $(java_resource_sources) ifdef LOCAL_PROGUARD_ENABLED $(common_javalib.jar) : $(full_classes_proguard_jar) else $(common_javalib.jar) : $(full_classes_jar) endif @echo "target Static Jar: $(PRIVATE_MODULE) ($@)" $(copy-file-to-target) ifneq ($(extra_jar_args),) $(add-java-resources-to-package) endif $(LOCAL_BUILT_MODULE): $(common_javalib.jar) $(copy-file-to-target) else # !LOCAL_IS_STATIC_JAVA_LIBRARY $(common_javalib.jar): PRIVATE_DEX_FILE := $(built_dex) $(common_javalib.jar) : $(built_dex) $(java_resource_sources) @echo "target Jar: $(PRIVATE_MODULE) ($@)" $(create-empty-package) $(add-dex-to-package) $(add-carried-java-resources) ifneq ($(extra_jar_args),) $(add-java-resources-to-package) endif ifdef LOCAL_DEX_PREOPT dexpreopt_boot_jar_module := $(filter $(LOCAL_MODULE),$(DEXPREOPT_BOOT_JARS_MODULES)) ifneq ($(dexpreopt_boot_jar_module),) # boot jar's rules are defined in dex_preopt.mk dexpreopted_boot_jar := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module)_nodex.jar $(LOCAL_BUILT_MODULE) : $(dexpreopted_boot_jar) | $(ACP) $(call copy-file-to-target) dexpreopted_boot_odex := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/$(dexpreopt_boot_jar_module).odex built_odex := $(basename $(LOCAL_BUILT_MODULE)).odex $(built_odex) : $(dexpreopted_boot_odex) | $(ACP) $(call copy-file-to-target) else # dexpreopt_boot_jar_module built_odex := $(basename $(LOCAL_BUILT_MODULE)).odex $(built_odex): PRIVATE_MODULE := $(LOCAL_MODULE) # Make sure the boot jars get dex-preopt-ed first $(built_odex) : $(DEXPREOPT_BOOT_ODEXS) $(built_odex) : $(common_javalib.jar) | $(DEXPREOPT) $(DEXOPT) @echo "Dexpreopt Jar: $(PRIVATE_MODULE) ($@)" $(hide) rm -f $@ @mkdir -p $(dir $@) $(call dexpreopt-one-file,$<,$@) $(LOCAL_BUILT_MODULE) : $(common_javalib.jar) | $(ACP) $(call copy-file-to-target) ifneq (nostripping,$(LOCAL_DEX_PREOPT)) $(call dexpreopt-remove-classes.dex,$@) endif endif # dexpreopt_boot_jar_module else # LOCAL_DEX_PREOPT $(LOCAL_BUILT_MODULE) : $(common_javalib.jar) | $(ACP) $(call copy-file-to-target) endif # LOCAL_DEX_PREOPT endif # !LOCAL_IS_STATIC_JAVA_LIBRARYLOCAL_PROGUARD_ENABLED默認是打開的,不特別指定的話,就是起作用的,就可能做優化。這個功能讓我想起來了,很早以前做很底層寄存器操作的時候,要加上volitate 來防止編譯器做優化一樣。
只需要再Makefile中加入一行即可解決。如下:
LOCAL_PROGUARD_ENABLED:= disabled
編譯還是照舊,運行還是照舊,可是就是出來了,真的不錯,沒搞清楚之前,很累人啊,加油!
相關在Android中,BroadcastReceiver是一套用來實現組件之間的通信機制,它是基於消息發布和訂閱機制,可以用在不同線程之間組件的通信,也可以跨進程進行組
1、前言webView是android中用於展示簡單的網頁或者加載一些html格式的很好的選擇,它提供了很多的操作上的封裝但同時又不失去靈活性,因為他提供了webView
Android-使用WebView顯示網頁WebView是安卓提供顯示web界面的工具類,可以像PC端的浏覽器那樣進行顯示:大致就是上圖那樣。其實也可以不用WebView
本文實例為大家分享了PopupWindow實現自定義overflow的具體代碼,供大家參考,具體內容如下當Action Bar的Action放不下時,系統會將其收集在ov