今天遇到一个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,成功编译。