车载系统应用开发集成系统API

背景

车载开发中,我们为了快速迭代,降低开发成本,往往都会把一些系统应用,剥离出来,做成普通的应用进行开发,这样做,环境配置更简单,编译效率更高,学习成本更低,开发和调试的速度也大大提高。但是我们在开发过程不可避免需要用到某些系统的某些API,如果所有的方法都用反射的话,会大大降低开发的效率。那么我们就需要集成一些系统编译的空方法和类。但是加载这个jar包,会有很多问题。

问题

隐藏的API和systemAPI 会爆红,编译也会失败,无法引用到jar里面的内容

通用解决方法

需要在指定模块gradle中 增加如下代码,把这个jar导入到编译链中。

groovy 复制代码
allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile).tap {
            configureEach {


                List<File> newFileList = new ArrayList<>();
                //相对位置,根据存放的位置修改路径
                newFileList.add(new File("./libs/framework.jar"))


                if (options.bootstrapClasspath != null && options.bootstrapClasspath.getFiles() != null) {
                    Set<File> fileSet = options.bootstrapClasspath.getFiles()
                    newFileList.addAll(fileSet)
                }

                options.bootstrapClasspath = files(newFileList.toArray())
            }
        }
    }
}

其他问题

但是在使用更高级别的工程上的时候,我们使用了更高级别的jdk的时候,这样使用就不生效,怎么都编译不过。

解决办法

这种集成framework.jar的方式,只针对 jdk8 有效,所以必须强制指定这个module 为jdk 8。并且和其他的代码隔离。才能使用,并且吧lint编译关闭,不关注报错,才行。

groovy 复制代码
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    lintOptions {
        abortOnError false
        absolutePaths false
    }

总结

  • 需要先把jar加载到工程中
  • 然后再设置 模块的jdk
相关推荐
火柴就是我5 小时前
让我们实现一个更好看的内部阴影按钮
android·flutter
砖厂小工12 小时前
用 GLM + OpenClaw 打造你的 AI PR Review Agent — 让龙虾帮你审代码
android·github
张拭心12 小时前
春节后,有些公司明确要求 AI 经验了
android·前端·人工智能
张拭心13 小时前
Android 17 来了!新特性介绍与适配建议
android·前端
Kapaseker15 小时前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
黄林晴15 小时前
Android17 为什么重写 MessageQueue
android
阿巴斯甜2 天前
Android 报错:Zip file '/Users/lyy/develop/repoAndroidLapp/l-app-android-ble/app/bu
android
Kapaseker2 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
xq95272 天前
Andorid Google 登录接入文档
android
黄林晴2 天前
告别 Modifier 地狱,Compose 样式系统要变天了
android·android jetpack