简体   繁体   中英

Is there a way to add .jar library to Android Studio just like in Eclipse?

I have searched Google for my curiosity, but I cannot get an answer.

In Eclipse, there is a menu for adding libraries (eg order and export). So, I can put the custom framework.jar before Android SDK(android.jar). Is there any way to do this in Android Studio development environment?

Just by adding .jar in libs folder, I can refer to classes which I added (not edited). But I can not refer to methods which I added in the already existing classes (for example, myMethod() in DevicePolicyManager).

right click on project

- new -> module
- import jar/AAR package
- import select the jar file to import
- click ok -> done

If you want to add just jar then add it into libs folder(If you dont have libs folder then make it in res)

If you want to add library then follow below steps

Goto File menu New-->Import module-->Select Library and finish steps.

At first put your .jar file inside lib folder. then right click and hit Add as library. and make sure that inside your gradle file under

 dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:22.0.1'
        }

write your jar file.. if its not already added. for more click

在此处输入图片说明

You can build your app if you write this in your app/build.gradle.

apply plugin: 'com.android.application'
android {
    ....
    ....
}

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs.add("-Xbootclasspath/p:${project.name}/libs/framework.jar")
    }
}

(But Android Studio editor still shows error. Is there any better solution?)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM