Imported module in Android Studio can't find imported class - android

I recently downloaded the ViewPagerIndicator library and imported it into android studio. After adding it to my project I get a rendering error "The following classes could not be found:" and points to com.viewpagerindicator.IconPageIndicator.
The steps I took were Files->Import Module->'library name', Project Structure -> Dependencies -> + the imported module. Then to my layout xml file I added the <com.viewpagerindicator.IconPageIndicator />, after that I got the missing class problem.
It compiles just fine and I went through all of the build.gradle and settings.gradle files and compared them to what they should be online.
MyApp->build.gradle has compile project(':library') under dependencies
settings.gradle has include ':library' with no build errors.

First of all, you must import your library project by following that path:
File --> New --> Import Module
After you have imported the library project successfully, you must check your build.gradle file inside your project's folder if the following line is present at the "dependencies" section:
implementation project(':NameOfTheLibProject')
Then your project must be built successfully.

I found that my issue was the Android Plugin Version under Project Structure --> Project was different to the version my plugins all used. Once I aligned them to the same version, I could see all my classes from my imported module.
Took me hours :(

I had the same problem. I just did: Invalidate / Restart ..

I too had trouble importing module as it was not appearing in list of modules. And way it worked for me is manually entering it in settings.gradle this way:
include ':app', 'module_name'
And in build.gradle
compile project(':module_name')

In my case, I did add in app gradle:
// Nearly deprecated.
compile project(':NameOfTheLibProject')
// Or
implementation project(':NameOfTheLibProject')
but it only works when I change
compileSdkVersion
minSdkVersion
targetSdkVersion
in app and the other modules are the same.

The following solution worked for me,just two steps.
Go to your project structure on android studio, select project from left side.Change Android plugin version to Gradle version press ok.
If error occurs after synchronization again go to project structure and select project.undo the android plugin version like before.Gradle will align the library and make the class visible to XML files.

The issue in my case was different compile and target SDK version,
mentioned in my main app module and your added lib module.
Once I matched both of them it worked perfectly.
So just open build.gradle file of app-level and lib module-level check for the SDK version.

settings.gradle
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(':wheel') // "Wheel" - you're project path name
}

