How do you edit a dependency/external library in android studio? [duplicate] - java

This question already has answers here:
How do I add a library project to Android Studio?
(31 answers)
Closed 7 years ago.
There is a lot of information about adding libraries and dependencies, but I haven't been able to find any useful information on being able to actually edit a library.
I have added https://github.com/jdamcd/android-crop as a dependency in my project, but I would like to edit some of its features, mostly layout related stuff. However, when I go into browse the files Android Studio says
"files under the build folder are generated and should not be edited" and when I edit them they are returned back to their pre-edited state once the system builds.
I also tried editing the files in notepad++ and the same problem occurs (they are returned to their pre-edited state on build).
Can someone tell me either how to edit the library or a workaround whereby I can change the layouts/some java without having to copy and paste the entire library into my project to make it editable?
Thanks in advance,
God speed.
Edit: The answer is instead of simply adding the library as a dependency in the build.gradle file using this code: compile 'com.soundcloud.android:android-crop:0.9.10#aar'
You have to add it as a module instead of just an external dependency, then you can edit the files.
If anyone is wondering how follows these steps:
Create library folder (call it whatever you want) in the root directory, i.e. the first folder you go into to get to the app and its contents.
Download the library, unzip it.
Put the folder from step 2 in the folder you created in step 1.
Add the module to the settings.gradle like so:
include ':LibraryContainingFolder:ActualLibFolder'
Sync and clean
Go to project structure in Android Studio, click on the main module, normally called app, click on dependencies tab, then click the green plus, then click "Module dependency".
The module should appear written as the containing folder and the library folder in it separated by colons 'something:somethingElse'. Add the module.
Sync, clean, buid etc.

You should add the library as a module in Android Studio, by downloading the code from the Github repository you're interested in (and removing the line under dependencies that you added to build.gradle)
Then follow the steps in this answer: https://stackoverflow.com/a/16639227/1065810

Related

Very similar imports - did I add this dependency twice somehow?

I'm trying to setup the Scichart libraries using this guide.
The library I downloaded has a structure that looks like this:
I copied the 5 .aar files and the 4 documentation .jar files into the libs folder of the app in Android Studio, like so:
Following a guide I read online (I've never added an external library before) I found that for the documentation to work I'd need to add it as an attachment here:
However, when I right clicked and went to library properties it looked like it already had it - I assume that since the files are in the lib folder in the app they're seen and used.
So, everything should work. The problem is that Android Studio is offering to import one of two classes with the exact same package name but different Gradle packages (? don't know if that's the right term) on the right. Picture:
Why is it doing this? What did I do wrong when adding the library?
Per tutorial (Tutorial 01), the sections
Using Maven (well it's more Gradle)
Using bare SciChart libs
Are mutually exclusive.
If you already referenced their libraries via build.gradle (as described in the tutorial, Using Maven part), you don't need (and don't have) to put JAR(s) inside any folder and then add them to the Module settings, or whatever. Even sources will be pulled down automatically.
What you're doing is creating a local repository, in addition to using the remote one. That's why the duplicated libraries.

Adding External jar copy to Project

I created a project but I am using an external library for it. enter link description here
I added the library to my Beans as follows:
Right click on folder "Libraries"
Add Library
Create...
Gave it a name "gson 2.7"
Picked the class, source and javadoc files.
I went on and continued programming and then I added my code to Github. Then when I cloned it my Library was missing.
How can I fix this ? How can I make it dynamic so I dont have to worry about this anymore. In other words I need to add the library to my code and not just the reference.
Thanks a lot for the help
Just upload a copy of your library to github.
I have not used netbeans, but from what I understand it adds the jar somewhere outside of your project directory, and it simply adds the location of the jar to your classpath. When you upload and then clone the project from github, the jars are not uploaded/cloned, and the project structure metadata for your project is also lost from netbeans.
My suggestion is to learn and start using a build tool like maven. It takes up the responsibility of adding your dependency libraries everytime, given that you have an internet connection. It also adds the libs to the target directory of your project folder, so you probably will need the internet connection only once. The libs will be uploaded and cloned back from the github repo everytime.
IDEs like eclipse have inbuilt support for maven, so you don't even have to worry about executing the mvn commands. Here's a tutorial that will get you intrigued - with the IDE that you prefer.
https://platform.netbeans.org/tutorials/nbm-maven-quickstart.html
Thanks a lot for all the replies and comments.
Technically there are two approaches to my problem. For this articular example I chose to copy the external jar files to my project.
1. Copy jar files to your project.
Go to project properties
Under Libraries folder make sure to set up a libraries folder by following the steps.
Add Library at the bottom ( you can create or import; since I already had gson in Netbeans I just imported it.)
Press ok to confirm and you are done!
2. Use Maven
Go to plugings and make sure you have all Maven plugins installed, if not do so.
Create an new project and choose maven/java application
Follow the prompts
At this point you can start coding (in my case I just imported my class files from the other project)
Right click in "Dependencies folder and then "Add Dependency"
Under query type the repository you are looking for; in my case "com.google.code.gson : gson : 2.7"
Click add and you are done!
Thanks a lot to everyone for the help :)

