烦人的Android SDK API报错

编译Android系统的时候经常会出现Check API报错的情况,特别烦人,接下来教大家如何彻底解决这个烦恼。

目录

1. 典型的SDK API报错日志

2. 新增API导致的报错

2.1. 隐藏新增的API

2.2. 更新API

3. 删除生成的API文件和时间错存根

4. API报错解决方案总结

4.1. 新增API后手动更新API或添加API隐藏声明

4.2. 删除已生成的API文件和时间戳存根使重新生成

4.3. 检查JDK版本是否匹配

4.3.1. update-alternatives命令方式配置JDK版本

4.3.2. PATH环境变量方式配置JDK版本

4.4. 重新完整编译


1. 典型的SDK API报错日志

先贴一段编译报错,如果你的错误类似,可以继续阅读后面的文字

Checking API: checkpublicapi-last
Checking API: checkpublicapi-current
Checking API: checksystemapi-last
Checking API: checksystemapi-current
target Static Jar: android-support-v13 (out/target/common/obj/JAVA_LIBRARIES/android-support-v13_intermediates/javalib.jar)
target Java: android-ex-camera2-utils (out/target/common/obj/JAVA_LIBRARIES/android-ex-camera2-utils_intermediates/classes)
target Java: glide (out/target/common/obj/JAVA_LIBRARIES/glide_intermediates/classes)
target Java: DocumentsUI (out/target/common/obj/APPS/DocumentsUI_intermediates/classes)
target Java: LatinIME (out/target/common/obj/APPS/LatinIME_intermediates/classes)
prebuilts/sdk/api/22.txt:8: error 9: Removed public constructor Manifest.permission()
prebuilts/sdk/api/22.txt:164: error 9: Removed public constructor Manifest.permission_group()
prebuilts/sdk/api/22.txt:203: error 9: Removed public constructor R.anim()
prebuilts/sdk/api/22.txt:220: error 9: Removed public constructor R.animator()
prebuilts/sdk/api/22.txt:226: error 9: Removed public constructor R.array()
prebuilts/sdk/api/22.txt:235: error 9: Removed public constructor R.attr()
prebuilts/sdk/api/22.txt:1442: error 9: Removed public constructor R.bool()
prebuilts/sdk/api/22.txt:1446: error 9: Removed public constructor R.color()
prebuilts/sdk/api/22.txt:1478: error 9: Removed public constructor R.dimen()
prebuilts/sdk/api/22.txt:1489: error 9: Removed public constructor R.drawable()
prebuilts/sdk/api/22.txt:1667: error 9: Removed public constructor R.fraction()
prebuilts/sdk/api/22.txt:1671: error 9: Removed public constructor R.id()
prebuilts/sdk/api/22.txt:1724: error 9: Removed public constructor R.integer()
prebuilts/sdk/api/22.txt:1732: error 9: Removed public constructor R.interpolator()
prebuilts/sdk/api/22.txt:1752: error 9: Removed public constructor R.layout()
prebuilts/sdk/api/22.txt:1780: error 9: Removed public constructor R.menu()
prebuilts/sdk/api/22.txt:1784: error 9: Removed public constructor R.mipmap()
prebuilts/sdk/api/22.txt:1789: error 9: Removed public constructor R.plurals()
prebuilts/sdk/api/22.txt:1793: error 9: Removed public constructor R.raw()
prebuilts/sdk/api/22.txt:1797: error 9: Removed public constructor R.string()
prebuilts/sdk/api/22.txt:1825: error 9: Removed public constructor R.style()
prebuilts/sdk/api/22.txt:2548: error 9: Removed public constructor R.transition()
prebuilts/sdk/api/22.txt:2560: error 9: Removed public constructor R.xml()
prebuilts/sdk/api/22.txt:3228: error 9: Removed public constructor ActionBar.LayoutParams(Context,AttributeSet)
prebuilts/sdk/api/22.txt:3229: error 9: Removed public constructor ActionBar.LayoutParams(int,int)
prebuilts/sdk/api/22.txt:3230: error 9: Removed public constructor ActionBar.LayoutParams(int,int,int)
prebuilts/sdk/api/22.txt:3231: error 9: Removed public constructor ActionBar.LayoutParams(int)
prebuilts/sdk/api/22.txt:3232: error 9: Removed public constructor ActionBar.LayoutParams(LayoutParams)
prebuilts/sdk/api/22.txt:3233: error 9: Removed public constructor ActionBar.LayoutParams(LayoutParams)
prebuilts/sdk/api/22.txt:3246: error 9: Removed public constructor ActionBar.Tab()
prebuilts/sdk/api/22.txt:3539: error 9: Removed public constructor ActivityManager.MemoryInfo()
prebuilts/sdk/api/22.txt:3551: error 9: Removed public constructor ActivityManager.ProcessErrorStateInfo()
prebuilts/sdk/api/22.txt:3571: error 9: Removed public constructor ActivityManager.RecentTaskInfo()
prebuilts/sdk/api/22.txt:3586: error 9: Removed public constructor ActivityManager.RunningAppProcessInfo()
prebuilts/sdk/api/22.txt:3587: error 9: Removed public constructor ActivityManager.RunningAppProcessInfo(String,int,String)
prebuilts/sdk/api/22.txt:3615: error 9: Removed public constructor ActivityManager.RunningServiceInfo()
prebuilts/sdk/api/22.txt:3641: error 9: Removed public constructor ActivityManager.RunningTaskInfo()
prebuilts/sdk/api/22.txt:3656: error 9: Removed public constructor ActivityManager.TaskDescription(String,Bitmap,int)
prebuilts/sdk/api/22.txt:3657: error 9: Removed public constructor ActivityManager.TaskDescription(String,Bitmap)
prebuilts/sdk/api/22.txt:3658: error 9: Removed public constructor ActivityManager.TaskDescription(String)
prebuilts/sdk/api/22.txt:3659: error 9: Removed public constructor ActivityManager.TaskDescription()
prebuilts/sdk/api/22.txt:3660: error 9: Removed public constructor ActivityManager.TaskDescription(TaskDescription)
prebuilts/sdk/api/22.txt:3705: error 9: Removed public constructor AlarmManager.AlarmClockInfo(long,PendingIntent)
prebuilts/sdk/api/22.txt:3743: error 9: Removed public constructor AlertDialog.Builder(Context)
prebuilts/sdk/api/22.txt:3744: error 9: Removed public constructor AlertDialog.Builder(Context,int)
prebuilts/sdk/api/22.txt:3866: error 9: Removed public constructor ApplicationErrorReport.AnrInfo()
prebuilts/sdk/api/22.txt:3867: error 9: Removed public constructor ApplicationErrorReport.AnrInfo(Parcel)
prebuilts/sdk/api/22.txt:3876: error 9: Removed public constructor ApplicationErrorReport.BatteryInfo()
prebuilts/sdk/api/22.txt:3877: error 9: Removed public constructor ApplicationErrorReport.BatteryInfo(Parcel)
prebuilts/sdk/api/22.txt:3887: error 9: Removed public constructor ApplicationErrorReport.CrashInfo()
prebuilts/sdk/api/22.txt:3888: error 9: Removed public constructor ApplicationErrorReport.CrashInfo(Throwable)
prebuilts/sdk/api/22.txt:3889: error 9: Removed public constructor ApplicationErrorReport.CrashInfo(Parcel)
prebuilts/sdk/api/22.txt:3902: error 9: Removed public constructor ApplicationErrorReport.RunningServiceInfo()
prebuilts/sdk/api/22.txt:3903: error 9: Removed public constructor ApplicationErrorReport.RunningServiceInfo(Parcel)
......
......
prebuilts/sdk/api/22.txt:49836: error 9: Removed public constructor ThreadPoolExecutor.AbortPolicy()
prebuilts/sdk/api/22.txt:49841: error 9: Removed public constructor ThreadPoolExecutor.CallerRunsPolicy()
prebuilts/sdk/api/22.txt:49846: error 9: Removed public constructor ThreadPoolExecutor.DiscardOldestPolicy()
prebuilts/sdk/api/22.txt:49851: error 9: Removed public constructor ThreadPoolExecutor.DiscardPolicy()
prebuilts/sdk/api/22.txt:50118: error 9: Removed public constructor AbstractQueuedLongSynchronizer.ConditionObject()
prebuilts/sdk/api/22.txt:50165: error 9: Removed public constructor AbstractQueuedSynchronizer.ConditionObject()
prebuilts/sdk/api/22.txt:50260: error 9: Removed public constructor ReentrantReadWriteLock.ReadLock(ReentrantReadWriteLock)
prebuilts/sdk/api/22.txt:50270: error 9: Removed public constructor ReentrantReadWriteLock.WriteLock(ReentrantReadWriteLock)
prebuilts/sdk/api/22.txt:50309: error 9: Removed public constructor Attributes.Name(String)
prebuilts/sdk/api/22.txt:51639: error 9: Removed public constructor PSource.PSpecified(byte)
prebuilts/sdk/api/22.txt:56296: error 9: Removed public constructor SingleClientConnManager.ConnAdapter(PoolEntry,HttpRoute)
prebuilts/sdk/api/22.txt:56300: error 9: Removed public constructor SingleClientConnManager.PoolEntry()

******************************
You have tried to change the API from what has been previously released in
an SDK.  Please fix the errors listed above.
******************************


build/core/tasks/apicheck.mk:46: recipe for target 'out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp] Error 38
make: *** Waiting for unfinished jobs....
prebuilts/sdk/system-api/22.txt:8: error 9: Removed public constructor Manifest.permission()
prebuilts/sdk/system-api/22.txt:233: error 9: Removed public constructor Manifest.permission_group()
prebuilts/sdk/system-api/22.txt:272: error 9: Removed public constructor R.anim()
prebuilts/sdk/system-api/22.txt:289: error 9: Removed public constructor R.animator()
prebuilts/sdk/system-api/22.txt:295: error 9: Removed public constructor R.array()
prebuilts/sdk/system-api/22.txt:305: error 9: Removed public constructor R.attr()
prebuilts/sdk/system-api/22.txt:1516: error 9: Removed public constructor R.bool()
prebuilts/sdk/system-api/22.txt:1520: error 9: Removed public constructor R.color()
prebuilts/sdk/system-api/22.txt:1552: error 9: Removed public constructor R.dimen()
prebuilts/sdk/system-api/22.txt:1563: error 9: Removed public constructor R.drawable()
prebuilts/sdk/system-api/22.txt:1741: error 9: Removed public constructor R.fraction()
prebuilts/sdk/system-api/22.txt:1745: error 9: Removed public constructor R.id()
prebuilts/sdk/system-api/22.txt:1798: error 9: Removed public constructor R.integer()
prebuilts/sdk/system-api/22.txt:1806: error 9: Removed public constructor R.interpolator()
prebuilts/sdk/system-api/22.txt:1826: error 9: Removed public constructor R.layout()
prebuilts/sdk/system-api/22.txt:1854: error 9: Removed public constructor R.menu()
prebuilts/sdk/system-api/22.txt:1858: error 9: Removed public constructor R.mipmap()
prebuilts/sdk/system-api/22.txt:1863: error 9: Removed public constructor R.plurals()
prebuilts/sdk/system-api/22.txt:1867: error 9: Removed public constructor R.raw()
prebuilts/sdk/system-api/22.txt:1873: error 9: Removed public constructor R.string()
prebuilts/sdk/system-api/22.txt:1901: error 9: Removed public constructor R.style()
prebuilts/sdk/system-api/22.txt:2625: error 9: Removed public constructor R.transition()
prebuilts/sdk/system-api/22.txt:2637: error 9: Removed public constructor R.xml()
prebuilts/sdk/system-api/22.txt:3305: error 9: Removed public constructor ActionBar.LayoutParams(Context,AttributeSet)
prebuilts/sdk/system-api/22.txt:3306: error 9: Removed public constructor ActionBar.LayoutParams(int,int)
prebuilts/sdk/system-api/22.txt:3307: error 9: Removed public constructor ActionBar.LayoutParams(int,int,int)
prebuilts/sdk/system-api/22.txt:3308: error 9: Removed public constructor ActionBar.LayoutParams(int)
prebuilts/sdk/system-api/22.txt:3309: error 9: Removed public constructor ActionBar.LayoutParams(LayoutParams)
prebuilts/sdk/system-api/22.txt:3310: error 9: Removed public constructor ActionBar.LayoutParams(LayoutParams)
prebuilts/sdk/system-api/22.txt:3323: error 9: Removed public constructor ActionBar.Tab()
prebuilts/sdk/system-api/22.txt:3627: error 9: Removed public constructor ActivityManager.MemoryInfo()
prebuilts/sdk/system-api/22.txt:3639: error 9: Removed public constructor ActivityManager.ProcessErrorStateInfo()
prebuilts/sdk/system-api/22.txt:3659: error 9: Removed public constructor ActivityManager.RecentTaskInfo()
prebuilts/sdk/system-api/22.txt:3674: error 9: Removed public constructor ActivityManager.RunningAppProcessInfo()
prebuilts/sdk/system-api/22.txt:3675: error 9: Removed public constructor ActivityManager.RunningAppProcessInfo(String,int,String)
prebuilts/sdk/system-api/22.txt:3703: error 9: Removed public constructor ActivityManager.RunningServiceInfo()
prebuilts/sdk/system-api/22.txt:3729: error 9: Removed public constructor ActivityManager.RunningTaskInfo()
prebuilts/sdk/system-api/22.txt:3744: error 9: Removed public constructor ActivityManager.TaskDescription(String,Bitmap,int)
prebuilts/sdk/system-api/22.txt:3745: error 9: Removed public constructor ActivityManager.TaskDescription(String,Bitmap)
prebuilts/sdk/system-api/22.txt:3746: error 9: Removed public constructor ActivityManager.TaskDescription(String)
prebuilts/sdk/system-api/22.txt:3747: error 9: Removed public constructor ActivityManager.TaskDescription()
prebuilts/sdk/system-api/22.txt:3748: error 9: Removed public constructor ActivityManager.TaskDescription(TaskDescription)
prebuilts/sdk/system-api/22.txt:3794: error 9: Removed public constructor AlarmManager.AlarmClockInfo(long,PendingIntent)
prebuilts/sdk/system-api/22.txt:3832: error 9: Removed public constructor AlertDialog.Builder(Context)
prebuilts/sdk/system-api/22.txt:3833: error 9: Removed public constructor AlertDialog.Builder(Context,int)
prebuilts/sdk/system-api/22.txt:3956: error 9: Removed public constructor ApplicationErrorReport.AnrInfo()
prebuilts/sdk/system-api/22.txt:3957: error 9: Removed public constructor ApplicationErrorReport.AnrInfo(Parcel)
prebuilts/sdk/system-api/22.txt:3966: error 9: Removed public constructor ApplicationErrorReport.BatteryInfo()
prebuilts/sdk/system-api/22.txt:3967: error 9: Removed public constructor ApplicationErrorReport.BatteryInfo(Parcel)
......
......
prebuilts/sdk/system-api/22.txt:52639: error 9: Removed public constructor AbstractQueuedLongSynchronizer.ConditionObject()
prebuilts/sdk/system-api/22.txt:52686: error 9: Removed public constructor AbstractQueuedSynchronizer.ConditionObject()
prebuilts/sdk/system-api/22.txt:52781: error 9: Removed public constructor ReentrantReadWriteLock.ReadLock(ReentrantReadWriteLock)
prebuilts/sdk/system-api/22.txt:52791: error 9: Removed public constructor ReentrantReadWriteLock.WriteLock(ReentrantReadWriteLock)
prebuilts/sdk/system-api/22.txt:52830: error 9: Removed public constructor Attributes.Name(String)
prebuilts/sdk/system-api/22.txt:54160: error 9: Removed public constructor PSource.PSpecified(byte)
prebuilts/sdk/system-api/22.txt:58817: error 9: Removed public constructor SingleClientConnManager.ConnAdapter(PoolEntry,HttpRoute)
prebuilts/sdk/system-api/22.txt:58821: error 9: Removed public constructor SingleClientConnManager.PoolEntry()

