android9反射失败api被隐藏了,修改源码后报:You have tried to change the API from what has been previously approved.
android 反射创建SharedMemory对象
Class<?> clz = Class.forName("android.os.SharedMemory");
Object sharedMemory = InvokeUtil.newInstanceOrThrow(clz, fileDescriptor);
而本次设备为android 9,系统隐藏了API
直接android9系统源码修改SharedMemory构造方法为public后编码报错
Users are strongly recommended to migrate to the new APIs.
DroidDoc took 10 sec. to write docs to out/target/common/docs/api-stubs
[ 91% 12982/14238] Docs droiddoc: out/target/common/docs/system-api-stubs
javadoc: warning - The old Doclet and Taglet APIs in the packages
com.sun.javadoc, com.sun.tools.doclets and their implementations
are planned to be removed in a future JDK release. These
components have been superseded by the new APIs in jdk.javadoc.doclet.
Users are strongly recommended to migrate to the new APIs.
DroidDoc took 11 sec. to write docs to out/target/common/docs/system-api-stubs
[ 91% 12985/14238] Checking API: checkpublicapi-current
FAILED: out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp
/bin/bash -c "(( out/host/linux-x86/bin/apicheck -JXmx1024m -J\"classpath out/host/linux-x86/framework/doclava.jar:out/host/linux-x86/framework/jsilver.jar:prebuilts/jdk/jdk8/linux-x86/lib/tools.jar:)\" -error 2 -error 3 -error 4 -error 5 -error 6 -error 7 -error 8 -error 9 -error 10 -error 11 -error 12 -error 13 -error 14 -error 15 -error 16 -error 17 -error 18 -error 19 -error 20 -error 21 -error 23 -error 24 -error 25 -error 26 -error 27 frameworks/base/api/current.txt out/target/common/obj/PACKAGING/public_api.txt frameworks/base/api/removed.txt out/target/common/obj/PACKAGING/removed.txt || ( cat build/make/core/apicheck_msg_current.txt ; exit 38 ) ) ) && (mkdir -p out/target/common/obj/PACKAGING/ ) && (touch out/target/common/obj/PACKAGING/checkpublicapi-current-timestamp )"
out/target/common/obj/PACKAGING/public_api.txt:33314: error 4: Added public constructor android.os.SharedMemory.SharedMemory(FileDescriptor)
******************************
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.
******************************
大致意思是
1. 在你添加的API或者变量前面,(在java类中找到自己定义的变量)增加javadoc 注释@hide。但是要注意的是,并不是简单写个@hide 或者 /*@hide*/ 就可以了,这些都是错误的javadoc注释格式,标准的javadoc都是这样的 /** */ 而且对于 format 变量 应该加上 { }。
所以我们应该这样写 /** {@hide} */
2. 你就是想要生成的javadoc里面出现这个方法或者变量,你必须输入:
make update-api
执行: make update-api ;
在base库下面会产生“.current.txt”文件的差异
再次执行make -j40 编译通过
编译后class文件在
/out/target/common/obj/JAVA_LIBRARIES/android_system_stubs_current_intermediates/classes/android/os/SharedMemory.class
找到对应版本的android.jar包准备替换
就获取成功了