In case you just changed the name of your project in the pubspec.yaml File, make sure to change the import names as well, because they will stay the same and therefore wont find the new named directory.
Ex. change this to :
import 'package:previousName/backend/connector/userConnector.dart';
to this:
import 'package:newName/backend/connector/userConnector.dart';
As far as i know, there is no terminal command for that, only find-in-files-replace :(

Related

How to insert github source code to my project

I'm new at GitHub. I found a library that I want to use in my Android project (Glide), but I don't know how.
After downloading the source code I'm stuck with a zip folder that I don't know how to import it into my project. I'm working with Android Studio.
Any help?
Thanks.
Unzip the downloaded project. Open YOUR project in Android studio. Click File -> Import module. Add this module as a dependency to your project. You should be good to go.
[EDIT]
BUT, since Glide has gradle/maven support, I can just simply modify your project's build.gradle file and add the following lines to the dependencies group:
compile 'com.github.bumptech.glide:glide:3.3.+'
compile 'com.android.support:support-v4:19.0.0' // You might need to increase the version numbers if the libraries have never versions

Adding external library in Android studio

I want to add external library https://github.com/foursquare/foursquare-android-oauth to my Android application (I use Android Studio, the instructions provided by lib author for Eclipse didn't work for Android Studio).
I've tried to do it with maven, so in File->Project Structure->Dependencies I've added com.foursquare:foursquare-android-nativeoauth-lib:1.0.0 but Gradle Sync fails:
Error:Failed to find: com.foursquare:foursquare-android-nativeoauth-lib:1.0.0
When I try to build my app (without fixing above error becaus I don't know how) I get:
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.foursquare:foursquare-android-nativeoauth-lib:1.0.0.
Required by:
ForSquaresOnly:app:unspecified
> Could not parse POM http://jcenter.bintray.com/com/foursquare/foursquare-android-nativeoauth-lib/1.0.0/foursquare-android-nativeoauth-lib-1.0.0.pom
> Could not find any version that matches com.foursquare:parent:1.0.0.
Any other way to import this lib? I can simply copy-paste source code into my source or create JAR out of it?
BTW: if you run into problems see this question (I had this issue after importing): Manifest merger failed : uses-sdk:minSdkVersion 14
Try one of these approaches:
Approach 1)
1- Choose project view
2- Copy your JAR file in app -> lib folder
3- Right click on your JAR file and choose add as library
4- Check it in build.gradle
Approach 2)
1- File -> New -> New Module
2- Import .JAR/.AAR Package
3- Browse your JAR File
4- Finish
5- File -> Project Structure -> Dependencies
6- You should click on + button and then click on Module Dependency
7- You will see your library here
8- choose your library and click ok
9- Then, you will see that your library is added.
For first two approaches, you need a JAR file. You can search http://search.maven.org/ to find JAR files that are related to Android. For example, this is the search result for jdom in this link
Approach 3) Android is using http://jcenter.bintray.com/ as remote library. For example, this is the search result for jdom in the link.
To add a library in this approach, please follow these steps:
1- File -> Project Structure -> Dependencies
2- Click on + button and choose library dependency
3- find your library and select it, then click OK.
Try this:
File > Project Structure > Dependencies Tab > Add module dependency (scope = compile)
Where the module dependency is the project library Android folder.
To reference an external lib project without copy, just do this:
- Insert this 2 lines on setting.gradle:
include ':your-lib-name'
project(':your-lib-name').projectDir = new File('/path-to-your-lib/your-lib-name)
Insert this line on on dependencies part of build.gradle file:
compile project(':your-lib-name')
Sync project
There are two simplest ways if one does not work please try the other one.
Add dependency of the library inside dependency inside build.gradle file of the library you are using, and paste your library in External Libraries.
OR
Just Go to your libs folder inside app folder and paste all your .jar e.g Library files there, Now the trick here is that now go inside settings.gradle file now add this line include ':app:libs' after include ':app' it will definitely work.
Any other way to import this lib? I can simply copy-paste source code
into my source or create JAR out of it?
Complete Steps for importing a library in Android Studio 1.1
Goto File -> Import Module.
Source Directory -> Browse the project path.
Specify the Module Name
Open build.gradle (Module:app) file
Add the following line with your module name
compile project(':internal_project_name')
Taken from: how to add library in Android Studio
I had also faced this problem. Those time I followed some steps like:
File > New > Import module > select your library_project. Then include 'library_project' will be added in settings.gradle file.
File > Project Structure > App > Dependencies Tab > select library_project. If library_project not displaying then, Click on + button then select your library_project.
Clean and build your project. The following lines will be added in your app module build.gradle (hint: this is not the one where classpath is defined).
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library_project')
}
If these lines are not present, you must add them manually and clean and rebuild your project again (Ctrl + F9).
A folder named library_project will be created in your app folder.
If any icon or task merging error is created, go to AndroidManifest file and add <application tools:replace="icon,label,theme">
A late answer, although I thought of giving an in-depth answer to this question. This method is suitable for Android Studio 1.0.0 and above.
STEPS
First switch your folder structure from Android to Project.
Now search for the libs folder inside app - build folder.
Once you have pasted the .jar file inside libs folder. Right click on the jar file and at end click on Add as library. This will take care of adding compile files('libs/library_name.jar') in build.gradle [You don't have to manually enter this in your build file].
Now you can start using the library in your project.
For the simplest way just follow these steps
Go to File -> New -> Import Module -> choose library or project folder
Add library to include section in settings.gradle file and sync the project (After that you can see new folder with library name is added in project structure)
include ':mylibraryName'
Go to File -> Project Structure -> app -> dependency tab -> click on plus button
Select module dependency -> select library (your library name should appear there) and put scope (compile or implementation)
Add this line in build.gradle in app level module in dependency section
implementation project(':mylibraryName')
Three ways in android studio for adding a external library.
if you want to add libarary project dependency in your project :
A. In file menu click new and choose import module choose your library project path and click ok, library project automatically add in your android studio project .
B. Now open your main module(like app) gradle file and add project dependency in dependency section dependencies {
compile project(':library project name')
if you want to add jar file :
A. add jar file in libs folder.
B. And Add dependency
compile fileTree(dir: 'libs', include: '*.jar') // add all jar file from libs folder, if you want to add particular jar from libs add below dependency.
compile files('libs/abc.jar')
Add Dependency from url (recommended). like
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
Android studio doesn't use Maven, it use Gradle, you can open your build.gradle the route should be: /app/build.gradle and add the Gradle dependency that shows on the repo:
The build.gradle has a dependencies section:
dependencies {
//here add your dependency
}
The repo says that you need to add this dependency:
compile 'com.foursquare:foursquare-android-oauth:1.0.3'
only add that line to your dependencies on buil.gradle, save the file, and android will rebuild the project, that's all
If the library you need is on GitHub then adding it to Android Studio is easy with JitPack.
Step 1. Add the jitpack repository to build.gradle:
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
Step 2. Add the GitHub repository as a dependency:
dependencies {
// ...
compile 'com.github.Username:LibraryRepo:ReleaseTag'
}
JitPack acts as a maven repository and can be used much like Maven Central. The nice thing is that the maintainers don't have to upload the library. Behind the scenes JitPack will check out the code from GitHub and compile it. Therefore for this to work there needs to be a working build file in the git repository.
There is also a guide on how to publish an Android library.
Turn any github project into a single line gradle implementation with this website
https://jitpack.io/
Example, I needed this project:
https://github.com/mik3y/usb-serial-for-android
All I did was paste this into my gradle file:
implementation 'com.github.mik3y:usb-serial-for-android:master-SNAPSHOT'
There are some changes in new gradle 4.1
instead of compile we should use implementation
implementation 'com.android.support:appcompat-v7:26.0.0'
1.Goto File -> New -> Import Module
2.Source Directory -> Browse the project path.
3.Specify the Module Name – it is used for internal project reference.
Open build.gradle (Module:app) file.
implementation project(':library')
I had the same problem. This happened because of core library dependency. I was using javax.* . This is what i did to fix
In File->Project Structure->Dependencies I added this as as provided file, not a compile. Then re build the project.
This problem started after upgrade of android studio. But I think it happens when you try to edit you build files manually.
Adding library in Android studio 2.1
Just Go to project -> then it has some android,package ,test ,project view
Just change it to Project View
under the app->lib folder you can directly copy paste the lib and do android synchronize it.
That's it
1)just get your lib from here http://search.maven.org/
2)create a libs folder in app directory
3)paste ur library there
4)right click on ur library and click "Add as Library"
5)thats all u need to do!
I hope this will definitely gonna help you!!!!
Could not find any version that matches com.foursquare:parent:1.0.0.
Means that library developer made a mistake in .pom file and specified a wrong one.
I would recommend use the standard approach. You can find .pom file in Maven Repository and use that version or ask developer to take a loot at this problem(via github issue tracker)
compile 'com.foursquare:foursquare-android-oauth:1.1.1'
SIMPLE STEPS TO ADD ANY LIBRARY IN ANDROID STUDIO:
Copy the file in question from any folder in your computer (eg. C:/documents/xyz.jar"), then go to Android Studio and right-click the Project Library folder and select paste.
Now, right click on the newly added Library file and select the option "add as Library"
D.O.N.E

Library projects in Android Studio only work if nested in the project tree?

I'm trying to build a project dependent on ActionbarSherlock in Android Studio.
After much reading I've ended up having a working build, but only if I nest the ABS project inside my main project like so:
MainProject
MainProject\ABS (copied here and then used import module)
MainProject\MainModule (the one created by the wizard)
I had to edit the various Gradle files, settings.gradle is as follows:
include ':OnTop'
include ':ActionbarSherlock'
I fixed the dependencies in the build.gradle files accordingly.
This is suboptimal, I think. Surely I don't want to replicate the ABS module in every new project that uses it? What should I be doing instead?
Every step are here : How do I add a library project to Android Studio?
If you want to more about gradle see the Google I/O conference by Xavier Ducrohet on youtube : http://www.youtube.com/watch?v=LCJAgPkpmR0
I searched this issue enough and finally these are my results:-
This sample project
-> project root
d:\asprojects\thisproject
-> module
d:\asprojects\thisproject\MyModule
-> libraries
d:\asprojects\lvl
d:\asprojects\MyLibrary
-> jars
D:/asprojects/android-support-v4.jar
D:/asprojects/GoogleAdMobAdsSdk-6.4.1.jar
-If you want to use external (outside the project) libraries then the settings.gradle has to point to it like so:-
settings.gradle
include ':lvl', ':MyLibrary', ':MyModule'
project(':MyLibrary').projectDir = new File('D:/asprojects/MyLibrary')
project(':lvl').projectDir = new File('D:/asprojects/lvl')
-Then you need to setup the build.gradle for the MyModule correctly like so:-
build.gradle
dependencies
{
compile files('D:/asprojects/android-support-v4.jar')
compile files('D:/asprojects/GoogleAdMobAdsSdk-6.4.1.jar')
compile project(':lvl') compile project(':MyLibrary')
}
-But the IDE will not like these absolute paths and will say not found.
-But gradlw from commandline work justs fine:-
gradlew clean
gradlew build
gradlew installRelease
etc

Proper way to add global library in android-studio/gradle

First of all, I know how to add a local library to the build.gradle file, it was discussed in several questions here already (which are all basically the same), see here, here and here. But you have to hardcode the paths in the compile files('/path/to/lib.jar') statements in the build.gradle file, which isn't nice, not redistributable, etc, IF you use a library not within the project's folder structure. I prefer to maintain this library for all my projects in the same place (so it is always up to date for all projects etc.). So I would like to know how to add a library, which is not available via Maven, to an Android-Studio project using gradle, in a sane way, given that the library is added as a global library in AS's preferences.
What I have done so far:
I use Google's new Android-Studio, which uses gradle for the build management, to build an Xposed framework module. For that, I have to include an external library, XposedLibrary, which I downloaded from the respective Github repository to keep it up-to-date.
It contains the jar XposedLibrary/XposedBridgeApi.jar, which I added in AS as a global library (Ctrl+Shift+Alt+S -> Global Libraries -> green plus to add the folder XposedLibrary). The compilation failed, complaining that it doesn't know the imported classes. So I had to manually add the library to the build.gradle file, adding the respective line in the dependencies like so:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('/home/sebastian/dev/android/XposedMods/XposedLibrary/XposedBridgeApi.jar')
}
I tried out to just add compile files('XposedBridgeApi.jar') or compile files('XposedLibrary/XposedBridgeApi.jar') but this didn't work.
So, what is a nice way to add an AS global library to the dependencies without using full paths? (I don't like the idea of symlinking to the jar file from within the lib/ folder ;) )
when referencing a file via
files("relative/path/to/a.jar")
the relative path is evaluated relative to the buildscript this snippet is in. so when your build.gradle file is located in let's say '/a/project/build.gradle' then the jar should be in '/a/project/relative/path/to/a.jar'. In a multiproject gradle build you can put the the jar in a folder relative to the root - project and reference it in all subprojects via
rootProject.files("relative/to/root/a.jar")
hope that helps,
cheers,
René
This post describes how to get XposedBridgeApi.jar working with Gradle in Android Sudio: http://forum.xda-developers.com/showpost.php?p=41904291&postcount=1570
I think here is the proper way:
Import Xposed in Android Studio
Edit the /app/build.gradle like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
provided fileTree(dir: 'deps', include: ['*.jar'])
}
The best way is to use "provided files('src/XposedBridgeApi-54.jar')" as the lib isn't allowed to be included in the module, because the XposedBridge is already installed on the phone.
With Android Studio, you have to first understand that the IDE uses the same model for a project that your command line build (gradle) uses. That is why the Project Structure dialog has a pop up that says edits here will have no effect. So adding a global library will also have no effect.
The correct way to fix such issues is to edit your gradle build scripts so that the command line gradle build works properly. Then you should just have to click on "Tools | Android | Sync Project with Gradle files" menu item to refresh the project structure in the IDE.
Finally, if your dependencies are not going to be in Maven Central, then you'd have to create a local maven repository. Read the thread here: https://groups.google.com/d/msg/adt-dev/eCvbCCZwZjs/vGfg-4vNy9MJ for background.

