本文主要是介绍Android Studio编译含有@SystemApi @UnsupportedAppUsage @Hide的属性,方法,类时报错,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题来源:用到系统方法WifiMnanger.ActionLinstener时Android Studio编译报错
环境:Android 12(S)
1.将系统编译好的framework-wifi.jar,framework-minus-apex.jar放在/app/libs/文件夹中
在App的build.gradle中加入以下代码
dependencies {...compileOnly files('libs\\framework-minus-apex.jar')compileOnly files('libs\\framework-wifi.jar')...
}
2.在项目的build.gradle中加入以下代码
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {id 'com.android.application' version '7.4.2' apply falseid 'com.android.library' version '7.4.2' apply false
}
allprojects {gradle.projectsEvaluated {tasks.withType(JavaCompile) {options.compilerArgs.add('-Xbootclasspath/p:app/libs/framework-wifi.jar')options.compilerArgs.add('-Xbootclasspath/p:app/libs/framework-minus-apex.jar')}}gradle.projectsEvaluated {tasks.withType(JavaCompile) {Set<File> fileSet = options.bootstrapClasspath.getFiles()List<File> newFileList = new ArrayList<>();newFileList.add(new File("app/libs/framework-wifi.jar"))newFileList.add(new File("app/libs/framework-minus-apex.jar"))newFileList.addAll(fileSet)options.bootstrapClasspath = files(newFileList.toArray())}}
}
3.还是标红,但是编译正常,运行正常
这篇关于Android Studio编译含有@SystemApi @UnsupportedAppUsage @Hide的属性,方法,类时报错的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!