当前位置:网站首页>Android studio import customized framework classess.jar As 4.0.1 version is valid for pro test

Android studio import customized framework classess.jar As 4.0.1 version is valid for pro test

2020-11-09 12:12:00 osc_ydeb2o99

occasionally , We need to call the system framework Layer hidden interface , Or some customized interfaces , So in androidstudio Without special configuration and processing , The default preference is android sdk api. Then we need to make the following configuration :

 

step 1: stay Moudle Under the app Add below libs Folder , And put your own jar The bag is in it .

--app

--libs

---framework.jar

 

step 2: stay Moudle Under the app In the catalog build.gradle Add the following red code to the file .

dependencies {
    compileOnly  files('libs/framework.jar')
    implementation 'androidx.appcompat:appcompat:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

 

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
        }
    }
}

In fact, the above one preBuild{...} The main thing is to default to android sdk Put it at the back , This is your own framework.jar You can give priority to .

step 3: stay project In the root directory build.gradle Add the following code under the file :

 

allprojects {
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs.add('-Xbootclasspath/p:app\\libs\\framework.jar')
        }
    }
    repositories {
        google()
        jcenter()
    }
}

 

After the above steps are set , Refresh project , recompile , There may be an error when running , Tips odex beyond 65536, Generally, you need to add the following settings .

stay Module Of app Below build.gradle Found in defaultConfi Join in multiDexEnabled = true

And in dependencies Add in

implementation 'com.android.support:multidex:1.0.0'

 

版权声明
本文为[osc_ydeb2o99]所创,转载请带上原文链接,感谢