******************************
You have tried to change the API from what has been previously released in
an SDK.  Please fix the errors listed above.
******************************


build/core/tasks/apicheck.mk:92: recipe for target 'out/target/common/obj/PACKAGING/checksystemapi-last-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checksystemapi-last-timestamp] Error 38
Note: external/glide/library/src/main/java/com/bumptech/glide/request/target/ViewTarget.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: frameworks/base/packages/DocumentsUI/src/com/android/documentsui/ProviderExecutor.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

一大堆错误,无从下手的时候非常烦恼!

2. 新增API导致的报错

之前其实修改framework代码的时候有遇到过类似的问题,报错打印中还会夹带如下日志:

******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.

   2) You can update current.txt by executing the following command:
         make update-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************

这种错误解决方式很明确,如果你正在尝试更改API,那么建议你增加 "@hide"的注释来显示隐藏你的接口,或者通过make update-api命令来更新api。

2.1. 隐藏新增的API

增加 "@hide"的方式参考如下:frameworks/multidex/library/test/src/android/util/Log.java

    /** @hide */ public static final int LOG_ID_CRASH = 4;

    /** @hide */ @SuppressWarnings("unused")
    public static int println(int bufID,
            int priority, String tag, String msg) {
        return 0;
    }

2.2. 更新API

