Importing a maven project on Github into Android Studio as dependency - android

I am trying to work on an android app using Android Studio and I want to use the SlidingMenu github project in my app. This github project appears to be related to Maven (Disclosure: I've never used Maven before).
I want to be able to reference its classes in my Android Studio project.
I tried to create a new module, but that it creates its own directory structure. I want to just import the existing file structure of this github project (so I don't change anything related to it).
Can anyone tell what is the recommended way to do this. Thanks.

if this library can be found in maven central search, you can just go to
file
project structure
while selected in the left "app" under modules
go to Dependecies tab
click + button on the right and choose library dependency and search for your lib.(there is another sliding menu lib then yours i think)
use it in your code
otherwise:
if you want to add the library you posted, download it and go to
file
project structure
click + button (top left corner this time)
in the new window select "import gradle project " choose the folder of your lib (if it will not do this, choose the library folder inside it(idk this lib)). i think it will import your lib
then go to dependencies tab
click + button and choose add module dependency this time choose your lib and your done
use it in your code
have fun

Related

Editing external libraries in Android Studio

I am using an image carousel library that I snagged off of github, but there are a few things I would like to change in the code. I have imported it using the compile 'com.theartofdev.edmodo:android-image-cropper:2.6.+' command. Is that code available for me to edit somehow? Or is it downloaded from github every time I run my code?
For this you need to import it as lib and modify as you like:
To import the library to Android Studio, there are two methods that can work.
Method 1:
Open your project in Android Studio
Download the library (using Git, or a zip archive to unzip)
Create a folder "subProject" in your project
Copy and paste the FreemiumLibrary folder to your subProject folder
On the root of your project directory create/modify the settings.gradle file. It should contain something like the following:
include 'MyApp', ':subProject:FreemiumLibrary'
gradle clean & build/close the project and reopen/re-import it.
Edit your project's build.gradle to add this in the "dependencies" section:
dependencies {
//...
compile project(':subProject:FreemiumLibrary')
}
Edit your App Activities to extend AdsFragmentActivity instead of Activity.
Edit the library if you want to use it with ActionBarCompat
Method 2:
Open your project in Android Studio
Download the library (using Git, or a zip archive to unzip)
Go to File > New > Import-Module and import the library as a module
Right-click your app in project view and select "Open Module Settings"
Click the "Dependencies" tab and then the '+' button
Select "Module Dependency"
Select "Freemium Library" (not Freemium Library Project)
Modify your App Activities to extend AdsFragmentActivity instead of Activity.
Modify the library if you want to use it with ActionBarCompat
I solved this way. Fork library project. Then clone it (In Android Studio, File -> New -> Project from Version Control -> put the link of your repository that you forked and open it). Edit it and commit it to your master branch. Then push it to your master branch. And finally find snapshot version of that library. For example if you use JitPack. Go to jitpack.io website and search for your repository (forked version with your username). And there go to commits section and get latest version that you committed. And use that library dependency in your project instead of original repo.
My approach was similar to #Shailendra Madda's with some minor differences.
At first I downloaded/cloned the project in my PC. Let's say the library's name is 'VideoPlayer'.
I ensured that the module level gradle of VideoPlayer did not contain applicationId. I also ensured that it contained
plugins {
id 'com.android.library'
}
instead of
plugins {
id 'com.android.application'
}
Now the library is ready for import.
In order to import this library into my project, I went to File -> New -> Import Module.
From there, I selected the directory of VideoPlayer. The VideoPlayer project that I downloaded had four modules. In cases like this you can simply select the modules you want to import. I selected the module named core and clicked finish. [Note: instead of selecting VideoPlayer folder from the explorer, you can also select the 'core' folder].
After importing the module, go to File -> Project Structure (or Ctrl+Alt+Shift+S) and select dependencies. From modules section, select app (here, app is the name of my project's module) and then select the + icon in 'declared dependencies' section and select Module Dependency. From the new window, select the module you wish to add as dependency (in my case, it is 'core').
After you click Apply and/or OK, android studio will modify relevant gradle files, so you don't have to worrry about it. And the project will be added as a dependency in your project.
Check this page to learn more: https://developer.android.com/studio/projects/android-library

How does Android Studio import Gradle projects

I've read lots of "how-to" guides to importing libraries into Android Studio (now the only supported Android SDK, hmmpf) yet none of them explain what's actually going on during an import.
I can see projects that have Gradle build files everywhere and some that have none, why is this?
Half the stuff I get on Git-hub to play around with takes me more time to successfully import than the time it's saved me by using. My question is, what is required to successfully import and use your average library (project, not JAR or AAR) in Android Studio without having to refactor half the stuff?
Eclipse would allow me to use one single project (folder structure, not jar) as an "external" library and I needn't define what needs compiling where and when.
Android Studio keeps making copies of the project library inside my project folder then proceeds to complain about a whole host of things whilst it pollutes my project space with incorrectly named folders and packages (See screenshots)
Here's and incomplete import where I only imported the "core" folder
because I don't need this other blokes extra stuff - but it's missing
some definitions.
Here's a complete import of the whole folder (as you can see, samples
and all) but it's polluted my project folder and I don't need the
majority of it, and there's all these individual references now to
dependencies and things I don't think I should need.
How do I properly import a whole library with it's dependencies
without it polluting my current project?
Thanks in Advance!
EDIT
Ok here's what I have in one case of a library for an example.
The root folder of the zipped library - lots of garbage I don't need
What do I need to do to use this library? If I import the whole folder using Android Studio's "Import module" feature, it just makes a mess.
If I import just the "Core" folder it semi-works, but lacks some dependencies.
Why are there 3 individual gradle.build files?
Why are the required components in separate folders?
Should I just manually copy an arbitrary number of folders to my new "Libraries" folder under the root of my project?
Importing via File->Import Module
So the "sample" "module" (library..) requires the "layout" and "core" modules, that makes sense. But why if they're required aren't they all in the one module, using the same gradle.build file?
Now I've done that, I get this "Error:(23, 0) Could not read script 'C:\Users\me\AndroidstudioProjects\MyApp\gradle\scripts\gradle-mvn-push.gradle' as it does not exist."
It does exist at C:\Users\me\place_the_module_was_imported_from\gradle\scripts\ though, but
why if it's needed, was it not copied? Is this just bad Gradle...'ing?
Again, thanks!
I think I've found what seems to be the closest answer to this.
10 Gradle Basics
The addition of Gradle is going to be your largest hurdle during your transition over to Android Studio. Here are the basics of what you need to know:
Your Android Studio project will have a settings.gradle for the whole project
The settings.gradle file includes references to all modules which are included in the project and is generally updated automatically when you import or create a new module
Each Android Studio module will have its own build.gradle file
If one module depends upon another module, you will need to add that dependency in the build.gradle under the dependencies section
If your Module requries a jar file, it must be listed in that Module's build.gradle file
You may add remote dependencies to your project by listing them in a module's build.gradle file
From time to time, you will need to manually edit these gradle files Read more about Gradle over here.
Problem is that dependencies show up as modules in the UI so I now have a polluted workspace full of single-use libraries.
You can add the library via gradle.build and the necessary dependencies will be neatly added to your project without "polluting" your project. An example is the Facebook SDK
dependencies {
...
compile 'com.facebook.android:facebook-android-sdk:3.23.0'
}
As you can see from the image, the only place to know the external libraries am using is in the libraries folder of my project:
Add .jar file in your project
1 - Create libs folder under the app folder.
2 - copy your .jar file
3 - paste in app->libs folder
4 - after Click on File menu and select Project Structer option and open it
5 - Open one window in left side Modules under App folder select that folder
6 - In your window Top display 5 Option menu in select Dependencies option
7 - Then Right side display "+" "-" Sign click on "+" sign
8 - then open small dialog and choice "File dependencies" option
9 - then open another dialog here navigate .jar file in your libs folder and select
10 - click on Ok button and Apply And ok
add module project
1 - Click on File menu and select Import Module option
2 - then open one window here navigate your module and Finish
3 - Click on File menu and select Project Structer option and open it
4 - Open one window in left side Modules under App folder select that folder
5 - In your window Top display 5 Option menu in select Dependencies option
6 - Then Right side display "+" "-" Sign click on "+" sign
5 - then open small dialog and choice "Module dependencies" option
6 - then open another dialog here Module and select
7 - click on Ok button and Apply And ok

Android Studio 0.8.2 : How to add local Project Library?

i am a android app developer and converting myself from Eclipse to Android Studio.
Now i get a difficulty to add library project into another project.
What i can do in Eclipse is very clear:
1.Set project B as library Project (right click->properties->android->is Library)
2.Add this library into Project A (right click->Properties->android->add...->choose Project B->OK
But how can i execute such behavior in AS?
I read article
Create a standalone library with Android Studio
and Create Project A as Library in AS.
Now i create Project B in AS with module BApp,
how can i add Library Project A into B/BApp?
The reason i would not like to copy files of Project A to Project B is, I would also use Library Project A in my many other Project. I dont think it is a good idea that make a hard copy to each Project while i will always update Library A in local.
Appreciation for the Help!
You have to go to Project Structure and add the library as a new module. To do this click on the + icon and select Import Existing Project, once the module is imported go to the Dependencies tab, click on the + icon and select Module Dependency and click on your library.

Get Gradle Path while importing action sherlock project in android. Adding it as librabry

I was just trying importing the action sherlock library to my project in android studio. Once I imported the project it shows to find the gradle path:
Really can't figure out what it means? Does it want build.gradle from the action sherlock project? If so tried that too, the build.gradle does not appear in the chooser window.
But it's there when we try in the file explorer.
Do we have any way around?
The best way to import ActionBarSherlock is to use it via a Maven coordinate-style include rather than downloading the source and trying to import it as a module. In Project settings, select your module, and from the Dependencies tab, click the + button, choose "Library dependency":
. From the dialog that follows, enter the Maven coordinates com.actionbarsherlock:actionbarsherlock:4.4.0#aar
In a more direct answer to your original question, it was asking for the path to your Gradle installation, not the build file. If you want to import modules from source, it's best to update Android Studio -- there have been fixes that went in since 0.5.2 which you're running. In the most recent versions, you can choose "Import Module" from the File menu to import modules from source.

How to import eclipse library project from github to android studio project?

I want to use HoloCircullarProgressBar as a library project in my android studio project.
I tried to do it by copying into pre-created "library" folder in my project and then to add it to project in "Project Structure". But it's not working somehow.
Could anyone give a very specific step-by-step tutorial on how to do that in android studio 0.3.6?
If you're importing a library as source code into a Gradle-based project, then at the moment there's no super-easy way to do it (sorry, it's on the to-do list, see https://code.google.com/p/android/issues/detail?id=62122) so you'll have to author your own build file for the library. Actually, it might be easier to use the New Module wizard to set up the build file and directory structure, then you can trim it down and copy the files over. This set of steps should get you up and running. It seems like a lot of steps but it should hopefully go pretty quick.
From the File menu, choose New Module...
From the wizard that comes up, choose Android Library
From the next page of the wizard, give it the module name HoloCircularProgressBar, and uncheck the options for Create custom launcher icon and Create activity.
Click Finish on the wizard.
It should add the new module to your project, so you'll end up with something like this:
Delete everything inside the src/main folder.
Now copy AndroidManfiest.xml, ic_launcher-web.png, res, and src from the HoloCircularProgressBar source into the src/main folder.
Rename the src folder that you just copied into src/main to java.
The New Module wizard left some things in the build.gradle file in your HoloCircularProgresBar module/directory (make sure you're editing that one, not the one for your main app module) we don't need. Remove the dependencies block and the release block.
At this point you should hopefully be able to build successfully. Now if you want to actually use the module:
Go to File > Project Structure... > Modules > Your main module > Dependencies.
Click on the + button to add a dependency, choose Module dependency, and select HoloCircularProgressBar from the list.
Now import statements and usages of the library should work, and you should be good to go.

Categories

Resources