Using volley the right way within eclipse - android

I'm working with eclipse mars on ubuntu 15.04.
I'm trying to do the tutorial about volley (https://developer.android.com/training/volley/simple.html) but I'm facing some difficulties.
As explained in this tutorial, I've cloned the volley repository, created an android projet for it, marqued it as a library. I can see that ./src/main/bin/volley.jar is generated, so at that point I would say that everything is good.
Next, I created an Application project and in Projet>Properties>Android I've added volley as a library.
If I well understand the tutorial and some other answers about similar questions I've read, this is the correct way to go.
Anyway, in my code if I try some "import com.android.volley;" I always get the same "The import com.android.volley cannot be resolved".
The only way I can make it work is by adding the source code of volley into my project directly. Obviouly this is not the good solution.
Can someone please tell me what I'm doing wrong ?
Regards
EDIT1:
Thank for the comments but it appears to me that those information are a little bit out of date. If I refer to the git history, volley switched from Gradle to Maven 8 months ago, so it does not build with ant.
Any way, as I said in my question, the project is already building within eclipse so that I have a volley.jar. So I try what is suggested: copie the volley.jar into the libs folder on my project. I'm surprised it does not work :/ Looking closely to the jar file I'm surprised it weighs only 166 bytes!
Referring to https://developer.android.com/tools/projects/projects-eclipse.html:
Creating the manifest file: A library project's manifest file
must declare all of the shared components that it includes, just as
would a standard Android application
and
Declaring library components in the manifest file: In the manifest file of the application project, you must add declarations of all components that the application will use that are imported from a library project. For example, you must declare any <activity>, <service>, <receiver>, <provider>, and so on, as well as <permission>, <uses-library>, and similar elements.
Declarations should reference the library components by their fully-qualified package names, where appropriate.
May it happen that the default manifest file from volley is incorrect and it does not "export" anything which makes the jar file being so small?
Does it mean that I have to put in both manifests (the one from volley and the one of my app) any import I did in my code?

Related

Using aar in Eclipse - why does the 3rd party activity resolve at build time but not run time?

