Retrieving android.jar from a local repository

3 views
Skip to first unread message

Eric Hall

unread,
Jun 2, 2008, 1:05:28 PM6/2/08
to masa-de...@googlegroups.com
Hey Guys,
I've put the android.jar in our local repository and I am trying to
retrieve it from there during the initial build instead of priming the
cache in the .m2/repository/... like what is done in your install
script. This is causing problems during the [aapt:compile] phase as for
some reason the android.jar doesn't get downloaded before this point.
If I do prime the cache with just the jar file and nothing else, during
the [compiler:compile] stage the android.pom that is in the local
repository does get downloaded correctly along with the other
dependencies for that project and everything succeeds.

Did you run into this problem as well and is that why you have that
helper script? If not can you think of any reason why the dependencies
don't seem to get resolved for this project until after the aapt compile?

I hope this question makes sense, I'm still pretty new to Maven and
haven't learned all the terminology yet.
Thanks for your help,
Eric

Here is the error :
[INFO] aapt [compile, -J, <my source path>/src/main/java, -M, <my source
path>/src/main/resources/AndroidManifest.xml, -S, <my source
path>/src/main/resources/res, -I,
/home/ehall/.m2/repository/android/android/m5-rc15/android-m5-rc15.jar]
[ERROR] W/asset (30390): Asset path
/home/ehall/.m2/repository/android/android/m5-rc15/android-m5-rc15.jar
is neither a directory nor file (type=1).
[ERROR] ERROR: Asset package include
'/home/ehall/.m2/repository/android/android/m5-rc15/android-m5-rc15.jar'
not found.

Here is th snippet of my pom, with some of our project information taken
out.
<packaging>android:apk</packaging>

<dependencies>
...
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jvending.masa.plugins</groupId>
<artifactId>maven-dx-plugin</artifactId>
</plugin>
</plugins>
</build>

Eric Hall

unread,
Jun 3, 2008, 3:00:08 PM6/3/08
to masa-de...@googlegroups.com
Hey Guys,
Using the info I found here
http://docs.codehaus.org/display/MAVENUSER/Mojo+Developer+Cookbook
I was able to modify the aapt compiler to resolve the android.jar
dependency. Here's a patch let me know what you think.

Index: AaptCompilerMojo.java
===================================================================
--- AaptCompilerMojo.java (revision 38)
+++ AaptCompilerMojo.java (working copy)
@@ -19,6 +19,10 @@
import org.apache.maven.artifact.factory.ArtifactFactory;
import
org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
@@ -47,16 +51,19 @@
private MavenProject project;

/**
- * @parameter expression="${settings.localRepository}"
- * @required
- */
- private File localRepository;
-
- /**
* @component
*/
private ArtifactFactory artifactFactory;

+ /** @component */
+ private ArtifactResolver resolver;
+
+ /** @parameter expression="${localRepository}" */
+ private ArtifactRepository localRepository;
+
+ /** @parameter expression="${project.remoteArtifactRepositories}" */
+ private java.util.List remoteRepositories;
+
/**
* @parameter default-value = "m5-rc15"
*/
@@ -95,10 +102,17 @@
}

Artifact artifact = artifactFactory.createArtifact("android",
"android", androidVersion, "jar", "jar");
- ArtifactRepositoryLayout defaultLayout = new
DefaultRepositoryLayout();
- System.out.println(defaultLayout.pathOf(artifact));
- File androidJar = new File(localRepository,
defaultLayout.pathOf(artifact));
+ try {
+ resolver.resolve( artifact, remoteRepositories, localRepository );
+ } catch ( ArtifactResolutionException e ) {
+ throw new MojoExecutionException("", e);
+ } catch (ArtifactNotFoundException e ) {
+ throw new MojoExecutionException("", e);
+ }

+
+ File androidJar = artifact.getFile();
+
List<String> commands = new ArrayList<String>();
commands.add("compile");
if (createPackageDirectories) {

Shane Isbell

unread,
Jun 3, 2008, 11:35:51 PM6/3/08
to masa-de...@googlegroups.com
I added  @requiresDependencyResolution compile to the aapt plugin. See if that solves your problem.

Eric Hall

unread,
Jun 4, 2008, 1:48:16 PM6/4/08
to masa-de...@googlegroups.com
That did it. Thanks! 

BTW as a newcomer to maven one of the things I have been struggling with is the documentation.    I've been wandering around on the  maven  homepage, and I've seen the "Better Builds with Maven" book.  But they don't usually seem to answer my questions. Do you have any good pointers?

Thanks again,
Eric

Shane Isbell

unread,
Jun 4, 2008, 2:36:15 PM6/4/08
to masa-de...@googlegroups.com
I think your best bet is: http://www.sonatype.com/book/ It's updated frequently.
 
Shane

Reply all
Reply to author
Forward
0 new messages