title: run non-ui android code on mac
body: <p>G'day</p>
  
  <p>How do I run the non-UI parts of a Java Android app on a Mac under program control i.e. headless ? </p>
  
  <p>(A short digression on why I want to do this: I am developing a performance testing tool. It is specifically for testing the performance of servers addressed by Java API clients. My tool uploads an API client, wraps it, and can immediately start creating performance testing use cases by examining the methods of the client. At runtime it calls the servers by executing the API client directly. No recording and playback involved. No worrying about protocols.</p>
  
  <p>Now it recently occurred to me that a well-structured mobile app that communicates with servers would likely have a module that does all the communication in response to method calls. In other words an API client. Since this module is unlikely to have any Android UI elements in it it should, with probably a suitable harness, be runnable on a Unix box or Mac and therefore within my tool. This would extend the range of my tool to Android Java apps.)</p>
  
  <p>My proof of concept vehicle is the simple Android Java app called Network Connect found in the Android Studio sample applications under connectivity. The app just connects to a specified URL and gets and displays the first 500 raw HTML bytes.</p>
  
  <p>That this app can be run on the Mac isn’t really in doubt as it can be run on the Mac under e.g. the emulator built into Android Studio. (The emulator is extremely slow but the slowness is almost certainly related to UI handling and unlikely to be an issue for me.) </p>
  
  <p>So the first thing I tried was setting up a NetBeans project based on the source of the sample app. Naturally the project wanted some library JAR files. I found that three JARs copied from the Android SDK that came with Android Studio sufficed to get the project to compile. Now you know what happened when I ran the app: Stub !</p>
  
  <p>So then I had a look at the Java sources that came with the SDK in Android Studio. The class that Stubbed ! clearly wasn’t stubbed in the source code. So I though I would build the SDK from the source. Bad idea. With 11,000+ classes NetBeans, even on a 4-processor Mac with lots of memory, was unworkably slow.</p>
  
  <p>So then I approached from the other end. I set up another NetBeans project and brought across just the classes in the three JARs that I had found sufficient to run my POC app. But to compile them I of course had to bring across a lot more classes from a lot more JARs. In due course this became unworkable too.</p>
  
  <p>So then I discovered RoboElectric. It promised a de-fanged set of Android SDK JAR files. I downloaded that expecting to find the de-fanged JARs. But it had to be built and the instructions for that were way short of what I needed. I tried collecting all the source files into a NetBeans project but that soon went nowhere.</p>
  
  <p>Then I discovered Deckard. This claims to be the simplest Java Android application project that uses RoboElectric.  As a byproduct it builds RoboElectric. Perfect !. Well I guess its a while since anyone built Deckard. But I got it to build. And I got a single JAR that contained virtually all of the Android SDK code. I took that to my NetBeans Network Connect project as the JAR library. And the project compiled nicely. But when I ran it it Stubbed ! again. So I started replacing the classes that Stubbed ! using the source files from the SDK source. But this too became unworkable.</p>
  
  <p>So what I think I am looking for is a set of un-stubbed Android SDK JARs. I understand that the things that are stubbed in the SDK are intended to be implemented for each Android Java project. So there should be plenty of implementations out there. It probably won’t matter to me how they have been implemented and, if it does, I can probably change the implementation. </p>
  
  <p>Anyone got any ideas ? (I don't think I need any help on the headless bit. If I can get the POC app to run I think I can take it from there.)</p>