I have an android application consisting of a library project that contains the source code. I then have two additional projects, that are used to manage a pro, and lite version of the app.
I have been unable to get robotium to load the class files from either of my proxy apps(pro and lite, which reference the library via a module reference), or the library itself. I have tried a bunch of different class names, and references, but the test project fails below.
public MainTest() {
super("com.joe.app.lib", Main.class);
}
I haven't found any discussion here about testing with library projects in android. Looking for advice.
Error msg
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.joe.app.tests/com.job.app.tests.MainTest}: java.lang.ClassNotFoundException: com.joe.tests.MainTest in loader dalvik.system.PathClassLoader[/data/app/com.joe.app.tests-1.apk]
While not specific to Robotium, this post may help you using external libraries in your test project.
In case you haven't found a solution yet or others are getting to this question due to similar errors after the last the adt update.
In Project Properties of your Test Project go to item Java Build Path and select tab Order and Export. There you'll have to check the project you're testing against so it's properly exported.
For latest ADT you also have to have the Android Private Libraries exported in your projects.
Related
We have an Android library project that we use in a couple Android app projects. When developing the Android app in Android Studio, if I hover over classes or methods defined in the library, the documentation popup has the package and signature, but no JavaDoc content.
The library is not in the same project as the application. It is built separately and uploaded to a private artifact repository (I think it's Nexus) and then referenced as a gradle dependency.
How do I get Android Studio to show the library's JavaDoc comments when viewing the class or method from the app project?
The AARLinkSources plugin may be able to solve this for you. I haven't used it myself, but it is recommended by a Stackoverflow user as an answer to a similar question.
I am using:
org.apache.commons.lang.builder.EqualsBuilder
in a in an Android library project (A) that in turn is used in another library project (B).
This works fine in the Android app that consumes library project B.
However, I have built an Android Test project to unit test the Android app - in particular the library project B classes. When doing so I encounter the following exception:
java.lang.NoClassDefFoundError: org.apache.commons.lang.builder.EqualsBuilder
I have included
commons-lang-2.6.jar
which contains the
org.apache.commons.lang.builder.EqualsBuilder
namespace in library project A build path for export.
I have searched SO for this issue and found a number of posts on the NoClassDefFoundError, but none that have a situation with unit testing.
I found the answer. After reviewing this article, I realized that I needed both the jar from project A and the commons-lang-2.6.jar in the test project. Adding BOTH jars to the build path and export resolved the issue.
I've been playing with a Java's Magento connector called magja (https://github.com/magja/magja) in a 'normal' Java project. And everything were working fine till this point.
After that, I started a simple Android application that would use the magja code to consume such information from Magento.
The question is: how should I configure the my Android project to deal with a 'normal' Java project (not a library)? This another project uses several xml files to configuration and Maven to deal with dependencies. How this impacts my Android App?
Thanks a lot!
EDITED
Actualy, I've already tried this approach (Android project unable to reference other project in eclipse), but always when the app tries to run the 'project B' (magja) code, it causes a
java.lang.NoClassDefFoundError: org.apache.commons.httpclient.params.HttpConnectionManagerParams
I believe it's related to some .jar files that magja uses. It looks like that I would solve the problem if I could share such library between the projects.
According to this SDK guide, unit-testing a Library project can be achieved by creating a standard application project, reference the Library project and then instrument the application for unit testing.
However, when I do this and launch the test application I get the message
No tests found with test runner 'JUnit 3'.
I'm using Eclipse and the Android ADT plugin, all latest versions.
Note: the projects compile just fine. The test project also installs fine to the emulator. But in the console I can see that it looks for <library>.apk, which of course doesn't exist since I'm compiling this as a library into the test project.
Anyone got this to work? And if so, what is the trickery here?
Update: after discovering and fixing a problem, which was actually including the test classes (!), the test runner now can find all tests. But, all the tests fail with the following exceptions:
java.lang.NoClassDefFoundError: <nameOfClassInLibraryProject>
nameOfClassInLibraryProject are classes defined in the library project. These classes should be compiled into the test project, and indeed, everything compiles just fine. But when running the test project, the runtime doesn't seem to find the library classes.
After much fiddling and wasted time in Eclipse I have managed to get Android Library projects to work.
According to the Working with Library Projects article:
Instead, you must compile the library indirectly, by referencing the library from a dependent application's build path, then building that application.
The problem was that I interpreted this to mean that the library project should be added to the Projects tab in Java Build Path. Doing this makes the test project compile since the library code is obviously available to the compiler. But since the library is not compiled into a .jar or .apk in itself, the library classes are never deployed to the device.
The solution is to not add the library project to Projects, rather on the Source tab, add the library /src folder using the Link Source... button. And yes, it is the library src folder, not the library project root, that must be linked into the test project.
I just started to play with android dev and java+eclipse is pretty new to me. I managed to create simple project and run it on my device. Now I want to create simple game (more of them actually) and I would love to use shared code base for all of them (game loop, initialization, etc..).
Problem is that I have no idea how to correctly do this. I created android project called engine with all basic stuff that I need and made it work on device. Now I tried to create another project in same workspace called mygame. Main class (activity) of mygame is MyGameApp which inherits from EngineApp (main activity of my engine project) which inherits from Activity.
I added engine project into required projects in mygame build path tab in properties. Problem is that when I try to run this project it crashes on ClassNotFoundException trying to find my MyGameApp class.
Any help (or pointer to some articles that explain how this is done) is greatly appreciated. few hours of googling didn't help much :/
You need to set up an Android Library Project
An Android library project is a development project that holds shared Android source code and resources. Other Android application projects can reference the library project and, at build time, include its compiled sources in their .apk files. Multiple application projects can reference the same library project and any single application project can reference multiple library projects.
The docs go on to say how to convert an existing project to a library project:
You can also convert an existing application project into a library. To do so, simply open the Properties for the project and select the "is Library" checkbox. Other application projects can now reference the existing project as a library project.