I tried to look though the documentation but nothing explained why some android java apps are compiled with 'ant' vs. the normal way to to compile an app in eclipse?
In basic words you can use ant to compile your Android project and get several apks as output, lets say for different companies. Like build machine. In ant you write all dependences and its easy to manage compilation process.
From my experience I used ant to bind Android NDK with SDK but Eclipse can do that pretty well.
So If you are not familiar with ant, use Eclipse for Android. It will be enough.
Some link to start from
Related
(I asked a similar question earlier, so I'll try a more general form and see if anybody knows how to do that.) There's a Java library to which I have added patches for Android support. I would like to automate testing of the code, but in order to check if it runs properly on Android, I need to test it on Android. The library artifact is a jar, though, not an AAR or an APK, so I don't want to remove the old build modes, and so far my attempts to add the Gradle Android Plugin yields errors like The 'java' plugin has been applied, but it is not compatible with the Android plugins.
How can I continue to produce a plain Java jar, but also automatically test it on Android? Do I need to, like, make a new submodule or something specifically for the tests?
Yes, usually it's a good practice to create a new module, say integration-tests, which in itself is an android library/app, and then you'd include your JAR/java lib in there and run android tests over it.
I have always used ADT to develop Android applications, but have moved to a new machine which does not have ADT installed. Google does not seem to support using ADT any more anyway, saying "you should migrate your app development projects to Android Studio as soon as possible". But Android Studio apparently uses Gradle which requires an Internet connection to compile, which won't work for me when I'm on the road, when I can download stuff to install if needed, but don't have an Internet connection when I'm actually working.
So as a work-around I am exploring the idea of not using an IDE at all and just manually compiling everything. (This also seems more future proof against the next time Google decides everyone needs to switch to a whole set of new tools.) I assume that to do this I need a few command line tools, for instance, something like "javac" to compile Java files into class files and next something to create dex file(s) and finally something to package everything together into an apk and sign it. However, when I search for instructions on manual builds I still find constant references to a build system such as Ant or Gradle. I don't want to use any build system!
From scratch, what is the minimum I need in terms of tools I need to download and figure out the command line invocation to turn a simple (let's say "Hello World" simple) java file (and a few support files like a layout XML file and manifest) into a working APK? (Note that I need to build an APK that will work on APIs as old as API level 10.)
Update: Ok, so far I have installed the standalone SDK tools, and have used the SDK Manager to install the SDKs that I need. But now I'm unsure of what commands I need to run: I'm familiar with javac and I see that, but I know there are other commands too. Again, I have seen several SO questions asking about how to build and it refers to things like the ant or android command, which are NOT in the stand-along SDK tools and which shouldn't be necessary if I just knew which commands to invoke manually.
I'm writing an Android application and there's some Java code in it that's somewhat sophisticated and therefore hard to verify the correctness of in the Android environment. I would like to run this code in a desktop environment where I have more tools with which to examine the output of this code while still using it in my Android application.
My attempted solution is to have three different projects in Eclipse. My Android project and two plain (non-Android) Java projects. One Java project has the sophisticated code that I want to use in Android and the other is a test program that verifies the correctness of the former project. The latter project has already been useful in debugging the former.
However, so far, my attempts to use the Java project in my Android project appears to work in the IDE but when I actually run the Android application, the NoClassDefFoundError exception is thrown whenever I try to access any of the classes. Obviously, that code is not being recompiled into the .dex file but why not?
I could go into detail about what I've done so far but I can't help but think that what I'm doing is a pretty standard and simple thing and there's a plain way of doing it, even though I can't find anyone doing quite what I'm trying. Can someone describe to me how this is done?
Luckily, I found the answer to my own question and I thought I'd share it here to help others in the same situation. It turned out to be very simple...
What I was already doing would have normally worked, which should have been a big clue to me since I have actually done this before, successfully. All you have to do is, under your Android project's Properties > Java Build Path > Projects, add the plain Java project to your "Required projects on the build path" and then under Properties > Java Build Path > Order and Export, check the checkbox of that same project in the "Build class path order and exported entries" list and everything should just work.
From within Eclipse, there's nothing else you need to do to get this setup to work. It's only when you're compiling from the command line that you need to build Java Jars and import them as libraries but I'm not doing that (yet).
Finally, this wasn't working for me because I just happened to be compiling my plain Java project under JDK 1.7 compliance, while my Android project was compiled under JDK 1.6. This is verified by the output on the Console pane, reporting "Dx bad class file magic (cafebabe) or version." This error message goes away when both projects are compiled under the same compliance level and, not coincidentally, the Android program runs properly.
Thank you to everyone who tried to help and I hope this answer is helpful to someone out there!
Would it not work if you made your other plain java project into an Android project and use it to monitor the output on the device?
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I code mostly in Java and use Maven for all of my projects. I do really love using Maven since it is easy to download the sources and documentations, and, more importantly, I don't need to keep the copy of the external libraries under my project source code folders.
I have started to develop an Android application and I found that the Android plugin for eclipse are terribly good. However, all provided examples are not maven projects so I do not know whether, if I use maven, I would still get all the functionalities from the Android plugin or whether there is any drawback from using Maven.
So the questions are:
Do all features from Android plugin for eclipse still work?
Is it going to be more difficult than using the normal build (I believe it is Ant but not certain)
Any other drawbacks, e.g. the file size of the final application (Maven tends to bundle a lot of things together) or the difficulties of getting the latest libraries on maven repository (which is probably differnt for Android).
Please do not point to this maven support for android projects?
I would like an answer from experience developers. I already know that it is possible to use maven for an Android app. All I need to know is whether I should use it.
My teams current task is to develop an Android app. Since it is a small app and also some kind of prototype we decided to evaluate Maven and the Android Eclipse plugin.
In short:
After two developers spent three days, we were not able to gain the Android Eclipse plugin functionalities in our Maven project.
The R class was not updated according to our resources
We were not able to start the application directly from within Eclipse in the emulator and/or an attached device
Because of these issues which impeded our development sincerely we decided to develop the app without Maven.
But if any of you knows how to fix these issues I would love to hear a solution!
If you want fast running tests you are nearly forced to use maven. As robolectric is the way to go then. And they said Roboletric is probably easier to set up via maven under Eclipse (they are using IDEA).
That said, did you read this post or that? And what error message exactly did you get?
Typical things I made wrong:
use maven >= 3.0.3 ! And avoid that embedded thing in eclipse. (This was necessary only for robolectric, if I remember correctly)
use ~/.m2/settings.xml as described on the robolectric page to set up the android path
specify your android sdk also properly in the local.properties and under Preferences -> Android -> SDK location
Further read this and that or just try the mavenized robolectric example itself, which worked for me. Import it as existing maven project.
Install the necessary sdk (in my case 2.2_r3) via maven-android-sdk-deployer and
export ANDROID_HOME=/path/to/android/sdk
mvn install -P 2.2
And did I mention this strange tool: m2e-android - not sure why one needs so many stuff with Eclipse ... here you can install it via software updates http://rgladwell.github.com/m2e-android/updates/master/m2e-android/
Hopefully I remembered all steps correctly. Good luck!
Update:
Switching back to normal Android stuff without maven under Eclipse as the IDE makes strange stuff: http://groups.google.com/group/robolectric/browse_thread/thread/ac814076c40d9df1
But the nice thing of this Maven adventure is that I can now easily test and debug my projects via NetBeans :)
As we all know Android Devolopment migrated to Android Studio from Eclipse.
The Android Studio build system consists of an Android plugin for Gradle. Gradle is an advanced build toolkit that manages dependencies and allows you to define custom build logic.
The build system is independent from Android Studio, so you can invoke it from Android Studio or from the command line.
The Android Studio build system supports remote Maven dependencies. As you know, Maven is a popular software project management tool that helps organize project dependencies using repositories.
You can build your Android apps from the command line on your machine from Android Studio,thus by avoiding the mess of plugins as there in Eclipse.
Check out this tutorial for Building Android Apps with Maven.
Refer here for more about Gradle build
I recommend avoiding Maven for professional development on Android. Here's why:
Google is investing time into keeping Android Studio integrated with Gradle. So maven is extra work right off the bat.
If you have to use Maven (e.g. to manage dependent libraries), then Gradle can use the Maven plugin. See https://docs.gradle.org/current/userguide/maven_plugin.html
By making maven your primary build tool you'll be downloading a massive amount of dependencies that you don't need and you're not sure where they come from. This goes against the notion that for your Android app, you ideally want just your code, and the android platform. In other words you're involving a lot of libraries/code you don't need.
In short, using maven as your Android build tool adds much more work than is necessary and creates a management nightmare (IMO).
Try this to illustrate:
Heat a pan on a stove.
Hold up a raw egg. Say "This is your android application."
Crack the egg into the pan.
Say "This is your android application on maven-with-rats-nest-dependency-tree-and-unknown-code-downloads-that-you-don't-need-anyway."
Wait for the egg to burn to a crisp.
Say, "This is your android application when the maven build packaged a useless or bad library with your Android application."
I have been able to use maven for android application development using Android Development Tools for Eclipse (Kepler) and Android for Maven Eclipse 1.0.1 (m2e-android). Follow these instructions http://rgladwell.github.io/m2e-android/. After you have created your new project with the android quickstart archetype modify your pom.xml. Add the android platform version. Eclipse (m2e) will report an error on the pom.xml on the android-maven-plugin declaration, to fix this issue follow alexander's response in Error in maven pom xml file: Building Android project. Then update the maven project using eclipse and that should be it.
From my own experience in Intellij. I used Maven as a build automation tool for my android development process. I started learn it with "Android Application Development with Maven" from Packtpub.
I am creating a library for Android that others can include in their own project. So far I have been working on it as a normal Java project with JDK 1.6 setup as system library. This works just fine in Eclipse when I add the android.jar.
The issue comes when I try to my build script. I am running Gradle and doing a normal compile and test build cycle. My thoughts were that it does not matter if I compile it with a normal JDK, since this is not a standalone application. The benefits by creating a normal Java project is that Gradle does support this much better. My project also does not contain any UI at all. However, the problem is that of course android.jar and the JDK contains lots of the same classes and I think that this is what messes up my build script. Everything crashes when running the tests (the tests are in the same project under src/test/java).
My question is, how should I create this project that is meant to be included in Android projects as a third party library? Should I create it as an Android project in Eclipse even though I am only creating a library that does not use any of the UI features? Also, should the tests be in a separate project?
Thanks for all responses!
Have you looked at the Android plugin for Gradle? It incorporates the ProGuard tool to package only necessary classes into your Android APK file, so might address your scenario. Have a look here: https://github.com/jvoegele/gradle-android-plugin/wiki
I will start with the simple question, the one regarding the test project. My experience is that is is better to have a separate test project. I have done this with success in many Java ME project, where the problems are similar. The test project only need to import the source code, not the libraries. Then there should be no problems with duplicate classes.
The other question is a little more difficult. My intuition tells me that the core project should be an Android project.