1

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

In Eclipse, there is a menu for adding libraries (e.g. 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).

Keale
  • 3,924
  • 3
  • 29
  • 46
David Jo
  • 11
  • 1
  • 4

4 Answers4

1

right click on project

- new -> module
- import jar/AAR package
- import select the jar file to import
- click ok -> done
Aditya Vyas-Lakhan
  • 13,409
  • 16
  • 61
  • 96
  • What I want to know is how to change the order between my custom jar and android.jar. I`ve already added my custom jar. – David Jo Oct 13 '15 at 05:41
0

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.

0

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

enter image description here

Community
  • 1
  • 1
Tanim reja
  • 2,120
  • 1
  • 16
  • 23
  • I`ve already done it. But still can not refer to the methods I added in DevicePolicyManager – David Jo Oct 13 '15 at 05:38
  • did you import your package before using it ? – Tanim reja Oct 13 '15 at 05:50
  • Of course. The package names are the exactly same because I edited default DevicePolicyManager class. – David Jo Oct 13 '15 at 06:08
  • try to clean and build your project and still its not working then raise another question... may be its another issue... Thanks – Tanim reja Oct 13 '15 at 06:11
  • That class is in my custom jar and also in default android.jar. I want to refer to my custom jar.. – David Jo Oct 13 '15 at 06:13
  • then there must be an error ( when you try to use your class in code) ... can you tell me what is it? – Tanim reja Oct 13 '15 at 06:48
  • [link](http://stackoverflow.com/questions/27441398/how-to-put-my-libraries-in-front-of-android-jar-by-editing-build-gradle-in-andro) The link is the same question as mine. – David Jo Oct 13 '15 at 07:01
0

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?)

  • Thanks for your reply, but where do I need to put that code in build.gradle? It told me that cannot resolve symbol 'options'. Please give me more details. – David Jo Oct 14 '15 at 08:55
  • It worked. But like you, Android Studio editor still shows error. – David Jo Oct 15 '15 at 06:48