Android studio how to build a project from github source - android

How do I build a android studio project from github repository that only contains the source codes, no gradle build information. For example. I want to build a project from this repository https://github.com/googledrive/android-quickstart, but the android project could not be built correctly. Can I just add the build.gradle and expect the project to work?

This is a project in eclipse. Just download the zip file, and extract it. Then in android studio, import the existing Eclipse project by hitting File -> Import Project. Android Studio will just build you a AS project, including all the gradle files.

You can just create a new project with same package name as in the github project.
This will create a compilable android project/library. after that manually copy the code by downloading from github (download as zip) and then just copy the source folder.

There are three ways to do this that I know of officially.
1) Add project directly
Step 1:
Add project into following directory {App Root Folder}/Libraries/ (create libraries folder if doesn't exist)
Step 2:
Go to File/Project Structure/ under Dependencies tab click green add icon and select Module dependency and select the project you added to libraries.
2) Add project as a .jar/.aar
Step 1:
Either look for a the version of .jar/.aar you are looking for on web or compile project to .jar/.aar.
Step 2:
Follow Step one for previous way but instead select Library dependency
3) Add project from Maven
Step 1:
Find library on gradleplease.appspot.com
Step 2:
Add compile 'package name' under dependencies in your apps build.gradle

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 add libarary which don`t have compile dependencies android studio?

I want to add DonwloadProvider library to my android studio project but it doesn`t have any compile dependencies.
so therefore I searched so much but did not find any related answer
please anyone help me with this it is very important for me
Download the Project from the github and add it under your project folder
Do the following steps
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.
4. Let Android Studio build the project.
Open build.gradle (Module:app) file.
References:
How to add library projects

Run Facebook SDK sample apps in Android Studio

Novice question.
What is the recommended way to run the sample apps, included in the Facebook SDK, in Android Studio (0.8.6)?
The ideal answer would include step-by-step instructions.
I'm using Android Studio version 0.8.0, and Facebook SDK 3.18.
When I tried to open a sample as a separate project, it can't find Gradle and wasn't able to run it. However, when I imported /samples folder as a root, all sample projects were imported and was able to run each samples.
File > Import Project > Select FACEBOOK_SDK_PATH/samples > OK > Create project from existing sources
and then, click next/ok as Android Studio's default setting.
Hope it helps!
Suposing you already downloaded and unzipped the SDK.
Create your android project. Gradle based.
File -> Import Module. Navigate to the unzipped folder and select the unzipped folder.
Add the library dependency in your main module (the one created with your project) adding this line in your build.gradle:
Synchonize project.
If you want to continue creating your own app, you might add the dependency module build.gradle file:
android {
dependencies {
compile project (':facebook')
}
}

Android facebook sdk import error

i had download facebook skd import it in my eclipse add v4 jar file and change complier to 1.6 but yet it give me error in class FacebookAppLinkResolver
import bolts.AppLink;
import bolts.AppLinkResolver;
import bolts.Continuation;
import bolts.Task;
above are not import
1.Open your project properties
2.Select "Java Build Path" from left side menu
3.Select "Libraries" tab
4.Press "Add External Jar"
5.MOST IMPORTANT STEPS :-
Select "bolts" jar file of "libs" folder of YOUR CURRENT PROJECT LOCATION(Path Should be
of your project only and not the android sdk).
6.Select "Order and Export" tab and "TICK" the checkbox of "android-support-v4.jar"
Download sdk for Bolts library from
https://github.com/BoltsFramework/Bolts-Android
and add this project with facebook sdk project.
Or if you're using Gradle you can add this to your Gradle file:
dependencies {
compile 'com.parse.bolts:bolts-android:1.1.3'
}
Facebook is also available so you don't have to add that manually either. To include both use the following:
dependencies {
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.parse.bolts:bolts-android:1.1.3'
}
You can check for the latest version of Bolts here.
amalBit's answer works great for Eclipse. Here is the Android Studio equivalent.
I encountered this error after updating to the latest Facebook SDK for Android.
File ->
Project Structure ->
Select the Facebook module on the left
Select the Dependencies tab
Press the + button at the bottom of the
window
Select File Dependency
In the libs folder, you should see the
bolts.jar file you copied over when updating the SDK.
Select the
bolts.jar file and press OK
Then press Apply and OK
Doing a Gradle Sync (happened automatically for me) should resolve the error.
I had the same problem. Check your facebook-sdk/facebook folder to see if there is a libs file (Not directory)
So I think Android studio failed to import the libs as a directory instead included a libs file with "../libs" in it.
Not sure if this was facebook-sdk issue, git cloning issue or android studio issue.
Solution:
1. remove the dummy libs file
2. copy the libs directory manually
3. remove the dependency in project structure
4. add it manually by clicking + sign

importing jar libraries into android-studio

