Copying sources from one maven project to another - android

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

Related

Import maven project from Eclipse to Android Studio

I have a very complex maven project in Eclipse with many modules and submodules and a lot of dependencies to each other and to third party files in pom.xml files. It works well in net browsers. But how can I try it in PC within an Android phone emulator? I have found this Android Studio program, but how can I import my very complex maven project from Eclipse without adding extra file(s) to it (like AndroidManifest.xml,etc) and not to destroy the original structure of the project?Anyway, I could use the File/Open option from menu and I can see the project in AS, but I can't run it. What should I do to run?
If you are trying to migrate an Android application from Eclipse IDE to Android Studio, then the hard truth is there is no easy way. I know because I already did this and it was worth the move.
And if you decide to take the hard route you will need to fully understand the directory structure of your Eclipse project compared to the directory structure of Android Studio projects and how the two IDEs build and deploy the project - because they are totally different and Android Studio uses gradle for its build.
Try reading through the Android Studio Guide and the Migrate to Android Studio from Eclipse.

How does one migrate libGDX projects to another system?

I have libGDX projects on one laptop. I need to move to another laptop. I am using eclipse on both windows laptops. I have a git repo I can push to and pull from. I know that I can clone the https://github.com/libgdx/libgdx-demo-cuboc and import it into eclipse as a gradle project. But when I try this with my libGDX projects the "Build Model" fails.
I suspect I did not export the project correctly from my source laptop.
Can someone please point out what I am doing wrong?
Update:
OK. When I exported the projects from Eclipse I exported as plain old Android projects (Export Android Application), so I figured that I should export the project as Generate Gradle build files but I get this error when I attempt to do so ...
... and yes I did this too ...
... and I still get the same error.
UPDATE: After accepting JH's answer. Thank you for your answer BTW.
I was able to copy files in the project, but with gradle one copies the files into the directory libGDX generated the base project. I was coping the files into my Eclipse workspace, which is why the files were not showing up in my Eclipse project ... I know confusing huh. Well I was able to get my project to build but whenever I launched the app if crashed at runtime (see java.lang.UnsatisfiedLinkError: Native method not found: com.badlogic.gdx.backends.android.AndroidGL20.glGenTexture:()) I decided to give up on Eclipse and migrate my project to Android Studio. After taking a quick look at the Android Studio I was FINALLY able to build my app and execute it without runtime errors on my new laptop!
For clarity here is what I did to migrate my project from one laptop to another.
1) I got the my code out my git repo.
2) I downloaded the latest gdx-setup.jar, 1.5.3, from the libgdx project.
3) I generated a project, being careful to use the correct values for: Name, Package, Game class and Android SDK. For Destination I used c:\Users\Me\.
4) I copied the directories android, core, html, desktop and ios directories from my git repo into the corresponding directories in the project that gdx-setup.jar created.
5) Then I started Android Studio and follow the directions found here: Migrating to Android Studio
6) updated my build.gradle to include google play service and BANG! it worked
You shouldn't have to export anything, just clone the git repository on the new computer and then import gradle project and build model.
You could even generate a new libgdx project with their project wizard and then copy the source files.

How to create a Maven project that can be imported as an Android project

I am a fan of Maven and love the freedom it gives me and my fellow programmers when collaborating on a project. I consider myself to have a fairly good understanding of Maven and its pom as well as the command line goals.
Now we are starting to create an android test project to test our Android software in an automatic way. We have no problems doing this from within the eclipse environment and the test suite is now up and running.
However, its time to include more programmers into this project and therefore we want to be able to clone this project from our git repository, run mvn eclipse:eclipse, import it into a fresh eclipse (of course with android-sdk and what not) and run the tests as is expected.
We stumble over the hurdle that the project doesn't become an Android Test Project within eclipse thus it is not possible to run Android JUnit on any of its classes.
The main question: How do we make the project become an Android Test Project from the terminal window after it has been cloned from Git?
You can manually add android nature to the project by adding it in the .project file and then opening eclipse again.
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
You can create an empty android test project, and then compare it's .project file with your project's.

Integrating maven project in Android project

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.

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