I have a mature app that needs to have an SDK brought in that wraps the camera and makes it do some spiffy processing while it's running. The SDK has come to me in the form of some aar files but my app still lives in Eclipse. Because of my massive, steaming pile of a branding structure and deadlines for this integration the uncertain timeline required to fully migrate to Android Studio will not work (for now) so I'm going for converting the aars and using them in my app via Eclipse.
The problem I'm having is that I need to kick off the activity in the library but even though I fixed up all my build time reference problems, when running the app once I get to the point that is supposed to kick off the activity I get this error.
I've read through and double checked dozens of how-tos explaining how to consume the aar files and I think I've followed every step including:
Unzip the aar files and dress them up as individual library projects, including the file structure with the resources, the manifest, and the .jar
Make the project that needs the libraries add them as such
Add the .jars contained in the library projects to the build path (this step was not listed in most articles, and wasn't necessary for the project to build, but nevertheless it did not help my problem)
Declare the activity in your AndroidManifest.xml that the library brings in and declares in its AndroidManifest.xml
As I've said, everything looks good at build time, so I'm not sure what else to check. Because I'm reading that Gradle and Android Studio mashes manifests together really well, I have a hunch that it's something I'm supposed to regulate between the manifests but I don't know what it could be if that is it. I've wondered if I'm declaring the 3rd party's activity properly, but I'm not sure how to test it because the only way I can think to test it is to provide gibberish for the namespace but even then there are no complaints. I've also tried dissecting the .apk to look at the .dex file but I could not decipher anything useful.
My guess is that the library may not be building properly in eclipse - even before it's being added as a dependency to the application project.
Try looking at out/classes/* and making sure you have a .class file for the activity in question. I think the .class should actually be in the library as well as end up in the application project's out/ dir also.
If there are any native files (x.so) (as I would imagine there might be for spiffy camera stuff), you can look for the x.so files being included in the out/ dirs of both the library and application projects as well as the library.jar file.
Another option to maybe consider for this use case: https://github.com/ksoichiro/gradle-eclipse-aar-plugin
It seems that our app had a bad version of the appcompat-v7 support library. The .jars in it were different sizes than the one that comes with the SDK and several resources were missing. I have no idea how we ended up that way or where this bad version came from. Once I replaced it, things went great.
Later, I did encounter the need to drop in the .so files into the libraries I made that came out of the .aar files as Stad Kurdziel said in his answer, but that was causing a different error (the exception explicitly states that the .so is missing) and I arrived at the solution independently.

Android: Using make with external java libraries

I have split out common components into libraries using Eclipse. Everything works great. I have resources/etc in the library. However, I need to make the same functionality work with using make instead of Eclipse. I need the libraries to recompile every time the APK is made.
Completely a noob question, but everything I am finding deals with making it work in Eclipse or creating a Jar file and inserting it into the project.
Thanks - Keith
create jar file:
You could use the Export->Java->Runnable Jar to create a jar that includes its dependencies
check this tutorial, And this similar type question

Android library project as jar file for distribution, like google analytics

I have seen this question, and have some more doubts regarding creating a jar file which I can distribute and can be used in any android applications.
What my requirement is
As I said, I want to build and distribute a closed source library. I
don't want the source code to be visible.
In that library I don't want to use any assets, layouts, resources
etc. But I want to use some android specific codes, like getting
android device id.
The most popular answer in the above linked SO question tells to create a regular java project and import android.jar in it. I tried to do that, but I don't know how to add android.jar to any java project. I would like to get some clarification on that too.
Moreover I would like to know if there are any other methods using android sdk itself (without using java project) create a closed source library jar file.
I think what I want is possible, since google analytics for android native apps seems to have done it. I am sure in the .jar file they distribute they are using android specific codes, since there seems no other way for them to get the device information to display in the analytics viewer.
EDIT : CAN SOMEONE CLARIFY THIS??
I think I have made some progress. This is what I have done
Created a regular android project (not library project, the "is
Library" checkmark is unchecked)
In the project I have coded out my logic. It uses some android
specific classes like SharedPreference, UUID, PackageManager. But
nothing related with assets, layouts also no class extending
Activity. Just a java class extending java.lang.object
Exported the project using Project->rightclick->export->Java->JAR
file. In the next screen I unchecked the checkbox near
AndroidManifest.xml. Set a destination directory to export and
clicked next thrice with keeping the default settings. Then I clicked
Finish, and got a lovely libMyLibraryName.jar at my desktop.
Then I created another android project, added this libMyLibraryName.jar to new project using project->rightclick->properties->java build path -> libraries->add external jar.
And I tried to use my class in the library, in my new project
MyLibraryClass objClass = new MyLibraryClass(this);
And I was able to compile and run successfully. I even sent the library to one of my co worker who was able to use the library in his on machine (Just making sure library project in my workspace wont influence the project using it).
Now I have 2 questions.
1) My first question is , what they meant by the term "true library" in the below given documentation ? Is it any non android java project which can be exported to a JAR file?
However, a library project differs from an standard Android
application project in that you cannot compile it directly to its own
.apk and run it on an Android device. Similarly, you cannot export
the library project to a self-contained JAR file, as you would do
for a true library. Instead, you must compile the library indirectly,
by referencing the library in the dependent application and building
that application.
Well this portion is taken from documentation under title "Library Projects".
2) My second question is, anything wrong with the way I have created the JAR file? Any possible pitfalls which might bite me back later? I would like to make sure I am not doing something terribly wrong, before using it in my important projects.
I might add that I didn't try the method of creating a JAVA project and importing android.jar. I am ready to try that one, if what I have done currently is wrong.
The android.jar will be located where you installed your Android SDK. Under the platforms directory there should be a number of other directories named android-<version>. The android.jar will be there. Choose the one specific to the minimum android version you are targeting.
Once you have that, copy it into your project. If you're using eclipse I think you can just cut and paste jars straight into your project, right click and add it to build path. If you're not using eclipse or any other IDE, you just need to ensure that the android.jar is on the classpath when building your jar file.
After that your newly built android library can be dropped into any Android project.
In answer to your additional questions:
What they mean by a true library is a jar file as opposed to an Android library project.
I don't think there's anything wrong with the way you created the jar file. I would have made it using the android.jar as I mentioned above but your way should also work. To verify this I would examine the jar contents and make sure all you have in there is .class files.

Android project as Jar Library

I am currently working on a Android Project where we are expected to merge our App with 2 more apps from vendors who wouldn't be sharing their code.So just wanted to know Is there any way we could just include there Source code as JAR Files in our project and then include their resources and point to them(I did do it using getResources().getIdentifier("splash", "layout", getPackageName()) But Its still not working ?? I think I have tried all possible methods so hoping you guys could help me with this.
To quote CommonsWare from this question:
Bear in mind that your packaged classes cannot reference resources (at
least not via R. syntax), and that JARs cannot package resources,
manifest entries, etc. If all you are trying to JAR up is pure Java
code (perhaps using Android APIs), then you should be fine.
Basically, you can only use JARs that contain pure java as libraries in your app, not entire other projects.
The Activities can be compiled into a jar and added to the main Android project and we need to add their project's resources into your Project. The only we could make it work is using the getResources().getIdentifier("splash", "layout", getPackageName()). Even the Widgets like TextView, Button and all those should be referred to using the getResources() method. Like, for example, If you want to perform a action on particular button then we need to identify them by getResources().getIdentifier("Button" /*id in the XML File*/, "id"/*type*/, getPackageName()).
One more thing: you need to specify all the Activities in your Main Android Project's AndroidManifest.xml file with their package name. I hope this solves something.
In order to support faster build times, the r16 tools are creating their own jar files inside of Android Library Projects. You can use this feature to solve this issue. If a vendor would like to release their Android Library Project but without source code, they can make a copy of that Android Library Project that contains everything except for the source code tree. Next, include the jar file from the original Android Library Porject (the one that the r16 tools built.) This will allow you to have a component you can distribute that does not require source code. The consumer of this new Android Library Project will need to manually add any necessary meta data to their own project's AndroidManifest.xml file as needed (Activities, Providers, Permissions, etc).

merge two android projects

i want to merge two different android projects to use the functionalty of both in one project.
They are using complete different packages for the files.
I copied the files with the different packages in one project, but there is a problem with the manifest file.
Is it possibly to have different packages in the android manifest file?
Or how can i solve this? Maybe specify the activities with the whole package and not use ".shortcut" ?
I hope there is someone to help me.
Thanks!
Building a library can solve this problem. This is the way I have proceeded on my side for a similar question:
I had a project ProjectA that was finished and working
I had a new project ProjectB that had to reuse some functions of ProjectA.
These functions were likely to be reused again so I built a library Library1 and I moved the necessary code from ProjectA to it. I set the Library1's isLibrary flag to true under Eclipse (that's in the project properties - let me know whether you would like more details on this and I'll edit that post if needed).
Then I modified the ProjectA's properties to use Library1. This also implied some refactoring on ProjectA side but that was OK.
And finally, I created my ProjectB as a client of Library1 as well. And this was straightforward.
There is no easy way to merge multiple projects into one. However, you can choose to build one of the projects as a library and import it into the other.
See working with library projects
you can merge the code if it not having large scope..ie not having Native library and etc...
for merging the project you need to refactor package name, layout xml and etc...
for example. main.xml are seperate for both of package so need to care of such things

Categories

Resources