Integrating maven project in Android project - android

I am building an Android application, and I want to use certain functionalities that are supplied in a Maven project.
What is the easiest way to use this maven project in my Android project? I have never worked with Maven so I prefer to deal with it as little as possible.
I tried exporting the maven project into a jar using eclipse and then using it to my android's project build path, but when I run it I get java.lang.NoClassDefFoundError: info.bliki.api.User.
So what would be the easiest way to use this Maven project in my Android project?

Well, i guess you're just interested in the resulting artifact, then you should be able to just run in the command line (you need to have a version of Maven running though)
mvn install
which compiles and build the project. You'll get a local copy directly written into ~/.m2/ ... this is where all maven artifacts are installed to . You could then just grab the resulting jar (if it is one) or link directly to the resulting artifact.

Related

Android application project in Eclipse and use gradle or maven to download JARS

I'm using Eclipse IDE Mars and the ADT android plugin and the sdk 23, and I always encounter problems when I try to install a .JAR all the sites where I download a JAR have a sample about how to install the JAR using Maven or Gradle, I tried to install Android for Maven Eclipse 1.4.0 (m2e) plugin but had the following error The following solutions are not available: Android for Maven Eclipse 1.4.0 (id=com.android.ide.eclipse.adt.feature.group, site=http://rgladwell.github.io/m2e-android/updates/).
So I tried to install gradle plugin instead to do so I followed this question:
Is there any way to integrate Eclipse with Gradle in Android project? and I installed the Gradle IDE plugin but I don't know where to go from here since all the documentation I can find it is for too advanced users I can't find a simple tutorial in how to create an android application and use gradle to download the JARS all the info that appears is a gradle.build where you put the name of the jars similar to maven dependencies.
My questions are
1) How can I solved this problem ``The following solutions are not available: Android for Maven Eclipse 1.4.0 (id=com.android.ide.eclipse.adt.feature.group, site=http://rgladwell.github.io/m2e-android/updates/)when I try to install the maven plugin, Since I already have used Maven before and I have a lillte more experience with it than with gradle.
2) How can I use the Gradle IDE eclipse plugin to just download the JARS in my android application default project or some example about How to transform a default Android project application created by Eclipse IDE and add gradle to this project so I can download JARS. ( I don't have the Gradle_home variable in my system variables I don't know if this is necesary since if I only download the plugin).
My goal is just to use anyone of this tools to download JARS

Building Android project in Jenkins "requires Maven version 3.1.1"

