framework添加api给第三方用

out_sys\soong\.intermediates\frameworks\base\framework-minus-apex\android_common\combined
获取framework.jar
build.gradle中修改

apply plugin: 'com.android.application'

android {
    compileSdkVersion 33
    defaultConfig {
        minSdkVersion 28
        targetSdkVersion 33
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            Set<File> fileSet = options.bootstrapClasspath.getFiles()
            List<File> newFileList = new ArrayList<>()
            newFileList.add(new File("libs/framework.jar"))
            newFileList.addAll(fileSet)
            options.bootstrapClasspath = files(newFileList.toArray())
        }
    }
}
repositories {
    flatDir {
        dirs 'libs'
    }
}
dependencies {
    //implementation fileTree(dir: 'libs', include: ['*.jar'])
    compileOnly files("libs/framework.jar")
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    configurations.all {
        exclude group: 'com.hikrobot.hikdevicemanager', module: 'BuildConfig'
    }
    configurations.all {
        exclude group: 'com.xunmeng.scarecrow.device_api', module: 'BuildConfig'
    }
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:26.+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
}

gradle.projectsEvaluated {
    tasks.withType(JavaCompile){
        options.compilerArgs << '-Xbootclasspath/p:app/libs/framework.jar'
    }
}

preBuild {
    doLast {
        // 注意:iml的路径要根据自己的实际情况来写
        def imlFile = file("../.idea/modules/app/My_Application.app.main.iml")
        try {
            def parsedXml = (new XmlParser()).parse(imlFile)
            def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
            parsedXml.component[1].remove(jdkNode)
            def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
            new groovy.util.Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
            groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
        } catch (FileNotFoundException e) {

        }
    }

}
preBuild {
    doLast {
        def imlFile = file(project.name + ".iml")
        println 'Change ' + project.name + '.iml order'
        try {
            def parsedXml = (new XmlParser()).parse(imlFile)
            def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' }
            parsedXml.component[1].remove(jdkNode)
            def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
            new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
            groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
        } catch (FileNotFoundException e) {
            // nop, iml not found
            }
            }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值