Importing roottools.jar into Android Studio - android

I'm trying to import roottools from here: https://code.google.com/p/roottools/ (jar file) to the Android Studio project. So far I've tried the following:
copy RootTools-javadoc-3.4.jar into libs directory under my project.
Add imports
Reorganize imports.
Rebuild project
But still I don't have "acces" to it's methods. Is it possible that is only compatible with Eclipse?

I tried using the JAR available for download and it didn't work either. To get this working, I had to download the project available at github here. Compile and run the task "makeJar" (right click on task makeJar in the gradle.build and select run).
I just added this new jar in the libs and referenced in the gradle.build file.
dependencies {
...
compile files('libs/RootTools.jar')
}
or you can add it via Project Properties.
It worked perfectly (don't forget to sync your the gradle files if you edit it manually).

In your project, choose File menu > Project Structure (there's a bug in 0.4.4 and this menu item won't have a title at all; it still works) > Modules > choose your module > Dependencies > + button > File dependency > choose your library from the file picker. That file needs to be somewhere beneath the root directory of your projet; the libs directory is fine.
Screenshot of the Project Structure dialog:

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 to add "Empty Module" in Android Studio?

I am trying to add AndEngine to my Android Project using the tutorial here: https://docs.google.com/document/d/1fcSowvlKMqfTjM9r1mMP48KEhWbkJZGBDR5duFg4QYc/edit
I am stuck at Step #6 in the tutorial, unable to see the "Empty Module" option in my Android Studio Envt. (Version 0.4.0)
Their instructions were written for Android Studio 0.2; this dialog has changed since then. They have some hasty steps for 0.3 which should work; I've amended them:
Download andengine.jar (Google it, there is no official download)
Create your own libs folder in your project
Copy andengine.jar into this folder
File > Project Structure > Modules > Dependencies > + button > File Dependency > select andengine.jar
If you need more help, there are many other answers on SO on how to add a jar library to Android Studio; they vary a little bit based on what version of Android Studio they're written for, but they should help you out. Many of them have you modify your build.gradle file directly; the UI steps above accomplish much the same thing and make the edits on your behalf.
You can simply copy the AndEngine module inside your project directory and then configure your build.gradle and settings.gradle to include it in to dependencies like
----YOUR_PROJECT
---AndEngine
--res
--src
-- .....
-- build.gradle
---YOUR_MODULE
--res
--src
--build.gradle (no : A)
----settings.gradle
build.gradle (No. A) file
dependencies {
compile project(':AndEngine')
}
settings.gradle :
include ':YOUR_MODULE'
include ':AndEngine'
As Observed AndEngine is not moved to gradle yet, In that case download create jar using ant or eclipse.
The create a libs folder inside your Project
----YOUR_PROJECT
---YOUR_MODULE
--libs
-AndEngine.jar
--res
--src
--build.gradle (no : A)
----settings.gradle
Now go to File > Project Structure > Modules > Dependencies > + green button > File Dependency > select AndEngine.jar and press OK
You will see these lines will be automatically added in your build.gradle file inside dependencies, you can add this manually as well no difference.
compile files('libs/AndEngine.jar')

Android Studio not showing modules in project structure

I am using Android studio and I want to add module to my project like
"action bar Sherlock" or jar files,
but when I opened the project structure there is no module or library in the menu :\
In intelij it's appearing:
So what's the problem? How can I add these modules in Android studio?
Update 19 March 2019
A new experience someone has just faced recently even though he/she did add a library module in app module, and include in Setting gradle as described below. One more thing worth trying is to make sure your app module and your library module have the same compileSdkVersion (which is in each its gradle)!
Please follow this link for more details.
Ref: Imported module in Android Studio can't find imported class
Original answer
Sometimes you use import module function, then the module does appear in Project mode but not in Android mode
So the thing works for me is to go to Setting gradle, add my module manually, and sync a gradle again:
First, create your Module. You can do that using the default Android Studio Module Wizard (File -> New -> New Module), select Android Library, give it a Name and a package name, and finish.
After that you will see that nothing happens. Open the side Gradle Projects Section (should be somewhere on the right panel)
You should see something like this:
Expand your module gradle and run the Run Configurations task.
After that refresh the content and refresh the project structure.
It should work now.
Do right mouse click on your project, then select 'Open Module Settings' - then you can add modules to your project..
Go to File->Project Structure-> Project Settings -> Modules.
Click on the green colored + and add new module. select Application module and set the content root to your project module.
Click next and then finish.
Reference
You need to add a gradle.settings file to your root project structure, after that when you "Open Module settings" you will the menu aligned to your gradle.settings. When importing a project to Android Studio, it doesn't create this file for you. Sometimes it's usually better to start a clean project and move your code there, it's usually easier to achieve.
This Might be help some:
To import module as library in your project.
File > New > Import Module
Select Valid path in Source Dir..
Tick on Import > Finish
Now Open Module setting:
Go to File > Project Structure > Modules
Modules > Dependency > click on Green Plus Sign.
Click on Module Dependency > locate module > and Implement your module.
if your module is not shown in "Choose Modules Window"
Follow the below step..
Open Settings.Gradle file
include ':app', 'Put your module name here' and sync project.
Follow Open Module Setting as above.
As for me issue was that the first line in the build.gradle file of the OpenCV library.
It was something like this:
apply plugin: 'com.android.application'
This refers to the fact that the imported OpenCV is an application and not a library. It exists for OpenCV above 4.1.0. So change it to:
Something like this:
apply plugin: 'com.android.library'.
You might get an error in ApplicationId, comment it out in the gradle file.
Open settings.gradle and add the module as below,
include ':app',':bottomnav'
here i have added my newly imported module ':bottomnav' separated with a comma. then Sync your project. your module will be visible to dependency.
Android Studio only displays those module, which are defined in the settings.gradle file of your application.
after defining the module in settings.gradle, you will be able to add the module as dependency of your application.
I had the same problem, after switching to a branch that did not have my module, then switching back.
Clean Project -> Rebuild Project did not work for me.
But File -> Invalidate caches/restart did work.
Check settings.gradle. You'll find this : include ':app'
Just add your own module name and it should look like this :
include ':app', ':yourModuleName'
Sync.
That's it.
Had similar issue when running version control on a project in Android Studio (0.4.2). When pulling it down to a new location and importing the modules, only the "Android SDK" were showing in the Project Structure.
I removed the .idea/ folder from the version control, by adding it to .gitignore file, and did a fresh pull and imported the modules. Now all the settings appeared correctly in the Project Settings and Platform Settings for the Project Structure.
Here's what I did to solve this problem
Close Android Studio
Quick Start -> Check out from Version Control
Please go to Module settings
and choose Modules from Project Settings
then you need to Select src and gen folders and marked them as Source folders by right-click on them and select Source
First You Have To Add Name Of Your Module In setting.gradle(Project Setting) File Like This..
include ':app', ':simple-crop-image-lib'
Then You Need To Compile This Module Into build.gradle(Module app) File Like This..
implementation project(':simple-crop-image-lib')
That's all for adding module now it will be appear in android section or project section as well.
If It's till did't appear rebuild or clean your project..
Although not similar to the question above,
In my case,
The module is not visible in the android tab,
I saw it in the project tab.
After deleting the .idea/workspace.xml file, (I guess there is a problem because the unloadlist list remains here?)
When I reopened the project, it worked fine.
Additionally,
When invalidate caches (clear VCS Log caches and indexes),
It shows up for new modules, not for previously deleted modules (this only worked when deleting workspace.xml).
If you moved the modules, modify your workspace.xml file and settings.gradle file to use the new paths of your module.
Otherwise you will need to try using the import module feature.
Make sure the directory name is lower case.
First and foremost, check that all the modules are listed in your settings.gradle file.
If they are not, add them.
If they are, change something/anything in the file so that the Sync Project prompt comes on. Sync and your project should compile fine; the modules you're looking for will appear in your project structure.
in my case somehow build.gradle file deleted under app i restore it

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.

Android Studio - Importing external Library/Jar

I recently downloaded Android Studio to develop Android applications (I'm coming from Eclipse), and I am having issues using external libraries and/or external JAR files alongside my own project. NOTE: the following tests were conducted on a new application project created from scratch in Android Studio.
Example 1: JAR Import.
Download a fresh copy of the Admobs SDK from Google.
Copy the library jar GoogleAdMobAdsSdk-6.4.1.jar to the project's /libs/ folder.
In the project explorer, right click on the newly added library.jar and click on 'Add as Library'.
Technically at this point everything works, imports work just fine, the layout editor shows a preview of the AdView widget and all that. The only problem is that it doesn't compile successfully.
Log from console:
Gradle:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':APITests:compilePaidDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
I tried running gradlew compileDebug --stacktrace, and the problem seems to be that the despite being able to import the classes successfully in both the code & design editor, at compile time, it cannot resolve the imports. Here's the relevant part of the log: (full stacktrace here)
java:6: error: package com.google.ads does not exist
import com.google.ads.AdRequest;
java:7: error: package com.google.ads does not exist
import com.google.ads.AdView;
java:11: error: cannot find symbol
AdView mAdView;
symbol: class AdView
location: class MainActivity
java:22: error: cannot find symbol
mAdView = (AdView)this.findViewById(R.id.adView);
symbol: class AdView
location: class MainActivity
java:23: error: cannot find symbol
mAdView.loadAd(new AdRequest());
symbol: class AdRequest
location: class MainActivity
5 errors
:Test:compileDebug FAILED
But again, the imports work well in the editor, and the dependency is there:
It's also worth noting that without attempting to add a library/JAR, the projects compiles just fine.
I then tried editing the build.gradle file to include the new lib like this:
dependencies {
compile files('libs/android-support-v4.jar', 'libs/GoogleAdMobAdsSdk-6.4.1.jar')
}
This time, it did compile successfully, but the app now forces closes, as apparently, it cannot find a specific class from the lib in the application package.
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /data/app/com.foo.test-1.apk
Any ideas?
So,
Steps to follow in order to import a JAR sucesfully to your project using Android Studio 0.1.1:
Download the library.jar file and copy it to your /libs/ folder inside your application project.
Open the build.gradle file and edit your dependencies to include the new .jar file:
compile files('libs/android-support-v4.jar', 'libs/GoogleAdMobAdsSdk-6.4.1.jar')
File -> Close Project
Open a command prompt on your project's root location, i.e 'C:\Users\Username\AndroidStudioProjects\MyApplicationProject\'
On the command prompt, type gradlew clean, wait till it's done.
Reopen your application project in Android Studio.
Test run your application and it should work succesfully.
You don't need to close the project and go to command line to invoke grade:clean.
Go to Build-> Rebuild Project
Easy way and it works for me. Using Android Studio 0.8.2.
Drag jar file under libs.
Press "Sync Project with Gradle Files" button.
"simple solution is here"
1 .Create a folder named libs under the app directory for that matter any directory within the project..
2 .Copy Paste your Library to libs folder
3.You simply copy the JAR to your libs/ directory and then from inside Android Studio, right click the Jar that shows up under libs/ > Add As Library..
Peace!
Here is how I got it going specifically for the admob sdk jar file:
Drag your jar file into the libs folder.
Right click on the jar file and select Add Library
now the jar file is a library lets add it to the compile path
Open the build.gradle file (note there are two build.gradle files at least, don't use the root one use the one in your project scope).
Find the dependencies section (for me i was trying to the admob -GoogleAdMobAdsSdk jar file)
e.g.
dependencies {
compile files('libs/android-support-v4.jar','libs/GoogleAdMobAdsSdk-6.3.1.jar')
}
Last go into settings.gradle and ensure it looks something like this:
include ':yourproject', ':yourproject:libs:GoogleAdMobAdsSdk-6.3.1'
Finally, Go to Build -> Rebuild Project
you export the project from Eclipse and then import the project from Android Studio, this should solve your problem, open a eclipse project without importing it from Android Studio you can cause problems, look at:
(Excuse my language, I speak Spanish.)
http://developer.android.com/intl/es/sdk/installing/migrate.html
I had the problem not able to load jar file in libs folder in Android Studio.
If you have added JAR file in libs folder, then just open build.gradle file and save it without editing anything else. If you have added this line
compile fileTree(dir: 'libs', include: ['*.jar'])
save it and clean the project .. In next build time Android Studio will load the JAR file.
Hope this helps.
I'm using Android Studio 0.5.2. So if your version is lower than mine my answer may not work for you.
3 ways to add a new Jar to your project:
Menu under Files-->Project Structure
Just press 'F4'
under Project navigation, right clink on any java library and a context menu will show then click on 'Open Library Settings'
A Project Structure window will popup.
On the left column click on 'Libraries' then look at the right pane where there is a plus sign '+' and click on it then enter the path to your new library.
Make sure the new library is under the 'project\libs\' folder otherwise you may get a broken link when you save your project source code.
I am currently using Android Studio 1.4.
For importing and adding libraries, I used the following flow ->
1. Press **Alt+Ctr+Shift+S** or Go to **File --> Project** Structure to open up the Project Structure Dialog Box.
2. Click on **Modules** to which you want to link the JAR to and Go to the Dependency Tab.
3. Click on "**+**" Button to pop up Choose Library Dependency.
4. Search/Select the dependency and rebuild the project.
I used the above approach to import support v4 and v13 libraries.
I hope this is helpful and clears up the flow.
I use android studio 0.8.6 and for importing external library in project , paste that library in libs folder and inside build.gradle write path of that library inside dependencies like this
compile files('libs/google-play-services.jar')
In Android Studio (mine is 2.3.1) go to File - Project Structure:
Check the libs version requirements. The lib might be trying to call a method from from a higher Android version. Try adding the apps compatability libs.
When all else fails try switching from a Gradle build to an Eclipse build.
Delete and restructure your folders to the eclipse style and delete everything but your code. Then reload the project with your libs.
Once it runs go back to Gradle, if you wish.

Categories

Resources