1. 程式人生 > >Android 4.0 framework原始碼修改編譯,模擬器執行不起來

Android 4.0 framework原始碼修改編譯,模擬器執行不起來

我是用的android 4.0.3 ICS的原始碼,編譯好後,利用編譯好的映象啟動的模擬器,以前修改過裡面的Launcher,將生成的Launcher.apk和Launcher.odex  push後是成功的。現在我在

frameworks/base/policy/src/com/android/internal/policy/impl/LockScreen.java

frameworks/base/core/java/com/android/internal/widget/multiwaveview/MultiWaveView.java

中加了一點log,其實就是解鎖時相應的輸出座標等資訊,

試了兩種方法:

1. make framework  
  make snod

2.  在framework/base中mm
  adb push framework.jar 和 framework.odex 到 system/framework/

結果都是在啟動模擬器時,在開機顯示 android字樣時進不去了,ddms中不停的列印如下資訊:

07-30 06:50:52.762: I/ServiceManager(30): service 'media.audio_policy' died
07-30 06:50:52.762: I/ServiceManager(30): service 'media.audio_flinger' died
07-30 06:50:52.762: I/ServiceManager(30): service 'media.player' died
07-30 06:50:52.762: I/ServiceManager(30): service 'media.camera' died
07-30 06:50:52.822: I/Netd(383): Netd 1.0 starting
07-30 06:50:52.842: E/Netd(383): Unable to bind netlink socket: No such file or directory
07-30 06:50:52.842: E/Netd(383): Unable to open quota2 logging socket
07-30 06:50:53.253: I/(381): ServiceManager: 0xf958
07-30 06:50:53.253: I/AudioFlinger(381): Loaded primary audio interface from LEGACY Audio HW HAL (audio)
07-30 06:50:53.253: I/AudioFlinger(381): Using 'LEGACY Audio HW HAL' (audio.primary) as the primary audio interface
07-30 06:50:53.253: D/AudioHardwareInterface(381): setMode(NORMAL)
07-30 06:50:53.253: I/CameraService(381): CameraService started (pid=381)
07-30 06:50:53.262: D/EmulatedCamera_QemuClient(381): Emulated camera list: 
07-30 06:50:53.262: D/EmulatedCamera_FakeCamera(381): Initialize: Fake camera is facing back
07-30 06:50:53.262: V/EmulatedCamera_Factory(381): 1 cameras are being emulated. Fake camera ID is 0
07-30 06:50:53.272: I/AudioFlinger(381): AudioFlinger's thread 0x10fb0 ready to run
07-30 06:50:53.272: W/AudioFlinger(381): Thread AudioOut_1 cannot connect to the power manager service
07-30 06:50:53.272: I/AudioPolicyService(381): Loaded audio policy from LEGACY Audio Policy HAL (audio_policy)
07-30 06:50:56.022: D/AndroidRuntime(393): >>>>>> AndroidRuntime START com.android.internal.os.ZygoteInit <<<<<<
07-30 06:50:56.022: D/AndroidRuntime(393): CheckJNI is ON
07-30 06:50:56.042: I/dalvikvm(393): DexOpt: mismatch dep signature for '/system/framework/framework.odex'
07-30 06:50:56.042: E/dalvikvm(393): /system/framework/android.policy.jar odex has stale dependencies
07-30 06:50:56.042: I/dalvikvm(393): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
07-30 06:50:56.042: D/dalvikvm(393): Unable to process classpath element '/system/framework/android.policy.jar'
07-30 06:50:56.042: I/dalvikvm(393): DexOpt: Some deps went away
07-30 06:50:56.042: E/dalvikvm(393): /system/framework/services.jar odex has stale dependencies
07-30 06:50:56.042: I/dalvikvm(393): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
07-30 06:50:56.042: D/dalvikvm(393): Unable to process classpath element '/system/framework/services.jar'
07-30 06:50:56.042: I/dalvikvm(393): DexOpt: mismatch dep signature for '/system/framework/framework.odex'
07-30 06:50:56.042: E/dalvikvm(393): /system/framework/apache-xml.jar odex has stale dependencies
07-30 06:50:56.042: I/dalvikvm(393): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
07-30 06:50:56.042: D/dalvikvm(393): Unable to process classpath element '/system/framework/apache-xml.jar'
07-30 06:50:56.042: I/dalvikvm(393): DexOpt: mismatch dep signature for '/system/framework/framework.odex'
07-30 06:50:56.042: E/dalvikvm(393): /system/framework/filterfw.jar odex has stale dependencies
07-30 06:50:56.042: I/dalvikvm(393): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory
07-30 06:50:56.042: D/dalvikvm(393): Unable to process classpath element '/system/framework/filterfw.jar'
07-30 06:50:56.682: E/JNIHelp(393): Native registration unable to find class 'com/android/server/Watchdog', aborting