TOP目录直接执行:

make update-api

但是当前我遇到的问题,我很明确,我并没有修改过framework中的任何代码,没有增加过任何新的属性或者方法,接下来我该怎么办呢?尝试过执行make update-api && make ,发现仍然报错;尝试先执行make installclean && make,还是报错。这就相当痛苦了,总不能把out目录整个清理掉,重新开始编译吧,make clean && make。清理掉out目录,然后重编,也是可以解决问题的。如果你电脑配置比较高,并且你有时间去这么做的话。遇到解决不了的又很怪异的问题,都可以make clean && make来重编。

3. 删除生成的API文件和时间错存根

从打印中我找到了几处这样的打印:

build/core/tasks/apicheck.mk:46: recipe for target 'out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp] Error 38

从命名上可以看到这是一个时间戳,应该是编译用来检查上次是什么时候检查过api的一个东西。如果我想单独让系统重新帮我生成这些api的obj文件,是否就可以解决问题呢?

接下来查检查一下out/target/common/obj/PACKAGING/这个目录

$ ls out/target/common/obj/PACKAGING/
boot-jars-package-check_intermediates  checkpublicapi-last-timestamp     checksystemapi-last-timestamp  removed.txt     system-removed.txt
checkpublicapi-current-timestamp       checksystemapi-current-timestamp  public_api.txt                 system-api.txt

