问题
This is w.r.t Android Studio 1.3.2
So when i try to add the Repo from the Import Module->Import Existing Jar,the library is added as a separate module and included in the settings.gradle.
After this when I try to use the Jar, I get the message
Add Library 'x' to the classpath
Once i add this to the classpath,I am able to access the classes however the project does not build with the following error,
class Xx cannot be found(Xx belongs to the jar)
Is there a work-around to this.
I can add the jar by creatings a libs folder in the app
module and clicking on add as library
.
However I do not want the jar inside the main module.
回答1:
When you add any module dependency then it will not automatically added to gradle file.
You have to add that dependancy to gradle file manually..
Now here you are adding module to Android Studio project then, You have to add
compile project(':module_name')
So that you module will be attached to your app module.
Hope It will help.
Thank you.!
回答2:
Do something like this:
To import your module: Step-1; Goto File->new->import module. Select and import your module.
Step-2: In your app's build.gradle add compile project(':yourlibrary')
Step-3: Sync your gradle.
Now to add jar in the above module:
Step-1: Copy your jar file into your module's lib folder.
Step-2: In your module's build.gradle file add a dependency like compile files('libs/your_jar_file.jar')
Step-3 Sync your gradle and you are good to go.
来源:https://stackoverflow.com/questions/32367230/error-in-adding-external-jar-libraries-in-android-studio