Howto properly integrate Android SDK (Adt) and Maven : - android

I've created an android project based on android-release archetype (via mvn CLI).
In order to import it to eclipse ADT (version 21) I tried:
mvn eclipse:eclipse
The problem with this approach was that the created eclipse project was a Java project and didn't have an 'android' nature.
so I tried:
importing the pom.xml using M2E eclipse plugin (Maven Integration for Eclipse)
now I have 2 different problems:
the gen folder is not the one used by maven, and I have to add it as a source folder.
getting ClassNotFoundException for the unit test classes when running via eclipse. Maven has no problems at all.
is this how it supposed to work ? am I doing here something wrong, or I simply have too high expectations?

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

Phonegap_java: duplicate class: org.apache.cordova.BuildConfig

I have downloaded Phonegap from CLI (working on windows7) and made a project from command line
phonegap create hello com.example.hello HelloWorld
and built it
phonegap build android
When i import project (project/platforms/android) in Intelijj and try to build it, it gives me this error
java: duplicate class: org.apache.cordova.BuildConfig
Any advice?
The steps that I did to import project in IntelliJ, after I built the application with "cordova build":
Import project
select "PROJECT_FOLDER/platforms"
Import project from external model "Eclipse"
In select Eclipse project, select all.
Import JDK and SDK (JDK 1.7 and SDK Android API 17 and 19 in my case)
Import Android Dependencies From Property Files (Add dependency helloworls --> helloworld-cordovaLib) OK.
At last this build and run without problem to me.
There are an issue with IntelliJ and Maven, maybe you can apply the same solution.
http://youtrack.jetbrains.com/issue/IDEA-94901
1.) Delete the "gen", "target" and "out" folders
2.) Revert the changes within the "ipr" and "iml" files
3.) Start IntelliJ 11.1.5 EAP / 12 EAP
4.) Open the pom file
5.) Right click -> "Maven" -> "Reimport"
6.) "Build" -> "Rebuild project"
A better workaround (tl;dr): Don't do the 'cordova build' step from the Cordova workflow (Getting Started Guide for Android)
We ran into this issue while doing Cordova training for our students. The recommended tool from developer.android.com switched from the Eclipse ADT Bundle to Android Studio, so we made the switch.
Unfortunately, you can't follow the same workflow. The Cordova 'Getting Started' guide for the Android platform spells out the commands to execute from the command line. But, they are for the Eclipse platform. One step needs to omitted for it to work with Android Studio.
One of the links above (http://www.tricedesigns.com/2013/05/16/phonegap-android-studio/) shows the correct workflow, but if you're used to the Cordova workflow, you may just assume it's the same and complete the steps in the same way. However! Omit the 'cordova build' step. Building the project (instead of letting Android Studio build it) causes Android Studio to get the error from the question.
The accepted answer above didn't work for us, because when we attempt to import the project, there is no 'Import project from external model "Eclipse"' option. This, however, worked just fine. Hope this saves you the hours we spent looking for answers/troubleshooting.

Android ActionBarSherlock on NetBeans - working but editor showing errors

I'm using NetBeans for android application. I installed properly (I think) ActionBarSherlock package as android library project. Everything works fine, I can build and run application, but code editor doesn't recognize ABS classes (just look at screenshot, BUILD SUCCESSFUL but errors exists) and code completion doesn't work too.
My configuration:
Stable NetBeans 7.2 with android plugin ver. 1.13
Linux Mint 13 Maya 64 bit, Mate
ActionBarSherlock ver 4.2 (stable)
How I installed ABS:
Download and extract source
From sdk/tools run command:
./android update project -p path_to_ActionBarSherlock/library/
Similar command to connect android project library with my test project (there is similar option in Netbeans IDE but I get error that this is not android library project)
./android update project -l path_to_ActionBarSherlock/library/ -p path_to_my_test_project
I have tried clean and build on both projects but no results. Any idea?
Regards
The way I finally managed to add ActionBarSherlock to my android project on Netbeans was to:
Download the latest version of ActionBarSherlock and unzip it
Go to the subfolder called library and remove the pom.xml file from there (with one of the previous versions it didn't work. I had to first build it, close it and remove not only pom.xml but also some netbeans properties files)
Open that subproject (library) in the Netbeans
Now this project will no longer be seen as a maven project. Netbeans will see it as an Android project. Then I:
Clean&build it
Add it to my-project's library properties (right-click on my-project, properties, library, add, point the proper location of library project). Important here was to copy/move that library project somewhere near my-project. Otherwise it claimed that it cannot open it.
And from now on it works fine.
Key to that thinking was that Netbeans didn't want to add the provided library project cause it saw it as a Maven project. When the pom is deleted, Netbeans no longer sees it as Maven project nut as an Android project and it can without any objections add it as an Android's project library.
Probably there are better solutions, but I didn't find any and that was the only one working for me.
Hope it helps.
You can also make a new Android project, and then copy and paste the needed files in the new project.
So only copy:
libs, res, src, AndroidManifest.xml

Import maven project into Eclipse/Android project

I downloaded the Megamatcher Android SDK from http://www.neurotechnology.com/megamatcher.html
I already implementend a face identifier on android devices
now i want compare the performance of my identifier with a corporate one (the one above)
My problem is to export the mvn project from Megamatcher tutorial into an android project under Eclipse.
there's a way to create an eclipse project from a maven one? including all remote and local dependencies??
Thanks
Maybe it's just this what you are looking for
From: source:
If you have a simple java project which is made up of only one module,
using eclipse is very simple. To generate the eclipse project files
from your POM you execute the following command:
mvn eclipse:eclipse
If you have created or checked out the project with eclipse, you only
have to refresh the project in your workspace. Otherwise you have to
import the project into your eclipse workspace (From the menu bar,
select File >Import >Existing Projects into Workspace). In the latter
case the project (directory) should not be located in your workspace,
because eclipse might come into trouble, especially if you want to use
eclipse as the scm client.

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.

Categories

Resources