果然都在这里,很好,不管三七二十一全部删掉他们,或做个备份再删,大不了完整地重新编译一遍系统

rm out/target/common/obj/PACKAGING/checksystemapi-current-timestamp
rm out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp
rm out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp
rm out/target/common/obj/PACKAGING/checksystemapi-last-timestamp
rm out/target/common/obj/PACKAGING/public_api.txt
rm out/target/common/obj/PACKAGING/system-api.txt
rm out/target/common/obj/PACKAGING/system-removed.txt
rm out/target/common/obj/PACKAGING/removed.txt

删完之后再来编译一遍,发现如下报错:

Checking API: checkpublicapi-last
Checking API: checkpublicapi-current
Checking API: checksystemapi-last
Checking API: checksystemapi-current
Install: out/target/product/xxxxx/system/lib/libc.so
target thumb C: init <= system/core/init/builtins.c
target thumb C: init <= system/core/init/init.c
target thumb C: init <= system/core/init/devices.c
target thumb C: init <= system/core/init/property_service.c
system/core/init/devices.c: In function 'handle_generic_device_event':
system/core/init/devices.c:761:10: warning: 'kernel_logger' is deprecated (declared at system/core/init/devices.c:670) [-Wdeprecated-declarations]
          kernel_logger();
          ^
target thumb C: init <= system/core/init/util.c
target thumb C: init <= system/core/init/parser.c
com.google.doclava.apicheck.ApiParseException: Could not open file for parsing: out/target/common/obj/PACKAGING/public_api.txt
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:141)
        at com.google.doclava.apicheck.ApiCheck.checkApi(ApiCheck.java:113)
        at com.google.doclava.apicheck.ApiCheck.main(ApiCheck.java:67)
Caused by: java.io.FileNotFoundException: out/target/common/obj/PACKAGING/public_api.txt (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at java.io.FileInputStream.<init>(FileInputStream.java:101)
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:139)
        ... 2 more
Error parsing API

******************************
You have tried to change the API from what has been previously released in
an SDK.  Please fix the errors listed above.
******************************


