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 false
    id '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.还是标红,但是编译正常,运行正常

相关推荐
玉梅小洋41 分钟前
Windows 10 Android 构建配置指南
android·windows
Libraeking2 小时前
视觉篇:Canvas 自定义绘图与高级动画的华丽圆舞曲
android·经验分享·android jetpack
Fushize3 小时前
多模块架构下的依赖治理:如何避免 Gradle 依赖地狱
android·架构·kotlin
Jomurphys4 小时前
Kotlin - 类型别名 typealias
android·kotlin
Haha_bj4 小时前
Flutter ——flutter_screenutil 屏幕适配
android·ios
Haha_bj4 小时前
Flutter ——device_info_plus详解
android·flutter·ios
前端小伙计4 小时前
Android/Flutter 项目统一构建配置最佳实践
android·flutter
悟能不能悟5 小时前
如何打开2个notepad++
ide
Mr_sun.6 小时前
Day09——入退管理-入住-2
android·java·开发语言
wVelpro6 小时前
如何在Pycharm 2025.3 版本实现虚拟环境“Make available to all projects”
linux·ide·pycharm