How to import relative project with the Android Studio(not jar) [duplicate]

How do I add a library project (such as Sherlock ABS) to Android Studio?
(Not to the old ADT Eclipse-based bundle, but to the new Android Studio.)
Update for Android Studio 1.0
Since Android Studio 1.0 was released (and a lot of versions between v1.0 and one of the firsts from the time of my previous answer) some things has changed.
My description is focused on adding external library project by hand via Gradle files (for better understanding the process). If you want to add a library via Android Studio creator just check the answer below with visual guide (there are some differences between Android Studio 1.0 and those from screenshots, but the process is very similar).
Before you start adding a library to your project by hand, consider adding the external dependency. It won’t mess in your project structure. Almost every well-known Android library is available in a Maven repository and its installation takes only one line of code in the app/build.gradle file:
dependencies {
implementation 'com.jakewharton:butterknife:6.0.0'
}
Adding the library
Here is the full process of adding external Android library to our project:
Create a new project via Android Studio creator. I named it HelloWorld.
Here is the original project structure created by Android Studio:
HelloWorld/
app/
- build.gradle // local Gradle configuration (for app only)
...
- build.gradle // Global Gradle configuration (for whole project)
- settings.gradle
- gradle.properties
...
In the root directory (HelloWorld/), create new folder: /libs in which we’ll place our external libraries (this step is not required - only for keeping a cleaner project structure).
Paste your library in the newly created /libs folder. In this example I used PagerSlidingTabStrip library (just download ZIP from GitHub, rename library directory to „PagerSlidingTabStrip" and copy it). Here is the new structure of our project:
HelloWorld/
app/
- build.gradle // Local Gradle configuration (for app only)
...
libs/
PagerSlidingTabStrip/
- build.gradle // Local Gradle configuration (for library only)
- build.gradle // Global Gradle configuration (for whole project)
- settings.gradle
- gradle.properties
...
Edit settings.gradle by adding your library to include. If you use a custom path like I did, you have also to define the project directory for our library. A whole settings.gradle should look like below:
include ':app', ':PagerSlidingTabStrip'
project(':PagerSlidingTabStrip').projectDir = new File('libs/PagerSlidingTabStrip')
5.1 If you face "Default Configuration" error, then try this instead of step 5,
include ':app'
include ':libs:PagerSlidingTabStrip'
In app/build.gradle add our library project as an dependency:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation project(":PagerSlidingTabStrip")
}
6.1. If you followed step 5.1, then follow this instead of 6,
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation project(":libs:PagerSlidingTabStrip")
}
If your library project doesn’t have build.gradle file you have to create it manually. Here is example of that file:
apply plugin: 'com.android.library'
dependencies {
implementation 'com.android.support:support-v4:21.0.3'
}
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
Additionally you can create a global configuration for your project which will contain SDK versions and build tools version for every module to keep consistency. Just edit gradle.properties file and add lines:
ANDROID_BUILD_MIN_SDK_VERSION=14
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.3
ANDROID_BUILD_SDK_VERSION=21
Now you can use it in your build.gradle files (in app and libraries modules) like below:
//...
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
}
}
//...
That’s all. Just click‚ synchronise the project with the Gradle’ icon . Your library should be available in your project.
Google I/O 2013 - The New Android SDK Build System is a great presentation about building Android apps with Gradle Build System: As Xavier Ducrohet said:
Android Studio is all about editing, and debugging and profiling.
It's not about building any more.
At the beginning it may be little bit confusing (especially for those, who works with Eclipse and have never seen the ant - like me ;) ), but at the end Gradle gives us some great opportunities and it worth to learn this build system.
Here is the visual guide:
Update for Android Studio 0.8.2:
In Android Studio 0.8.2, go to Project Structure -> under Modules just hit the plus button and select Import Existing Project and import actionbarsherlock. Then synchronise your Gradle files.
If you face the error
Error: The SDK Build Tools revision (xx.x.x) is too low. Minimum
required is yy.y.y
just open the build.gradle file in actionbarsherlock directory and update the buildToolsVersion to the suggested one.
android {
compileSdkVersion 19
buildToolsVersion 'yy.y.y'
Menu File -> Project Structure...:
Module -> Import Module
After importing the library module, select your project module and add the dependency:
And then select the imported module:
Use menu File -> Project Structure -> Modules.
I started using it today. It is a bit different.
For Sherlock, maybe you want to delete their test directory, or add the junit.jar file to the classpath.
To import the library using gradle, you can have to add it to the dependencies section of your build.gradle (the module's one).
E.g.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
}
Android Studio is changing.
There exist a section named "Open module settings" if you
right-click on a module folder in the project section of Android
Studio (I'm using the version 0.2.10).
I would consider Dependencies, Android Libraries and Multi-project setup necessary reading. Please take a few minutes to do so.
Particularly, in the case of a non-jar library project, read the following snippet from above source:
Gradle projects can also depend on other gradle projects by using a multi-project setup.
A multi-project setup usually works by having all the projects as sub folders of a given root project.
For instance, given to following structure:
MyProject/
+ app/
+ libraries/
+ lib1/
+ lib2/
We can identify 3 projects. Gradle will reference them with the following name:
:app
:libraries:lib1
:libraries:lib2
Each projects will have its own build.gradle declaring how it gets built.
Additionally, there will be a file called settings.gradle at the root declaring the projects.
This gives the following structure:
MyProject/
| settings.gradle
+ app/
| build.gradle
+ libraries/
+ lib1/
| build.gradle
+ lib2/
| build.gradle
The content of settings.gradle is very simple:
include ':app', ':libraries:lib1', ':libraries:lib2'
This defines which folder is actually a Gradle project.
The :app project is likely to depend on the libraries, and this is done by declaring the following dependencies:
dependencies {
compile project(':libraries:lib1')
}
Kindly note that there was little or no use of Android Studio GUI to make this happen.
I am currently using git submodules to link the nested library to the actual library git repo to avoid a dependency mess.
I have just found an easier way (rather than writing directly into the .gradle files).
This is for Android Studio 1.1.0.
Menu File -> New Module...:
Click on "Import Existing Project".
Select the desired library and the desired module.
Click finish.
Android Studio will import the library into your project. It will sync gradle files.
Add the imported module to your project's dependencies.
Right click on the app folder -> Open Module settings -> go to the dependencies tab -> Click on the '+' button -> click on Module Dependency.
The library module will be then added to the project's dependencies.
???
Profit
The easiest way I found to include external library project is (for example to include a Facebook library which is stored one directory up in the dependencies folder):
In settings.gradle add
include ':facebook'
project(':facebook').projectDir = new File(settingsDir, '../dependencies/FacebookSDK')
In build.gradle dependencies section, add
compile project ('facebook')
All left to do is synchronise the project with gradle files.
A simple way to add a JAR file as a library to your Android Studio project:
a) Copy your *.jar files
b) Paste into the libs directory under your projects:
c) Add to build.gradle:
dependencies {
...
compile files('libs/ScanAPIAndroid.jar', 'libs/ScanAPIFactoryAndroid.jar', .., ..)
}
b) If your project from example com.example.MYProject and libraries com.example.ScanAPI has the same namespace com.example, Android Studio will check your build and create all necessary changes in your project. After that you can review these settings in menu File -> Project Structure.
c) If your project and libraries have a different namespace you have to right click on the library and select option "Add as Library" and select the type what you need.
Remember the "Project structure" option is not doing any auto changes in "build.gradle" in the current version of Android Studio (0.2.3). Maybe this feature will be available in the next versions.
Option 1: Drop Files Into Project's libs/directory
The relevant build.gradle file will then update automatically.
Option 2: Modify build.gradle File Manually
Open your build.gradle file and add a new build rule to the dependencies closure. For example, if you wanted to add Google Play Services, your project's dependencies section would look something like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:6.5.+'
}
Option 3: Use Android Studio's User Interface
In the Project panel, Control + click the module you want to add the dependency to and select Open Module Settings.
Select the Dependencies tab, followed by the + button in the bottom-left corner. You can choose from the following list of options:
Library Dependency
File Dependency
Module Dependency
You can then enter more information about the dependency you want to add to your project. For example, if you choose Library Dependency, Android Studio displays a list of libraries for you to choose from.
Once you've added your dependency, check your module-level build.gradle file. It should have automatically updated to include the new dependency.
Source
You can do this easily. Go to menu File -> New -> Import Module...:
Browse for the directory which contains the module. Click Finish:
Go to Project Structure and add Module Dependency:
Note: If you receive an SDK error, update that one.
This is how it works for me in Android Studio 1.5+
In the project where you want to add external library project,
go to menu File -> New -> *Import new Module**, navigate to the library project which you want to add to your project, select to add 'library' module in your project. You will get settings.gradle in your projects, beside app, included library, something like this:
include ':app', ':library'
Add in build.gradle(Module :app) in the dependencies section:
Compile project(':library')
Rebuild the project, and that's it.
*You can add as many libraries (modules) as you want. In that case in settings.gradle you will have:
include ':app', ':lib1', ':lib2', ...
And in build.gradle, you'll need to have:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Some other dependencies...
compile project(':lib1')
compile project(':lib2')
...
}
Press F4 to show Project Structure, click libraries or Global libraries, and click + to add the JAR file.
Click Modules what you want add jar, select the Dependencies tab, click +, and add Library.
If you need access to the resources of a library project (as you do with ABS) ensure that you add the library project/module as a "Module Dependency" instead of a "Library".
Editing library dependencies through the GUI is not advisable as that doesn't write those changes to your build.gradle file. So your project will not build from the command-line. We should edit the build.gradle file directly as follows.
For instance, given to following structure:
MyProject/
app/
libraries/
lib1/
lib2/
We can identify three projects. Gradle will reference them with the following names:
:app
:libraries:lib1
:libraries:lib2
The :app project is likely to depend on the libraries, and this is done by declaring the following dependencies:
dependencies {
compile project(':libraries:lib1')
}
Android Studio 3.0
Just add the library name to the dependencies block of your app's build.gradle file.
dependencies {
// ...
implementation 'com.example:some-library:1.0.0'
}
Note that you should use implementation rather than compile now. This is new with Android Studio 3.0. See this Q&A for an explanation of the difference.
To add to the answer: If the IDE doesn't show any error, but when you try to compile, you get something like:
No resource found that matches the given name 'Theme.Sherlock.Light'
Your library project is probably compiled as an application project. To change this, go to:
Menu File -> Project structure -> Facets -> [Library name] -> Check "Library module".
First Way This is working for MacBook.
First select your builder.gradle file as given screen:
Add dependencies like as on the selected screen:
Select sync project.
If you are getting an error like "Project with path':signature-pad' could not be found in project ':app'", then please use the second way:
Select menu File -> New -> Import Module...:
After clicking on Import Module,
give the path of library like as my MacBook path:
Click on Finish. Now your library are added.
After importing the ABS Module (from File > Project Structure) and making sure it has Android 2.2 and Support Library v4 as dependencies, I was still getting the following error as you #Alex
Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light.DarkActionBar'
I added the newly imported module as a dependency to my main app module and that fixed the problem.
To resolve this problem, you just need to add the abs resource path to your project build file, just like below:
sourceSets {
main {
res.srcDirs = ['src/main/res','../../ActionBarSherlock/actionbarsherlock/res']
}
}
So, I again compile without any errors.
If you have Android Studio .0.4.0, you can create a new folder in your build path, YourApp/libraries. Copy the JAR file. There in, right click on it and "Add As Library". Now you have a popup. Just select your directory and press OK, and that's it.
Simply import the Android library project as a module and in Build.gradle.
Apply plugin: 'com.android.library'
After that, follow these steps:
Right click on Module & select open Module settings
Select dependencies, click on +, select library dependencies, and add the previously imported module.
https://www.dropbox.com/s/1e3eteu3h0pmkf7/Android%20studio%20_doc.doc?dl=0 is the Dropbox link of how to add a JAR file and library project in the latest version of Android Studio 1.0.1.
Please see the documentation with screenshots. It's very easy for a new user.
I found the solution. It's so simple. Follow froger_mcs instructions.
Make sure that you make the src folder a Source folder in Project Structure -> Modules (Sources).
Basically, you can include your JAR files in three different ways. The last one is remote library that is using https://bintray.com/ jcenter online repository. But, if you do it in one of the two other ways, the JAR file will be included physically in your project. Please read this link https://stackoverflow.com/a/35369267/5475941 for more information. In this post I explained how to import your JAR file in Android studio and I explained all possible ways.
In summary, if it is like this (local address), they are downloaded and these JAR files are physically in the project:
But, if it is an internet address like this, they are remote libraries (bintray.com jcenter part) and they will be used remotely:
I hope it helps.
Open the build gradle module app file and add your dependency. If you download the library, just import and build as gradle.
Otherwise add repositories in side gradle module app:
repositories {
maven { url 'http://clinker.47deg.com/nexus/content/groups/public' }
}
The first repositories will download the library for you.
And compile the downloaded library:
compile ('com.fortysevendeg.swipelistview:swipelistview:1.0-SNAPSHOT#aar') {
transitive = true
}
If you are creating a library, you just need to import the project as import new module.
I had a different cause of the problem so for people:
repositories {
mavenCentral()
}
change mavenCentral() to jcenter() and add
allprojects {
repositories {
jcenter()
}
}
In Android Studio, go to inside app folder, and open build.gradle file. Here you will see dependencies{}. Inside it you can add the library project and synchronise. Now after synchronising the library it will be added to your project, and you can use its functions and classes in your project.
For Android Studio:
Click on Build.gradle (module: app).
And add for
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/commons-io-2.4.jar')
}
and in your directory "app", create a directory, "libs". Add the file yourfile.jar:
Finally, compile the Gradle Files:
I also encountered the same problem then I did following things.
I import the library project into my AndroidStudio IDE as a module using menu File -> Import module menus
Then I went to my main module in which I want the library project as a dependent project
Right click on the main module (in my case its name is app) -> open module setting -> go into dependencies tab -> click on + button (you will get it on right side of window) -> click on module dependency -> select your library project from list
Apply the changes and click the OK button.
It worked for me. I hope it will help others too.
You are able to use Gradle dependency configuration[About] to add some dependency into your project
<module_name>/build.gradle
dependencies {
//<gradle_dependency_configuration> '<dependency_name>:<dependency_version>'
//e.g.
implementation 'com.android.support:appcompat-v7:1.1.1'
}
Indeed as versions are changing, so is changing the user interface and options available on the menu. After reading most of the answers to these questions I had to guess what would work for Android Studio 1.1.0.
With your mouse, select the project at the main level (this is where it shows the name of your app).
Right click, and select the menu options New, Folder, Assets Folder.
After creating the assets folder, paste or copy in it, whatever JAR file you need for your library.
From Android Studio's main menu (top of the screen) select File -> Project Structure.
Then select your project name and go to the Dependencies tab.
Click on the plus sign (+) on the lower left of the dialog box and select file dependency.
Finally open the recently created assets folder, select the JAR files that you copied, and then click apply and OK.
Clean and rebuild your project.

Categories

Resources