Android Studio 2.0 using external projects with jar and source files

i've been searching all the web for a definitive solution for this simple problem of adding an external directory with .java files and .jar libraries to my Android Studio project.
Here's what I want to do:
Create a default project in Android Studio, and import from git the library I will work on, which is a bunch of .java files and a .jar (jsoup). These java files need this jsoup. The java files are not for Android, just simple java files.
I need it to be from github because I'm working on this lib and I need AndroidStudio to automatically update it to its newest version.
This is how I compile my project:
javac -cp ".:jsoup-1.8.3.jar" Main.java Class1.java Class2.java;
Then I run:
java -cp ".:jsoup-1.8.3.jar" Main
Well, I already loaded this library from github using Android Studio, so now I have:
Project/app/src/main/java/com.myname.myapp
Project/MyLibraryFromGithub
Of course I seen answers like this and I followed everything, but there are some problems. For example, it kept searching for a AndroidManifest.xml file which I don't know how to write because it's a simple java project, not a Android Project. Also, I think this answer is outdated, and won't work properly in AndroidStudio 2.0.
I've read some tutorials on Gradle but it won't say anything about external folders and so. Also, when I make it happen, how do I import my library? For example, in
Project/app/src/main/java/com.myname.myapp/Main.java
How do I import the library? import myLibrary? Or I just need to create new objects with the classe's names? Like Class1 myObject = new...?
This is so congusing! I whish I could compile everything by hand, Gradle is hiding too much from me and I can't find a good tutorial.
To add an external jar to your project you should do the following steps:
Select File >> New >> New Module.
Select Import JAR/AAR Package.
Give the file name in the File name text box and click on Finish.
Select File >> Project Structure.
Select app under the modules section on the left hand side.
Choose Dependencies tab at the top.
Click on the + on the right hand side.
Select Module Dependency
Select the JAR file that you have just imported.
Close both the open windows by clicking OK
Have you tried this?
Place X.jar into the libs folder
Right click on X.jar and 'Add as Library'
(In build.gradle) Place this in dependencies: compile files('libs/X.jar')

How to create jar file from Android Library project

I have a Android library project need to convert this in to a jar file and use it on my Android project.like we are doing on Adds network integrations,Is there any way to achieve this?.
An Android project can't really fit into a .jar file, unless you just wanna use the compiled java files, which you would certainly have done it via a normal Java library project instead of a Android Library Project in first place.
Android Library Projects are packaged into aar files. Read more about it here: http://tools.android.com/tech-docs/new-build-system/aar-format and it is automatically handled by Gradle builds and late Android Maven scripts...this last one used to use a 'apklib' format which has been deprecated to be replaced by aar format. You can read more about it here: https://code.google.com/p/maven-android-plugin/wiki/ApkLib
I've done this before.
But, due to my requirements, i only needed implementation (no android specific resources). Although you can still include Android actual code (if the project you're going to use it in is also an Android project in which you can load the SDK which includes the classes you're exporting in the jar)
Now the .jar file that is automatically generated in the bin folder, will not allow you to do this because it includes all the Android's project resources (which is not understood in the Jar format). Therefore, you must exclude all except the src folder. Note : Make sure you also exclude the files in the root folder of the project (i.e, AndroidManifest.xml, etc .. )
In Eclipse : Project properties -> Export -> Jar -> (Include only src folder)
If you're project library includes native code ( NDK ), there is a few other workaround that you need to do to get it to work. If this is the case, comment below, i'll help you out.
Cheers

How to add a library to an android project?

I have downloaded a messaging framework library from eneter.net. In eclipse I have imported the library to the /libs folder. I right clicked on the library and then added it to the build path. I know that the code is right, but when I compile it and try to run it, it says that that it can't find the classes. Odd thing is when I open up the apk in a zipping program, the library wasn't added to the apk at compile time. Does anyone know why this would be?
Try right-clicking your project in Eclipse's project explorer, then hit Properties. Go to the tab labeled Java Build Path and hit Add Library... (or if it is a jar file, Add JARs... if you already added the Jar to your project and Add External JARs... if it is not yet within the project). From there, browse for the library you wish to add and add it to the project. Re-compile (maybe even Project->Clean) and try running it, and see if the library gets added now.
I right clicked on the library and then added it to the build path
That is not necessary, as of the R17 version of the ADT plugin in Eclipse. Moreover, it may cause problems if you do it.
Does anyone know why this would be?
Possibly because there is a typo in your directory name, such that it is not named libs/. By adding it manually to your build path, you are compiling against it, but the build tools are not adding it to the APK.
Is the library in the form of a complete Android project? This is then used with another Android project by going to the Properties of that project, selecting the Android tab, and then finding and selecting that library in the lower window.

Categories

Resources