Method: AndParcel::InstallRequest#manifest

Defined in:
lib/andparcel/parcel.rb

#manifest(zf) ⇒ Object

If the parcel has a ManifestMerge.xml file, back up and then open the project’s AndroidManifest.xml file, and merge in anything with a distinct name.



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
# File 'lib/andparcel/parcel.rb', line 391

def manifest(zf)
	if zf.find_entry('ManifestMerge.xml')
		dest=File.join(@root, 'AndroidManifest.xml')
	
		if File.exists? dest
			backup=dest+'~'
			File.unlink backup if File.exists?(backup)
			FileUtils.cp dest, backup
			
			doc=Nokogiri::XML(open(dest))
			app=doc.search('application')[0]
			merge=Nokogiri::XML(zf.read('ManifestMerge.xml'))
			
			merge.root.children.each do |node|
				if node.element?
					if $COMPONENTS.include?(node.name)
						existing=app.xpath("*[@android:name='#{node['name']}']",
															 'android'=>"http://schemas.android.com/apk/res/android")
						
						if existing.size==0
							app.add_child(node.to_s)
						end
					else
						# no support for other elements right now
					end
				end
			end
			
			open(dest, "w") {|f| f.puts doc.to_s }
		end
	end
	
	true
end