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

最近在修改frameworks/base目录下代码的时候进行全编译,遇到了如下问题:

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.xml by executing the following command:

         make update-api

      To submit the revised current.xml to the main Android repository,

      you will need approval.

我修改的部分内容为:

/**
 * Interface for "xxx_yyy_service". 
 *
 * Note that Xxx permission is enforced in the implementation class instead.
 *
 * @hide
 */
@SystemApi
@SystemService("xxx_yyy_service")
public class XxxYyyManager {
    ......
}

以下是解决这个问题的心路历程,我的天,对frameworks不了解真的是最痛苦的一件事!!!

按照第一步,我在frameworks中添加相应类的时候有加@hide,但是还是在出现这个问题后把类中所有的方法均加上了@hide,再次编译也还是不行,报同样的问题。

接着去掉第一步,按照第二部,使用make update-api,全编译是可以通过的。

接着我删除了out目录,发现直接make也是可以编译过的。

那就感到很奇怪啊,肯定是在使用make update-api的时候系统有修改到frameworks。

果不其然,在frameworks/base/目录下使用git status查看,发现确实在frameworks/base/api/system-current.txt中有如下的修改:

package android.service.xxx{
  public class XxxxManager {
    method public java.lang.String[] getXxxxPackages(java.lang.String);
    method public java.lang.String getXxxVersion();
    method public byte[] readXxxData(int, int);
    method public boolean setXxxx(java.lang.String, java.lang.String, java.lang.String);
    method public void setUserXxxx(java.lang.String, boolean);
    method public int writeXxxxData(int, byte[]);
  }

接着我查看这个文件的提交记录,也有frameworks的同事对其修改过,也是类似的问题。比如涉及到修改这个目录下的current.txt等。

修改frameworks/base目录下代码的时候,如果涉及到修改系统原有的API(@SystemApi),就需要对frameworks/base/api/system-current.txt或是current.txt进行更新(编译报错的时候也会提示具体是哪个文件需要更新),否则就会出现以上问题。相应的,如果在全编译前不知道要做怎么修改system-current.txt文件等,可以通过执行make update-api进行自动更新,编译成功后,再查看frameworks/base/api目录下有哪些改动,检查后跟着代码一起提交就可以了。

猜你喜欢

转载自blog.csdn.net/hanhan1016/article/details/88420389