Question

I'm attempting to integrate a third party monitoring solution (New Relic) into my Android app, which uses an ant-based build. The integration instructions say to set the ANT_OPTS environment variable to -javaagent:{path to a jar file} before executing the ant command to perform the build.

This works swimmingly when I launch my ant build manually from the command line.

However, we also launch ant builds via Jenkins. In the Jenkins build configuration there's a section for configuring your ant builds. In this section is an entry called "Java Options". From searching elsewhere I've gathered this is the place to put JVM arguments. Typically people want to increase the max heap size, etc.

So I put this in the Java Options section:

-javaagent:{path to a jar file}

The Jenkins builds, however, fail during the Android "-dex" target as follows:

  [dex] input: /Users/builduser/.jenkins/jobs/Android - Latest/workspace/android/bin/proguard/obfuscated.jar
  [dex] [newrelic.info] Detected the New Relic Android agent in an Ant build (/Users/builduser/.jenkins/jobs/Android - Latest/workspace/android/bin/proguard/obfuscated.jar)
  [dex] Converting compiled files and external libraries into /Users/builduser/.jenkins/jobs/Android - Latest/workspace/android/bin/classes.dex...
   [dx] Unrecognized option: -
   [dx] Could not create the Java virtual machine.

I suspect this is not a Google/Android issue because these builds succeed when I set ANT_OPTS and launch the build from a command line. Something about the way Jenkins handles JVM args is screwy and is confusing the Android build tools.

Anybody have a workaround?

Was it helpful?

Solution

It looks like this is only an issue when the job name contains a space (" "). And then only when "-javaagent:{jar}" is specified as a "Java Option" in the ant plugin section. I cloned my job and used a name without a space and the build succeeded. Still unsure if this is an issue with the Jenkins ant plugin or with Google's "dx" executable, but now I'm leaning toward the latter.

OTHER TIPS

This may be a conflict with Proguard, While this Proguard section is on the New Relic documentation site, it's not in the install instructions within the New Relic user interface :/

1) Add a New Relic exclusion to your app by adding this to your proguard.cfg file:

-keep class com.newrelic.** { *; }
-dontwarn com.newrelic.**
-keepattributes Exceptions, Signature, InnerClasses

2) Clean your project, and then run your app in an emulator or device to start seeing data.

Link to the doc in question. I'm working on revamping the docs and help-text for New Relic since a number of Proguard conflicts have cropped up recently.

If it keeps failing, get in touch with Support at support.newrelic.com and we can investigate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top