I have created a library module in my project. Now, I want to share/publish this library with others. Sharing a .aar file would be fine for now.
I went through the article -
https://developer.android.com/studio/projects/android-library and found the following options.
When you want to build the AAR file, select the library module in the Project window and then click Build > Build APK.
However, if you want to share your AAR file separately, you can find it in project-name/module-name/build/outputs/aar/ and you can regenerate it by clicking Build > Make Project.
I have tried these two options, but couldn't find /aar folder in the path project-name/module-name/build/outputs/
This is the first time I am building a library that needs to be shared with others.
Is there something else I need to do? Please share your thoughts.
You should do it using gradle. Just follow these steps and you will get .aar file:
1) At right side of your android studio there is a pane name Gradle. Open it and then do open library portion and run assemble. Like in the picture below.
2) When it is successfully ran just go to your library folder and you will find your .aar files there.
C:\projectPath\libraryPath\build\outputs\aar
You can try manually create .aar from command line
./gradlew <moduleName>:assemble
output is located
<project_path>/build/outputs/aar/<module_name>-<build_variant>.aar
[Read more]
Related
I have added Watchdog jar as a library to the project. I am able to see the code but unable to modify it. How can I edit the jar source code?
Files in the code coming with a lock symbol .
The jar that you added is already packaged, meaning you can't edit it anymore. What you can do, is fork the watchdog library, make your changes to that version, and then build the library and add the newly generated jar to your project.
To do this, first download the sourcecode on github, with the "Clone or download" button. Afterwards, extract the zip file, and open the project in android studio.
Now you can make your changes to the source code. After you are done, go back to your main project, and right click it in the project view. Go to "Open Module Settings", and click on the plus sign in the top left. Then select "Import Gradle Project", and choose the directory, of the downloaded and modified watchdog version. Additionally remove the previously added jar from the project, and you should now have the modified version of watchdog, imported into your project.
You can't do it.
But There is a Transform API in android gradle plugin which allow you to manipulate your source code.
For example you can use javassist inside your transform task and change your jar file.
This solution is a little hard, an easy alternative is to fork Watchdog library and make a new modified jar file
I added the Google Gson jar file to my Android project by copying and pasting the gson-2.2.4 jar file to the libs folder and then right clicked on the Jar file and then select Build Path > Add to Build Path(I followed this tutorial). Then everything worked fine for me with this jar file, but after pushing to github, when my friends pulling this project, they said that all code relevant to that Gson jar file shows errors. How could I fix this?
Problem 1 : Jar doesnt exist. You probably forgot to add, commit and push your changes to github after adding the jar.
Problem 2 : Jar exists but unrecognised. Ask your friends to remove the existing library from java build path using project properties and add again.
You can create a library project which contains the jar file, and then add this library to your project.
Create library project in eclipse:
File->New->Android application project->Next->Check Mark this porject as a library,
uncheck Create custom launcher icon and Create activity->Finish
Add the library to your project:
Right click your project->Properties->Android->Add->Select the library project you created
->Apply->OK
After finishing these two, you should be able to use Gson, and when pushing your project,
remember to push the library project as well.
This is Not a duplicate
I've read each post, and at the flurry site as well...
I have read:
Add the FlurryAnalytics_x.y.z.jar to your classpath
If you're using Eclipse, modify your Java Build Path, and choose Add External JAR.
If you're using the SDK tools directly, drop it into your libs folder and the ant task will pick it up.
I am not using eclipse.
I am not using SDK tools (as best i know).
I AM using android studio...
I am not new to this, but i cant seem to get past the particularities of android studio .. so.
I already have the code added, so i dont need that.
What i need is a step by step on adding the jar file(s), and what "config/build" files that need to be modified....
BWT
if i have a TOP folder MyTestProject, and under that is MyTest, and under that there are build, and source, where Exactly do i put the libs dir ??
In newer versions of Android Studio, the projects it creates will pick up jars that are placed in the "libs" directory in the module. If you want to add it manually, do so through Project Structure > Modules > Dependencies.
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.
I'm trying to use GSON in my project, but my application is crashing, with logcat saying that com.google.gson.Gson cannot be found. I've put import com.google.gson.Gson on my class files, I have gson in my package explorer, and added it by Right click -> build path -> add libraries. It also shows up in Project->properties->java build path->libraries tab->gson. What have I done wrong?
What worked for me: Check the checkbox next to the lib (gson-2.0.jar) in: 'Project Properties' -> 'Java Build Path' -> 'Order and Export' tab. Then do a clean/build.
This adds the exported=true attribute to the classpath entry
<classpathentry exported="true" kind="lib" path="libs/gson-2.0.jar"/>
Have you put the jar file in the libs folder of the project? If not , try moving it there, creating the folder if required. Should be at the same level as the src folder.
I had a similar issue trying to get an app built and that solved it.
I'm using IntelliJ, not eclipse but here is how I did it:
Download the source files from https://google-gson.googlecode.com/files/google-gson-2.2.4-release.zip
Unpack them
Copy them into the "libs" folder of your project. I did this manually by using the terminal but you can do it by going in your project folder located in your computer. Your Project_Name >app >Libs [paste them here]
Go to your editor (IntelliJ in my case) You should see the the following 3 files in the libs folder of the project structure:
gson-2.2.4.jar
gson-2.2.4-javadoc.jar
gson-2.2.4-sources.jar
Open your build.gradle file and insert the following line in the dependencies section:
compile files('libs/gson-2.2.4.jar', 'libs/gson-2.2.4-javadoc.jar', 'libs/gson-2.2.4-javadoc.jar')
Right click on each of the source files and select "Add as Library..."
Use the following options:
Name: name of the jar file
Level: Project Library
Add to Module: select project your adding to
Rebuild project
Build > Rebuild project
Import and use it!
import com.google.gson.Gson;
I have observed today that it doesn't like when you add your library.
The solution that worked for me was to add it as an external jar only. I have observed it by doing the steps described by author of this post i.e. Properties -> Java Build Path -> Libraries -> Add External JARs and point to the downloaded gson library.
I ran into the same issue (when installed SDK 17) ...
The solution is, that you just put the pure jar files into the "libs" folder (without subfolders).
You also don't need to declare them, android wil find them itself. You may need to do a Project > Clean
I had similar problem, but I guess my requirement was more complicated as the GSON libarary was used by an Android Library Project that my main Android project depended on. I have tried both approaches above but none of them worked for me. If I add the GSON jar file directly to the main Android project it works, but that is not what I wanted.
With a bit of investigation I have realised that the GSON jar does not use any dependencies (third party libraries) itself. So my solution was to copy the source file of the GSON project to my Android Library project's src filder and it worked like a charm. so you can use the Source code rather then the binary code. The source code is part of the download in a jar file, just unzip it.
i'm sure you have copied the jar into "libs",
and also added property> Java Build Path >(tab) Libraries, right?
my issue was stupid...
please check other than Gson jar, if you have two stuffs at least in above tab:
android x.x
Android Dependencies (especially this one, i missed this, eclipse show me an error of "could not find class com.google.gson.xx" )
simply do a project copy will solve this problem...
Do not edit .classpath file directly or even put files into lib folders out of Eclipse.
Instead use the Java Build Path->Order and Export tab to select libraries to be exported in the final deployment unit (eg war/apk)
To be on safer side, do a Project->Clean after you change the build path.
I faced the same thing.But the solution was quite easy,just Right-Click on your project->Properies->Libraries->Add external jars->OK and thats it.It solved my problem.hope it will solve yours as well
If Projct Properties -> Java build path -> Add external jars doesn't work and your project is a web project, try adding the gson jar directly to the server lib folder. Example: for apache Tomcat to apache-tomcat/lib.
I have been trying the same thing and read so many answers and tried so many things but to not vial, but i solved this problem by doing just one click and its simple.
1) Add your .jar file in libs folder make sure its libs not lib
2) Clean and Build your project you will see that file under libs folder
3) right click the file and go to build path and select add to build path
Run your project it will work fine. Hope this helps
I am using Android Studio
I had the same problem I had solve it by
select project press f4 from popup
click app and in dependencies
select file dependency and select the three folders which I had pasted in lib directory