Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android 全工程編譯失敗常見問題整理

編輯:關於 Android 程式設計

在編譯 Android 全原始碼時,難免會遇到各種報錯。以下整理兩個較為典型的問題與對應的解法,供大家參考。

問題一:Module 使用了 'user' tag 導致中斷

編譯時可能出現類似以下的錯誤日誌:

frameworks/hwext/Android.mk:167: ...libfm_common_hal
build/core/base_rules.mk:64: *** Module name: libfwoeminfo_jni
build/core/base_rules.mk:65: *** Makefile location: frameworks/hwext/k3v2oem1/src/com/huawei/android/hardware/oeminfo/jni/Android.mk
* Module is attempting to use the 'user' tag.  This
* used to cause the module to be installed automatically.
* Now, the module must be listed in the PRODUCT_PACKAGES
* section of a product makefile to have it installed.
*** user tag detected on module..  Stop.
build: make error

解決辦法:將對應 mk 檔案中的 LOCAL_MODULE_TAGS := user 修改為 LOCAL_MODULE_TAGS := eng 即可。

問題二:finalize() 方法未捕捉或宣告例外

另一種常見報錯如下:

packages/apps/Bluetooth/src/com/broadcom/bt/service/ftp/FTPService.java:345: unreported exception java.lang.Throwable; must be caught or declared to be thrown
        super.finalize();
                      ^

解決辦法:為原本的 finalize() 方法加上 try...catch 結構,並在 finally 區塊中呼叫 super.finalize(),確保例外被妥善處理。示例如下:

@Override
 protected void finalize() throws Throwable {
   try {
     if(V) {
       synchronized (FTPService.class) {
         Log.d(TAG, "FINALIZED. Class= " + this);
       }
     }
   } catch (Throwable t) {
     throw t;
   } finally {
     super.finalize();
   }
 }

這兩類問題在 Android 全工程編譯中相當常見,掌握後可大幅減少排錯時間。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved