androidandroid-studioframeworksandroid-studio-arctic-fox

how to let 'framework.jar' compile in front of 'android.jar' on Android Studio Arctic Fox


First, how to let the framework.jar compile in front of android.jar on Android-Studio-Arctic-Fox with gradle 7.0.2 and AGP-7.0.2 Second is let Editor first to import from the framework.jar to fix it not display RED(cannot find some method or field or class)

i use below just work on jvm1.8

def addFrameworkJarToCompile(CompileOptions options) {
    if (options.bootstrapClasspath == null) return
    Set<File> fileSet = options.bootstrapClasspath.getFiles()
    List<File> newFileList =  new ArrayList<>()
    File frameworkFile = new File(rootDir, "../libs/framework.jar")
    newFileList.add(frameworkFile)
    newFileList.addAll(fileSet)
    options.bootstrapClasspath = files(newFileList.toArray())
}

how it works on jvm1.8+?


Solution

  • It is currently not possible to override android.jar with classes from a custom jar - https://issuetracker.google.com/167750503. However, you could replace android.jar in the Android SDK with your own, and Android Studio and Android Gradle plugin will pick them up.

    Alternatively, you can develop Sdk Add-on, and point your users to it. It will be automatically handled by Android Studio. Here is an example of how to build one.