1. 程式人生 > >Android原始碼中引用@hide類出現引用異常的問題error: cannot find symbol

Android原始碼中引用@hide類出現引用異常的問題error: cannot find symbol

    自己開發的APP在Android中使用一些系統隱藏的類

    

   編譯的時候報錯,出現如下異常

error: cannot find symbol
import android.net.EthernetManager;
                  ^
  symbol:   class EthernetManager
  location: package android.net

   原因是由於app在Android.mk中配置了LOCAL_SDK_VERSION 屬性,將其去掉,然後重新編譯,出現

Warning: there were 69 unresolved references to classes or interfaces.
         You may need to add missing library jars or update their versions.
         If your code works fine without the missing classes, you can suppress
         the warnings with '-dontwarn' options.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: there were 489 instances of library classes depending on program classes.
         You must avoid such dependencies, since the program classes will
         be processed, while the library classes will remain unchanged.
         (http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
Error: Please correct the above warnings first.
build/core/java.mk:460: recipe for target 'out/target/common/obj/APPS/AP4_intermediates/proguard.classes.jar' failed

 原因是由於混淆導致的warning太多,可以在Android.mk檔案中的LOCAL_PROGUARD_FLAG_FILES指定的檔案中(如果沒有可以新增一條LOCAL_PROGUARD_FLAG_FILES屬性)忽略掉錯誤

-ignorewarnings

當然,也可以按照提示在proguard檔案中按包名忽略錯誤

#對應的warning的包名
-dontwarn com.** 

再次編譯,即可成功