07-30 06:50:56.682: A/libc(393): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)

後來根據高手的提示,去看 build/core/main.mk,發現裡面有個droidcore命令,

嘗試使用make droidcore編譯後,模擬器成功執行,並打印出修改的log,後來仔細分析droidcore:

755 .PHONY: droidcore

756 droidcore: files \
757     systemimage \
758     $(INSTALLED_BOOTIMAGE_TARGET) \
759     $(INSTALLED_RECOVERYIMAGE_TARGET) \
760     $(INSTALLED_USERDATAIMAGE_TARGET) \
761     $(INSTALLED_FILES_FILE)
發現一開始是執行systemimage,於是我又嘗試用make systemimage來編譯:
修改framework中原始碼,在framework/base 中mm,退至原始碼根目錄,make systemimage後,啟動模擬器,修改效果成功顯示。
Ps:
1.貌似執行make snod(systemimage no dependence)不行,看來要編上dependence才行。
2.在make systemimage 之後一定要關閉模擬器重開才行,執行adb shell stop,adb shell start也不行。

就是時間比較長,編一下要10分鐘左右。

這個解決方法貌似不錯:http://blog.csdn.net/cqupt_chen/article/details/8166090

修復framework程式碼之後,push編譯好的framework.jar和相應的odex檔案,發現開機失敗,一直在android介面迴圈

而且不停打dismatch dep :

  1. I/dalvikvm(  375): DexOpt: mismatch dep signature for '/system/framework/framework.odex'                   
  2. E/dalvikvm(  375): /system/framework/android.policy.jar odex has stale dependencies                        
  3. I/dalvikvm(  375): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory   
  4. D/dalvikvm(  375): Unable to process classpath element '/system/framework/android.policy.jar'              
  5. I/dalvikvm(  375): DexOpt: mismatch dep signature for '/system/framework/framework.odex'                   
  6. E/dalvikvm(  375): /system/framework/services.jar odex has stale dependencies                              
  7. I/dalvikvm(  375): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory   
  8. D/dalvikvm(  375): Unable to process classpath element '/system/framework/services.jar'                    
  9. I/dalvikvm(  375): DexOpt: mismatch dep signature for '/system/framework/framework.odex'                   
  10. E/dalvikvm(  375): /system/framework/apache-xml.jar odex has stale dependencies                            
  11. I/dalvikvm(  375): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory   
  12. D/dalvikvm(  375): Unable to process classpath element '/system/framework/apache-xml.jar'                  
  13. I/dalvikvm(  375): DexOpt: mismatch dep signature for '/system/framework/framework.odex'                   
  14. E/dalvikvm(  375): /system/framework/filterfw.jar odex has stale dependencies                              
  15. I/dalvikvm(  375): Zip is good, but no classes.dex inside, and no valid .odex file in the same directory   
  16. D/dalvikvm(  375): Unable to process classpath element '/system/framework/filterfw.jar'                    
  17. E/JNIHelp (  375): Native registration unable to find class 'com/android/server/Watchdog', aborting        
  18. F/libc    (  375): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)                                        
在原始碼中定位到錯誤地點(DexPrepare.cpp中)
  1. if (len != storedStrLen ||  
  2.     strcmp(cacheFileName, (constchar*) ptr) != 0)  
  3. {  
  4.     LOGI("DexOpt: mismatch dep name: '%s' vs. '%s'",  
  5.         cacheFileName, ptr);  
  6.     goto bail;  
  7. }  
  8. ptr += storedStrLen;  
  9. if (memcmp(signature, ptr, kSHA1DigestLen) != 0) {  
  10.     LOGI("DexOpt: mismatch dep signature for '%s'", cacheFileName);  
  11.     goto bail;  
  12. }  
  13. ptr += kSHA1DigestLen;  
  14. LOGV("DexOpt: dep match on '%s'", cacheFileName);  
  15. numDeps--;  
看來是依賴簽名匹配失敗.

如此看來只有兩種解決辦法:

1.用make snod命令重新編譯system.img,這樣編譯出來的system中的架包之間沒有依賴

2.修改DexPrepare.cpp中的驗證程式碼,直接跳過簽名驗證