当前位置: 代码迷 >> 综合 >> AndroidStudio 引用 framework.jar
  详细解决方案

AndroidStudio 引用 framework.jar

热度:0   发布时间:2024-02-13 17:33:24.0

修改最外层的 build.gradle,如下:

buildscript {repositories {google()jcenter()}dependencies {classpath "com.android.tools.build:gradle:4.0.0"classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.9"}gradle.projectsEvaluated {subprojects {//添加以下代码,使framework.jar包编译先于android.jartasks.withType(JavaCompile) {options.compilerArgs.add('-Xbootclasspath/p:libs/framework.jar')doFirst {FileCollection fc = rootProject.files("libs/framework.jar") + options.bootstrapClasspathoptions.setBootstrapClasspath(fc)}}preBuild {doLast {def rootPath = project.rootDir.absolutePathdef projectPath = project.projectDir.absolutePath.replace(rootPath, "")def imlFile = new File(getRootDir(), ".idea/modules/" + projectPath + "/" + project.name + ".iml")System.out.println("iml file: " + imlFile + ", exist: " + imlFile.exists())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"//noinspection GroovyResultOfObjectAllocationIgnorednew Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])//noinspection UnnecessaryQualifiedReferencegroovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))} catch (FileNotFoundException e) {// nop, iml not found} catch (Exception e) {// nop, iml not found}}}}}
}allprojects {repositories {google()jcenter()}
}task clean(type: Delete) {delete rootProject.buildDir
}

 

  相关解决方案