今天遇到一个Kotlin源码编译问题。在Kotlin代码中调用AppOpsManager的setMode方法
提示error: none of the following functions can be called with the arguments supplied:
@UnsupportedAppUsage public open fun setMode(code: Int, uid: Int, packageName: String!, mode: Int): Unit defined in android.app.AppOpsManager
@SystemApi public open fun setMode(op: String!, uid: Int, packageName: String!, mode: Int): Unit defined in android.app.AppOpsManager
查看一下AppOpsManager的源码,setMode()方法已经被@UnsupportedAppUsage和@SystemApi注解声明。

在Kotlin代码调用,然后Android源码编译,报错如下:
AppUsageAccessDao.kt:150:36: error: none of the following functions can be called with the arguments supplied:
@UnsupportedAppUsage public open fun setMode(code: Int, uid: Int, packageName: String!, mode: Int): Unit defined in android.app.AppOpsManager
@SystemApi public open fun setMode(op: String!, uid: Int, packageName: String!, mode: Int): Unit defined in android.app.AppOpsManager
mAppOpsManager.setMode(
^
15:51:33 ninja failed with: exit status 1
#### failed to build some targets (30 seconds) ####
解决办法:在java代码中调用setMode,成功编译。

本文讲述了作者在使用Kotlin编写代码时遇到的AppOpsManager.setMode方法编译错误,通过对比Java调用方式,解决了在Android源码编译中关于@UnsupportedAppUsage和@SystemApi注解的调用问题。



2359

被折叠的 条评论
为什么被折叠?



