Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

intellij idea - How do I add a library project to the Android Studio and use it?(Some asked dont't take effect)

How do I add a library project to the Android Studio and use it?(Some asked question dont't take effect) I try to found answer on How do I add a library project to Android Studio? or How to import relative project with the Android Studio(not jar) . But it does not work.It also says "Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'." etc.

My sdk tools rev is 22.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

I'll show you how to do so with the map sample.

Say you have imported the map sample in Android Studio, and created the corresponding maps module.

1. Create an android library module

You need to create an additional library module for GMS, which includes all the classes the map sample needs from Google API to compile your map module.

The library project is located at:

$ANDROID_SDK/extras/google/google_play_services/libproject/google-play-services_lib

To do so, go to File -> Import module and select the location described above or the location of your library project.

Then use the right option between Create module from existing sources or Import module from external model. In my case it's from existing sources.

Android Studio detects the src/res directories, so far so good.

It also detects the library directories, which will save you the manual import of any jar you may have in lib/ (Like google-play-services.jar in my case).

[EDIT: It does actually save you only half the time because it creates the libraries but don't link them in you module dependencies]

2. Update your main module dependencies - Library module

Now, the tricky part is that you have only created the module, not linked to your project as a dependency.

Do do so, go to File -> Project structure -> Modules

Select your main module, maps in my case, and go to the dependencies tab on the right hand side. Click the + and 3. Module dependency.

Select the module your main module depends on and click OK.

3. Update your main module dependencies - Jars

Now for unexplained reason the activities in my maps module still cannot find the API classes. I also have to manually add the google-play-services.jar dependency on the Module configuration (as in 2., but select Library instead of Module dependency);

This point can surely be automatized with gradle but I haven't yet looked into it. When you use a new IDE, the fewer tools you use, the easier it is to track configuration errors. I'd suggest adding only one tool at a time :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...