build/core/tasks/apicheck.mk:46: recipe for target 'out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp] Error 38
make: *** Waiting for unfinished jobs....
target thumb C: init <= system/core/init/keychords.c
com.google.doclava.apicheck.ApiParseException: Could not open file for parsing: out/target/common/obj/PACKAGING/public_api.txt
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:141)
        at com.google.doclava.apicheck.ApiCheck.checkApi(ApiCheck.java:113)
        at com.google.doclava.apicheck.ApiCheck.main(ApiCheck.java:67)
Caused by: java.io.FileNotFoundException: out/target/common/obj/PACKAGING/public_api.txt (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
com.google.doclava.apicheck.ApiParseException: Could not open file for parsing: out/target/common/obj/PACKAGING/system-api.txt
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:141)
        at com.google.doclava.apicheck.ApiCheck.checkApi(ApiCheck.java:113)
        at com.google.doclava.apicheck.ApiCheck.main(ApiCheck.java:67)
Caused by: java.io.FileNotFoundException: out/target/common/obj/PACKAGING/system-api.txt (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at java.io.FileInputStream.<init>(FileInputStream.java:101)
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:139)
        ... 2 more
Error parsing API
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at java.io.FileInputStream.<init>(FileInputStream.java:101)
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:139)
        ... 2 more
Error parsing API

******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.

   2) You can update current.txt by executing the following command:
         make update-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************



build/core/tasks/apicheck.mk:62: recipe for target 'out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp] Error 38

******************************
You have tried to change the API from what has been previously released in
an SDK.  Please fix the errors listed above.
******************************


build/core/tasks/apicheck.mk:92: recipe for target 'out/target/common/obj/PACKAGING/checksystemapi-last-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checksystemapi-last-timestamp] Error 38
com.google.doclava.apicheck.ApiParseException: Could not open file for parsing: out/target/common/obj/PACKAGING/system-api.txt
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:141)
        at com.google.doclava.apicheck.ApiCheck.checkApi(ApiCheck.java:113)
        at com.google.doclava.apicheck.ApiCheck.main(ApiCheck.java:67)
Caused by: java.io.FileNotFoundException: out/target/common/obj/PACKAGING/system-api.txt (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at java.io.FileInputStream.<init>(FileInputStream.java:101)
        at com.google.doclava.apicheck.ApiCheck.parseApi(ApiCheck.java:139)
        ... 2 more
Error parsing API

******************************
You have tried to change the API from what has been previously approved.

To make these errors go away, you have two choices:
   1) You can add "@hide" javadoc comments to the methods, etc. listed in the
      errors above.

   2) You can update current.txt by executing the following command:
         make update-api

      To submit the revised current.txt to the main Android repository,
      you will need approval.
******************************



build/core/tasks/apicheck.mk:108: recipe for target 'out/target/common/obj/PACKAGING/checksystemapi-current-timestamp' failed
make: *** [out/target/common/obj/PACKAGING/checksystemapi-current-timestamp] Error 38

很明显,刚才的api文件被删掉了,这里没有自动生成,所以会报错找不到,是不是还有其他类似的标识用来标识是否需要重新生成javadoc,也许有呢?在out/target/common/目录下找找看,我发现了out/target/common/docs/目录,并且在这个目录下有如下文件:

$ ls out/target/common/docs/
api-stubs-timestamp  doc-comment-check  doc-comment-check-timestamp  system-api-stubs-timestamp

两个api相关的存根时间戳,不要犹豫果断删掉他们:

rm out/target/common/docs/system-api-stubs-timestamp
rm out/target/common/docs/api-stubs-timestamp

接下来编译就很顺利地进行了,编译打印中出现了如下打印:

Docs droiddoc: out/target/common/docs/api-stubs
Docs droiddoc: out/target/common/docs/system-api-stubs

4. API报错解决方案总结

总结一下上面遇到的API报错的解决方法:

4.1. 新增API后手动更新API或添加API隐藏声明

更新framework代码之后,有可能需要更新api,通过执行update-api的命令进行更新即可

make update-api

如果包含需要隐藏的接口或属性也可以添加 /** @hide */注释来声明。这种情况下一般只会报几个错误而已,不会出现大量的错误。

4.2. 删除已生成的API文件和时间戳存根使重新生成

