Maven build Android application - BuildConfig - android

While trying to use Maven for building Android projects I recognized that the maven-android-plugin doesn't autogenerate the BuildConfig class during build time. I have found a ticket regarding that problem and a Google Groups thread.
Issue: http://code.google.com/p/maven-android-plugin/issues/detail?id=275
Google Groups: http://groups.google.com/group/maven-android-developers/browse_thread/thread/cc74267bbb7baebb/4e63b710513bb535?lnk=gst&q=BuildConfig#4e63b710513bb535
The quick hack in the issues thread suggests creating another micro maven project to set the BuildConfig.DEBUG variable during build time with a profile switch. This would force me to build a multi module project for every single little application.
The suggestion in the Google Groups thread sounds ok for me (executing the Ant Task from the SDK to generate the BuildConfig class) but after digging through the build.xml and trying to get this work I gave up.
Has someone got a practical working solution for the BuildConfig problem with maven+android?

Thanks to Jake Wharton and Manfred Moser, BuildConfig generation has been supported since Android Maven Plugin 3.3.2.
Check out changelog for 3.3.2 release here.

Related

Get Android NDK crash reports with Unity 2019.3+

Since Unity 2019.3 the Android build process has changed and now the gradle project contains two modules - a unityLibrary module and launcher module.
I am having trouble uploading native symbols as I cannot apply the plugin to the unityLibrary module, and only works in the launcher. Is there a certain way I can achieve this?
When I run uploadCrashlyticsSymbolFileRelease task that is only present on the launcher module, I receive this error:
Could not find the file generated by Google Services. Please check your Firebase project configuration
The configuration file is in the unityLibrary module.
Is there any way to move the task to the unityLibrary module? If I move the crashlytics plugin to the unityLibray module the error changes into:
Crashlytics was applied to a project without an Android plugin. Please make sure the Crashlytics plugin is applied after the appropriate Android plugin for your project.
The tricky bit is that Firebase is still compatible with versions of Unity that do not support gradle integration. Because of this, the build pipeline in Unity re-implements the functionality of the google services plugin (namely generating the values.xml file).
I've personally put some effort into massaging the mainTemplate.gradle file to work with gradle plugin, but haven't gotten the NDK upload to work yet. Some notes that may help:
The External Dependency Manager for Unity (EDM4U) will both update the mainTemplate.gradle file if available but will also process google-services.json and drop the output into Assets/Plugins/Android. You'll likely want to run it once to generate the dependencies, delete the values.xml, and then disable EDM4U to prevent it from regenerating that file.
The Unity SDK is based on C++, and the aar archives that bind C#, C++, and Java are packaged into local maven repository in your Assets directory. This will make it hard to relocate your project after generating it (ie: try to do all your work Unity side if possible).
Because you'd be short-circuiting Firebase's processing of values.xml to use the plugin, you'll need to make sure google-services.json actually makes it into your Android sourcetree. Assets/StreamingAssets might do this automatically but you may have to write a build script to copy it over.
Finally, the team is aware of the desire to debug NDK code in the Unity Crashlytics plugin. There aren't any public timelines available, but in lieu of a good answer opening an issue on the quickstart or posting to the mailing list might could be a good way to try to work through the process.

Can I use Android data-binding with Maven?

There's a beta release of a data-binding library by Google. According to the docs
To use data binding, Android Plugin for Gradle 1.3.0-beta1 or higher is required.
In my project I need to use Maven instead. I'm trying to set up a minimal initial project. The problem is that the new data-binding library somehow mangles processing of the XML layout file that generates the R class and probably requires a gradle plugin: android/databinding/tool/DataBinderPlugin
There is no information on how to handle this without Gradle. Does anyone know what needs to be done to make this run with Maven as well?
There hasn't been a lot of effort put into this since most developers use gradle. That said, I did a quick bit of development to try to enable make builds that you could try out. There is a class android.databinding.tool.MakeCopy that you can try to run. It is a command line interface that copies resources from one or more directories to a target directory, modifies the layout files, and generates some artifacts that are required by the annotation processor (xml files, source files).
It should be included in the library with the annotation processor. You'll have to work out the full class path requirements to get it to work. As I said, I didn't spend a lot of time getting it going because we didn't have any clients for it.

Setting Up An Android/Maven Library Project in Intellij

As you can see from my passed 3 questions I am having major problems with my project setup. I am getting lots of very specific errors that seems like nobody can answer them. I am getting hugely frustrated. So I am going to try a fresh approach. I will describe how I would like my project set up and if somebody could give me some brief steps to follow I would be very grateful. After messing around with this for around a week I believe I have some knowledge but maven seems to be incredibly difficult to understand.
I am writing a library which will be used in 2 projects. The major libraries I would like to use are roboguice, robolectric and jackson(json library). I would like to have a way to test the library but I am unsure if this should be in a different module or not. Robolectric seems to suggest it should be in the same module. I am unsure how I should use this library in the other 2 projects. I have been looking at this http://code.google.com/p/maven-android-plugin/wiki/ApkLib but unfortunately the website tells me next to nothing about how I should create the apklib.
If it is possible I would also like the other 2 projects to have a dependency on that library and build it automatically.
I have been using this site to create the maven project http://stand.spree.de/wiki_details_maven_archetypes
But I have been running into issue after issue. If anybody can point me in the right direction I will be very appreicative
Even if maven is (almost) a foreign country to me, I had some moderate success setting up a maven project and interacting with it using intellij. I wanted to use it because it looked the easiest way to have robolectric working with intellij.
I wrote a blogpost you can find here
What you need is:
Maven android sdk deployer https://github.com/mosabua/maven-android-sdk-deployer
Maven android plugin http://code.google.com/p/maven-android-plugin/wiki/GettingStarted (using android archetypes is just fine)
If you want to build an apk lib instead of an apk, just specify apklib in the packaging tag
PS: I also saw this a while ago, but never gave it a try.

