简体   繁体   中英

External library dependency under Android Studio

I have my Android Studio project structured as follow:

/mysdk
  -manifests
  -java
     -com.xxx.sdk
     -ext-libs
       -com.yyy.lib (not .jar but .java files instead)
  -res
/app
 -manifests
 -java
 -res

I can include com.yyy.lib.* inisde com.xxx.sdk and reference all the methods without any symbol resolution problem in Eclipse project.

But after I transfer my IDE from Eclipse to Android Studio and it tells me it cannot resolve the symbols/methods from com.yyy.lib inside com.xx.sdk (ex: com.xxx.sdk.Activty.java)

How can I fix this dependency problem in Android studio?

That's because Android Studio uses Gradle as its dependency manager, whereas Eclipse uses either Maven or Ant.

You can read more about managing dependencies with Gradle, here .

This answer explains how to add a dependency/library to Gradle in Android Studio.

In your project file browser:
在此输入图像描述
Go to libs folder. and add your library if not present
在此输入图像描述

and then in gradle: add
compile files('libs/your_library')
in dependencies and then Sync Gradle

If you have no strong preference for the location of com.yyy.lib , just moving it into the parent (is it src/main/java ? based on gradle convention) it will probably get picked up.

It appears the IDE is treating src/main/java (or whatever) as a source folder and your package paths aren't matching up with your directory structure

ext-libs.com.yyy.lib instead of com.yyy.lib

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