问题来源:用到系统方法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.还是标红,但是编译正常,运行正常