How to get code coverage in Android using Maven (android-maven-plugin)

I have an Android Maven project (let's call it parent_project) that contains various submodules: my_library_project, app_using_my_library_project, test_project and extra_lib.
So, the structure would be like this:
parent_project
* my_library_project (Android Library Project)
* app_using_my_library_project (Demo app that uses the Android Library Project)
* test_project (Project containing the tests instrumented against app_using_my_library_project)
* extra_lib
What I would like is to generate test coverage for my Android project using Maven (and not Ant, I am already able to generate code coverage reports using Ant, following these instructions: https://wiki.jenkins-ci.org/display/JENKINS/Building+an+Android+app+and+test+project).
I have no strong preference for the code coverage tool used but I would prefer EMMA, since seems the most common in the Android development world.
I am using android-maven-plugin (http://code.google.com/p/maven-android-plugin/) in its 3.0.0-alpha-12 version and I have already tried to put in the configuration of my parent's pom.xml the next:
<test>
<coverage>true</coverage>
<createreport>true</createreport>
</test>
But that does not produce the desired code coverage report.
So:
Is there any difference between the pom configuration for getting code coverage for a standard Java project and an Android project?
Do you know any example Android project using Maven that has code coverage?
Any hints on how to do this?
If you're going to stick with maven, and want a plugin for maven that will do the code-coverage job, I think Cobertura is a better choice, as Emma stable last build is from 2005.
Although in "Android Application Testing Guide" (a recent book from June this year) they talk about Emma and demonstrate how to use it for testing, I think people stick to it, because it's needed to build Android from source (and if Google use it for their own OS development, it should be the best, right?).
If you're not fanatically bound to Maven, I strongly recommend to try Robotium.
Robotium has full support for Activities, Dialogs, Toasts, Menus, and Context Menus.
It also supports code coverage (Ant based though, for now) and some people recognize it as one of the leading testing platforms for Android.
Edit:
According to the Cobertura site, it supports code coverage in Maven 1 and Maven 2 environments. Although, you can find examples with Maven 3 also.
A problem exists between pom configurations of Maven 2 and Maven 3. It seems for the reporting to work you have to basically move your old reporting plugins into the configuration section of the new maven-site-plugin. (See the article for details).
Another option is to try and use Sonar with Maven. Sonar has cobertura embedded (also options to embedd EMMA) and some people state that they had successfully reported code coverage, despite they had problems using the "stand-alone" cobertura plugin.
I could generate code coverage reported using emma maven plugin and display reports in sonar for an android application project. Just follow the configuration in https://code.google.com/p/maven-android-plugin/wiki/EmmaMaven.
But for library project I get a 0% coverage. It doesn't generate the metadata files. However as soon I change the library project to package as an apk, it works like a charm. It runs the tests in a emulator(configured in jenkins) and shows the coverage reports.
If you are looking out specifically for library project, this wont help. I will post if I find some solution which deals with library projects.

Duplicate file when deploying apk

This problem seems to come up for a few people, but I haven't been able to apply the solution suggested in other threads for one reason or another so...
I am trying to build a simple android app with an embedded webserver. The server of choice if jetty. I am using maven to manage dependencies with the maven-android-plugin. I have added jetty-server v8.x as a dependency with the default scope. When I try and deploy my apk to the sandbox I get an error
Found duplicate file for APK: about.html
So the file in question is from the jetty package, or rather it is found in two jetty packages, one being a dependency of jetty-server. Other threads out there seem to be suggest I delete the file from one jar or the other but this is not really a scalable solution as I am not the owner of the jars.
Is there a more general solution to this problem? Something that manages the conflict and build or deploy time?
I should note, I am a bit of a Java noob, and have gone the NetBeans and maven route because this is the toolkit I'm familiar with.
OK, found it. The solution is to build using the following command
mvn android:deploy -Dandroid.extractDuplicates=true
There are a couple of issues:
First, to integrate Jetty, your project is going to need a pom.xml file. The Android APK (as-is) does not know how to resolve a pom with Maven dependencies without some sort of bridge. So, you'll need to install a few plugins for Pom management onto Eclipse. Follow the instructions here: http://rgladwell.github.com/m2e-android/
(I found it easier to create a new project using the method described here rather than converting my existing Android app to a Maven project, but I'm sure it'll work either way.)
Second, once you've installed this, you're going to have to make sure your pom.xml contains the necessary dependencies, build goals, and variables. So, open up your pom.xml, and make sure you have the following:
In the "build" node:
sourceDirectory -> src
defaultGoal -> install (I suppose...)
In the "dependencies" node:
... all the jetty/cometd dependencies (org.cometd.java, org.eclipse.jetty, etc.)
Third, you should know that you can't just click the green run button and launch the app via ADB. You have to install it the maven way (Run As -> Maven build/install/test/whatever)
You should open up your war file and check if you actually have two about.html files in there. Some time ago I had two web.xmls in my war files. If you actually have duplicates then you should try to exclude those files.
Maybe you have one file in your project and the duplicate is generated by the maven plugin.
I also just realized that you're probably already properly using the android-maven plugin. One other important tip: change the scope to runtime on the jetty dependencies. This builds successfully for me, whereas using the default scope (compile) always threw the duplicate file in APK error.

Categories

Resources