问题
For Java library projects, the artifact to publish is straightforward since the output is a single jar file. However, I also have a project with the following stuff to publish:
- MyLib.jar
- armeabi/libStuff.so
- armeabi-v7a/libStuff.so
- mips/libStuff.so
- x86/libStuff.so
I cannot setup all those .so files as artifacts, since they all have the same name. What is the recommended way to go? Put everything in a zip and let users use gradle (or ant or whatever) to unzip it prior to the build? Should I put the Jar file aside from the zip? Is there a convention for such artifacts?
回答1:
The best way with Ivy to manage many "same" artifact which only difference is the architecture, is to use extra attributes.
So in your module you would declare:
<publications xmlns:e="http://ant.apache.org/ivy/extra">
<artifact name="MyLib" type="jar" ext="jar" />
<artifact name="libStuff" type="native" ext="so" e:arch="armeabi" />
<artifact name="libStuff" type="native" ext="so" e:arch="armeabi-v7a" />
<artifact name="libStuff" type="native" ext="so" e:arch="mips" />
<artifact name="libStuff" type="native" ext="so" e:arch="x86" />
</publications>
The drawbacks is that your entire chain around Ivy would have to take that extra attribute into account. For instance, you should be able to configure your repository so it would accept a custom pattern like this one:
${repository.dir}/[organisation]/[module]/[arch]/[revision]/[artifact].[ext]
Another solution, as you mentioned, is to work with a zip folder. And this may be a good timing since Ivy 2.4 which is just about to be released, is supporting zipped folder via packaging.
For instance you could declare:
<publications xmlns:e="http://ant.apache.org/ivy/extra">
<artifact name="MyLib" type="jar" ext="jar" />
<artifact name="libStuff" type="natives" ext="zip" packaging="zip" />
</publications>
Then Ivy will download a libStuff-1.2.3.zip
into its cache and will automatically unzip it into the cache to libStuff-1.2.3
, folder in which you could find your several natives libraries.
来源:https://stackoverflow.com/questions/21086191/how-to-publish-native-libraries-with-ivy