android-studio 0.2.7
Fedora 18
Hello,
I am trying to add the jtwitter jar to my project.
First I tried doing the following:
1) Drag the jtwitter.jar into the root directory of my project explorer, see picture
2) File | project structure
3) Modules | yamba-yamba | dependencies
4) Click the plus sign | jars or directories | and navigate to jtwitter jar | click ok
When I import the jar file I get the following error:
import winterwell.jtwitter.Twitter;
Cannot resolve symbol winterwell
Gradle: error: package winterwell.jtwitter does not exist
I researched and found that android-studio has some issues and that you have to edit the build.gradle file yourself.
So I tried adding this to my build.gradle file:
dependencies {
compile files('libs/jtwitter.jar')
And got an error message: cannot resolve symbol dependencies
Another question, where would the libs folder be. Does it mean the External Libraries?
Try this...
Create libs folder under the application folder.
Add .jar files to libs folder.
Then add .jar files to app's build.gradle dependency.
Finally Sync project with Gradle files.
1.Create libs folder:
2.Add .jar to libs folder:
3.Edit app's build.gradle dependency:
Open app/build.gradle
4.Sync project with Gradle files:
Finally add .jar files to your application.
UPDATE:
Here I'm going to import org.eclipse.paho.client.mqttv3.jar file to our app module.
Copy your jar file and paste it in directory called libs.
Press Ctrl + Alt + Shift + s or just click project structure icon on the toolbar.
Then select your module to import .jar file, then select dependencies tab.
Click plus icon then select File dependency
Select .jar file path, click OK to build gradle.
Finally we're imported .jar file to our module.
Updated answer for Android Studio 2
The easy and correct way to import a jar/aar into your project is to import it as a module.
New -> Module
Select Import .JAR/.AAR Package
Select the .JAR/.AAR file and put a module name
Add the module as a dependency
Running Android Studio 0.4.0
Solved the problem of importing jar by
Project Structure > Modules > Dependencies > Add Files
Browse to the location of jar file and select it
For those like manual editing
Open app/build.gradle
dependencies {
compile files('src/main/libs/xxx.jar')
}
In the project right click
-> new -> module
-> import jar/AAR package
-> import select the jar file to import
-> click ok -> done
You can follow the screenshots below:
1:
2:
3:
You will see this:
Android Studio 1.0.1 doesn't make it any clearer, but it does make it somehow easier. Here's what worked for me:
1) Using explorer, create an 'external_libs' folder (any other name is fine) inside the Project/app/src folder, where 'Project' is the name of your project
2) Copy your jar file into this 'external_libs' folder
3) In Android Studio, go to File -> Project Structure -> Dependencies -> Add -> File Dependency and navigate to your jar file, which should be under 'src/external_libs'
3) Select your jar file and click 'Ok'
Now, check your build.gradle (Module.app) script, where you'll see the jar already added under 'dependencies'
This is how you add jar files from external folders
Click on File and there you click on New and New Module
New Window appears ,,There you have to choose the Import .JAR/.AAR package .
Click on the path option at the top right corner of the window ...And give the whole path of the JAR file .
4)click on finish.
Now you have added the Jar file and You need to add it in the dependency for your application project
1)Right click on app folder and there you have to choose Open Module Settings or F4
2)Click on dependency at the top right corner of the current window .
3)Click on '+' symbol and choose 'Module Dependency' and It will show you the existed JAR files which you have included in your project ...
Choose the one you want and click 'OK/Finish'
Android Studio 1.0 makes it easier to add a .jar file library to a project.
Go to File>Project Structure and then Click on Dependencies. Over there you can add .jar files from your computer to the project. You can also search for libraries from maven.
This is the way I just did on Android Studio version 1.0.2
I have created a folder libs in [your project dir]\app\src
I have copied the jtwitter.jar (or the yambaclientlib.jar) into the [your project dir]\app\src\libs directory
The following the menu path: File -> Project Structure -> Dependencies -> Add -> File Dependency, Android Studio opens a dialog box where you can drag&drop the jar library. Then I clicked the OK button.
At this point Gradle will rebuild the project importing the library and resolving the dependencies.
I see so many complicated answer.
All this confused me while I was adding my Aquery jar file in the new version of Android Studio.
This is what I did :
Copy pasted the jar file in the libs folder which is visible under Project view.
And in the build.gradle file just added this line : compile files('libs/android-query.jar')
PS : Once downloading the jar file please change its name. I changed the name to android-query.jar
There are three standard approaches for importing a JAR file into Android studio. The first one is traditional way, the second one is standard way, and the last one is remote library. I explained these approaches step by step with screenshots in this link:
https://stackoverflow.com/a/35369267/5475941.
I hope it helps.
If the code for your jar library is on GitHub then importing into Android Studio is easy with JitPack.
Your will just need to add the repository to build.gradle:
allprojects{
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
and then the library's GitHub repository as a dependency:
dependencies {
// ...
compile 'com.github.YourUsername:LibraryRepo:ReleaseTag'
}
JitPack acts as a maven repository and can be used like Maven Central. The nice thing is that you don't have to upload the jar manually. Behind the scenes JitPack will check out the code from GitHub and compile it. Therefore it works only if the repo has a build file in it (build.gradle).
There is also a guide on how to prepare an Android project.
Avoid redundancy. If you have your jars under /libs in your app build.gradle by default you will have
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
...
}
that is enough to add all the jars you have under /libs
this is not necessary
// compile files('libs/activation.jar')
// compile files('libs/additional.jar')
// compile files('libs/mail.jar')
I also faced same obstacle but not able to find out solution from given answers. Might be it's happening due to project path which is having special characters & space etc... So please try to add this line in your build.gradle.
compile files('../app/libs/jtwitter.jar')// pass your .jar file name
".." (Double dot) will find your root directory of your project.

Categories

Resources