Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
942 views
in Technique[技术] by (71.8m points)

importing jar libraries into android-studio

android-studio 0.2.7
Fedora 18

Hello,

I am trying to add the jtwitter jar to my project.

First I tried doing the following:

1) Drag the jtwitter.jar into the root directory of my project explorer, see picture
2) File | project structure
3) Modules | yamba-yamba | dependencies
4) Click the plus sign | jars or directories | and navigate to jtwitter jar | click ok

project explorer

When I import the jar file I get the following error:

import winterwell.jtwitter.Twitter;

Cannot resolve symbol winterwell
Gradle: error: package winterwell.jtwitter does not exist

I researched and found that android-studio has some issues and that you have to edit the build.gradle file yourself.

So I tried adding this to my build.gradle file:

dependencies {
    compile files('libs/jtwitter.jar')

build.gradle

And got an error message: cannot resolve symbol dependencies

Another question, where would the libs folder be. Does it mean the External Libraries?

Any help will be most helpfull,

question from:https://stackoverflow.com/questions/18735923/importing-jar-libraries-into-android-studio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Updated answer for Android Studio 2

The easy and correct way to import a jar/aar into your project is to import it as a module.

New -> Module

Right click on the main project and New -> Module

Select Import .JAR/.AAR Package

Import .JAR/.AAR Package

Select the .JAR/.AAR file and put a module name

Select the .JAR/.AAR file

Add the module as a dependency

Add the module as a dependency


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...