lib/dryrun/android_project.rb in dryrun-0.6.3 vs lib/dryrun/android_project.rb in dryrun-0.6.4

- old
+ new

@@ -1,8 +1,9 @@ require 'oga' require 'fileutils' require 'tempfile' +require 'find' require_relative 'dryrun_utils' module DryRun class AndroidProject def initialize(path, custom_app_path, custom_module, flavour) @@ -150,32 +151,41 @@ def uninstall_application DryrunUtils.execute(get_uninstall_command) # > /dev/null 2>&1") end def get_execution_line_command(path_to_sample) - path_to_manifest = File.join(path_to_sample, 'src/main/AndroidManifest.xml') + manifest_file = get_manifest(path_to_sample) - if !File.exist?(path_to_manifest) + if manifest_file.nil? return false end - f = File.open(path_to_manifest) + doc = Oga.parse_xml(manifest_file) - doc = Oga.parse_xml(f) - @package = get_package(doc) @launcher_activity = get_launcher_activity(doc) if !@launcher_activity return false end - f.close + manifest_file.close "adb shell am start -n \"#{get_launchable_activity}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER" end + def get_manifest(path_to_sample) + default_path = File.join(path_to_sample, 'src/main/AndroidManifest.xml') + if File.exist?(default_path) + return File.open(default_path) + else + Find.find(path_to_sample) do |path| + return File.open(path) if path =~ /.*AndroidManifest.xml$/ + end + end + end + def get_launchable_activity full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package,'')}" "#{@package}/#{full_path_to_launcher}" end @@ -187,10 +197,10 @@ activities = doc.css('activity') activities.each do |child| intent_filter = child.css('intent-filter') if intent_filter != nil and intent_filter.length != 0 - return child.xpath("//activity").attr("android:name").last.value + return child.attr("android:name").value end end false end end