How to support osgi in android gradle plugin enviroment?

I want to use apk as an osgi bundle, and then load it in a host application.

Now, it works ok. But I must manually do these things before push the osgi bundle to phone:

  1. Open osgi bundle apk file with WinRAR.
  2. Drag the built classes(in extension-a\build\intermediates\classes\debug\com) to the bundle file’s root directory.
  3. Drag the modified MANIFEST.MF (including OSGI config info) to the bundle file’s META-INFO/MANIFEST.MF .
  4. Sign the bundle apk at last.

I want to know how to write some gradle scripts to do these things automatically?

I use gradle 2.2.1, and ‘’.

I know there is a gradle plugin “osgi” can generate the MANIFEST.MF for osgi bunlde, but it only works with “java” gradle plugin.
I can’t use it with “android” gradle plugin.


I try to do it this way, but it not work:

	android.applicationVariants.all { variant ->
		variant.outputs[0].packageApplication.doLast {
			String zipFileName = variant.outputs[0]
			String inputFile = 'MANIFEST.MF'  
			def zipIn = variant.outputs[0].outputFile
			def zip = new ZipFile(zipIn.getAbsolutePath())
			def zipTemp = new File(zipFileName + "_temp") 
			def zos = new ZipOutputStream(new FileOutputStream(zipTemp))
			def toModify = 'META-INFO/MANIFEST.MF'

			for(e in zip.entries()) {
				if(! {
					zos << zip.getInputStream(e).bytes
				} else {
					zos.putNextEntry(new ZipEntry(toModify))
					zos << new File(inputFile).bytes

  1. If use “gradle clean build”, it report “out-file.apk” not found.
  2. If the out-file.apk exists, it report exception: invalid entry compressed size (expected 695 but got 693 bytes)
    at Source)