如果并没有修改framework代码,或者执行update-api的命令后仍然无法解决的话,首先你可以把api文件还原一下,不需要做update-api,撤销如下文件在update-api过程中自动做的修改:

        modified:   frameworks/base/api/current.txt
        modified:   frameworks/base/api/system-current.txt

然后删除api的存根时间戳和obj文件,让编译自动重新生成这些文件:

rm out/target/common/docs/system-api-stubs-timestamp
rm out/target/common/docs/api-stubs-timestamp

rm out/target/common/obj/PACKAGING/checksystemapi-current-timestamp
rm out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp
rm out/target/common/obj/PACKAGING/checkpublicapi-last-timestamp
rm out/target/common/obj/PACKAGING/checksystemapi-last-timestamp
rm out/target/common/obj/PACKAGING/public_api.txt
rm out/target/common/obj/PACKAGING/system-api.txt
rm out/target/common/obj/PACKAGING/system-removed.txt
rm out/target/common/obj/PACKAGING/removed.txt

之后重新编译Android。

4.3. 检查JDK版本是否匹配

JDK版本必须和Android SDK版本匹配

$ javac -version
javac 1.7.0_161

Android L(SDK API21)以下使用JDK 1.6,Android M(SDK API23)及以上使用JDK 1.8,Android L使用JDK 1.7,

详细的版本对应关系大家可以从网上找到,或者对应的项目编译文档里面会有说明。具体安装说明这里也不介绍了。

版本需要匹配如果不匹配的话,生成public_api.txt等api文档时就有可能报API错误。

4.3.1. update-alternatives命令方式配置JDK版本

如果不一致的话,先安装对应的版本,然后通过命令来切换到对应的版本:

$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config javaws
$ sudo update-alternatives --config jar
$ sudo update-alternatives --config javadoc
$ sudo update-alternatives --config javap (EDIT - This is needed to compile Kit Kat 4.4)

4.3.2. PATH环境变量方式配置JDK版本

通过设置环境变量来设置对应的版本,下面以切换JDK 1.7和1.8的版本为例

切换JDK 1.8

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

切换JDK 1.7

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar

切换完成之后按照2的方式清理下部分文件之后就可以正常编译了

4.4. 重新完整编译

如果仍然无法解决的话,只能清理out目录,重新完整地编译一遍了:

make clean && make -j8

如果以上方式还不能帮你解决问题的话,可以把错误贴在评论里面。

  • 8
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
如果你的应用程序的targetSdkVersion设置为26或更高版本,你可能会遇到以下两个错误: 1. java.lang.IllegalStateException: Only fullscreen opaque activities can request orientation 这个错误是由于在Android 8.0(API级别26)中,只有全屏不透明的活动才能请求方向更改。如果你的应用程序中的活动不是全屏和不透明的,则需要更改代码以适应这种变化。 解决方案:在AndroidManifest.xml文件中的相应活动中添加以下属性: ``` android:windowFullscreen="true" android:windowContentOverlay="@null" ``` 2. android.os.FileUriExposedException: file:///storage/emulated/0/your_app_folder/your_file exposed beyond app through ClipData.Item.getUri() 这个错误是由于在Android 7.0(API级别24)及更高版本中,应用程序不再允许在共享URI时向外公开file:// URI。相反,你应该使用FileProvider API来共享文件。 解决方案:使用FileProvider API来共享文件。你可以在你的AndroidManifest.xml文件中定义一个FileProvider,然后使用它来共享文件。以下是一个示例: 在AndroidManifest.xml文件中添加以下代码: ``` <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:grantUriPermissions="true" android:exported="false"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider> ``` 在res/xml/文件夹中创建一个file_paths.xml文件,并添加以下代码: ``` <paths xmlns:android="http://schemas.android.com/apk/res/android"> <external-path name="external_files" path="." /> </paths> ``` 然后,你可以使用以下代码来获取共享文件的URI: ``` File file = new File(Environment.getExternalStorageDirectory(), "your_app_folder/your_file"); Uri uri = FileProvider.getUriForFile(this, BuildConfig.APPLICATION_ID + ".fileprovider", file); ``` 请注意,这只是解决这两个常见错误的基本解决方案。如果你仍然遇到其他问题,请查看Android文档或在Stack Overflow上寻求帮助。
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值