I'm building an Android project in Jenkins. Everything was fine until upgrading to the lastest plugin version, but now it fails with "requires Maven version 3.1.1". Fair enough, but Jenkins seems to be stuck on Maven 3.0.4, even though I'm using the latest version (currently 1.553) of Jenkins and all its plugins. How to I make it update to a more current release of Maven?
Building in Jenkins via android-maven-plugin, which as of version 3.8.0 requires Maven 3.1.1 or higher (see http://code.google.com/p/maven-android-plugin/wiki/Changelog). Of course it can be done manually, outside Jenkins. The question is how to get Jenkins to use a current Maven; it seems to come packaged with an older one, and I'm not familiar enough with it to see where/how to update.
Update: For anyone following my footsteps, note that upgrading Maven will break the Android build until android-maven-plugin is also updated; they go together.
Jenkins does not come with Maven, but it can install it for you.
To Update Maven version used by Jenkins
Goto Manage Jenkins -> Configure System.
Scroll down till you see Maven section (not Maven Configuration or Maven Project, those are different).
Click Add Maven button.
Leave Name as default.
Checkmark Install Automatically.
Install from Apache is the default installer option.
Select the version you want installed.
Besides "Install from Apache", you can also install it from a zip or by executing a command line. Just delete the apache installer and click Add Installer button to select another option.
I would suggest to run a dummy Maven project at least once to verify this gets installed.
Jenkins doesn't come with maven as far as I am aware of. You can specify a maven installation in the Jenkins settings. I usually use a reference to a symlink (debian) and let that symlink point to my "current" or preferred Maven version.
You can alternatively install a recent maven version via Jenkins in the Jenkins settings aswell. And on my Jenkins there is a 3.1.1 via apache available.

Is it possible to set up an IntelliJ Android project to work with Maven?

I want to work with Maven dependencies in an IntelliJ Android project. Has anybody successfully done this?
I use IntelliJ IDEA (currently v11.0.2, build 111.277) on both Ubuntu 11.10 and Mac OS X 10.7.3 for working on Maven-based Android projects, and for the most part it works well. A nice thing about using IntelliJ with Android and Maven is that all support is already built-in - there are no extra IDE plugins to install.
As an example of a good working Android Maven project that can be opened with IntelliJ, you could use the source code of the open-source Gaug.es for Android app by GitHub (not all developers at GitHub use IntelliJ, personally I do - Eclipse is also used to work on this project).
The first step for smooth running is obviously to ensure that your project builds correctly using only plain Maven at the command line - although the question doesn't directly ask about this, I'd advise these pre-requisites as a bare minimum:
Java 6
Maven v3.0.3
android-maven-plugin v3.1.1
Android SDK r16 (if you downloaded your SDK before r15, you're probably better off nuking the entire thing and downloading it all again, as the directory layout has changed)
If you can mvn install the parent pom of your project, you're good to move on to actually working with it with IntelliJ.
If this is the first time opening the project with IntelliJ, you can still open it as a project, you just need to select the parent pom.xml file in the 'Open Project' dialog.
Ensure IntelliJ knows where the Java SDK is. IntelliJ, even though it's running on Java, doesn't auto-detect the location of the SDKs. You have to tell it. Go Project Structure, Platform Settings, SDKs and then edit the Java SDK if it's showing as red, giving it the path of your Java 6 SDK.
In the same Project Structure dialog window, set the Project SDK to the appropriate Android version, and under Project set the Project compiler output to whatever directory name you like - this value is required for doing a 'Make', but also overridden to by your submodules to sensiibly point to the Maven 'target' directories.
Double-check that all the Maven information has been parsed by IntelliJ. You should have a Maven Projects tab. Hit the Reimport All Maven Projects button (looks like two arrows chasing each other). If IntelliJ prompts you to enable Auto-Import, go for it. You should now have at least one module listed under the Maven Projects tab, more if you have an integration test project as well.
At this point, you should have a fairly meaningful IDE experience. Stuff that should work:
There should be no code underlined in red for no readily apparent reason.
All imports (whether from the Android SDK, Java, your own code or from apklibs) should be recognised. Note that apklib support only came in with late IntelliJ IDEA v10.5.
Refactor operations.
Force regenerate R.java file should correctly refresh the file under target/generated-sources/r/... - but this only seems to work if target/generated-sources/r is already set as a source path, ie has been generated by Maven, and imported by IntelliJ. The minimal command line alternative is to execute mvn android:generate-sources from the command line in the folder of the affected module.
Doing a 'Make' of the project within the IDE technically works, but again might fail for the same reason. I invoke all my builds using the mvn package or install at the command line.
Stuff that might not work:
Running individual integration tests from the IDE (dies with ClassNotFoundException: junit.textui.ResultPrinter)
If IntelliJ gets confused, the following steps will normally get you back on track:
mvn clean install on the command line
Hit the Reimport All Maven Projects button
Some advice:
Your Maven pom.xml files should be the source of truth for your project configuration. Minimise IntelliJ-specific configuration you do in the project settings- some of it will be liable to get wiped the next time settings are re-imported from the Maven POM - and try to avoid committing IntelliJ project files into source-control.
Hope that helps!
See Getting Started with the maven-android-plugin.
Here the command you can use to create an sampe working template with Maven structure:
mvn archetype:generate \
-DarchetypeArtifactId=android-with-test \
-DarchetypeGroupId=de.akquinet.android.archetypes \
-DarchetypeVersion=1.1.0 \
-DgroupId=com.foo.bar \
-DartifactId=my-android-project \
-Dpackage=com.foo.bar.android
BTW, IntelliJ has built in support for maven, so just open pom.xml from it - and everything will be ok.

Copying sources from one maven project to another

Am trying to copy sources from a maven multi-module web project to a maven-android project. This needs to be done as the sources (which I want to keep outside of the android project for another platform) need to be compiled under Dalvik in order to be run on android. Aside from that, dependencies are not packaged when running on android, but the need for compiling using Dalvik overshadows this limitation.
The closest documentation of the issue I found here.
Am using mvn dependency:unpack to unpack the sources to the android project in eclipse. Prior to this I need to run mvn install to install the sources to the local repository. Then I have to refresh the eclipse android project.
The ideally scenario would be for this to work directly with m2eclipse without the three step manual process.
Would appreciate any inputs.
Thanks
sfk
I would suggest lifting the common sources out of the web-project into their own project.
The new project should be configured to produce two artifacts:
normal jar file : for inclusion in the multi-module web app
apkLib : for inclusion in your android projects
This could be done by defining a secondary attached artifact with in the maven naming co-ordinates (groupId:artifactId:packaging:classifier:version).
see http://code.google.com/p/maven-android-plugin/wiki/ApkLib

android maven plugin in netbeans

I am trying to use android in netbeans with maven as the build tool. I want to be able to run the applications in netbeans and also run the emulator in netbeans itself. So far i have been using the command line for creating android applications with maven. Any help will be appreciated
thanks in advance
Abhirami
Technically it is possible with stock distribution of NetBeans IDE. Everything Android related will be handled by Maven there (including compilation against correct platform and special goals to deploy).
You will miss some goodies provided NBAndroid for regular Android projects. Some of them are available as you can read at http://www.nbandroid.org/2012/06/did-you-ask-for-maven.html.
are you looking to integrate maven with eclipse?
It's pretty simple. You Just have to follow the instructions here.
for NetBeans -
"NetBeans includes full Maven support since 6.7, including Maven 3 support in 7.0+. You can open any Maven project in the IDE and start coding immediately." as quoted here

Categories

Resources