lib/dryrun/android_project.rb in dryrun-0.3.6 vs lib/dryrun/android_project.rb in dryrun-0.4.0

- old
+ new

@@ -1,6 +1,8 @@ require 'nokogiri' +require 'fileutils' +require 'tempfile' module DryRun class AndroidProject @@ -8,10 +10,36 @@ @base_path = path @settings_gradle_path = settings_gradle @modules = find_modules end + def remove_local_properties + Dir.chdir @base_path + file_name = 'local.properties' + + if File.exist?(file_name) + File.remove(file_name) + end + end + + def remove_application_id + # Open temporary file + tmp = Tempfile.new("extract") + + file = "#{@path_to_sample}/build.gradle" + + # Write good lines to temporary file + open(file, 'r').each { |l| tmp << l unless l.include? 'applicationId' } + + # Close tmp, or troubles ahead + tmp.close + + # Move temp file to origin + FileUtils.mv(tmp.path, file) + + end + def settings_gradle "#{@base_path}/settings.gradle" end def is_valid @@ -27,11 +55,11 @@ return [] end end # ./gradlew clean installDebug - def clean_install + def install Dir.chdir @base_path path, execute_line = self.sample_project @@ -40,29 +68,39 @@ exit 1 end builder = "gradle" - if File.exist?("gradlew") - system("chmod +x gradlew") - builder = "./gradlew" + if File.exist?('gradlew') + system('chmod +x gradlew') + + builder = 'sh gradlew' end + + # Generate the gradle/ folder + if File.exist?('gradlew') and !File.directory?('gradle/') + system('gradle wrap') + end + self.uninstall + self.remove_application_id + self.remove_local_properties system("#{builder} clean assembleDebug installDebug") puts "Installing #{@package.green}...\n" - puts "executing: #{execute_line}" + puts "executing: #{execute_line.green}\n\n" system(execute_line) end def sample_project @modules.each do |child| full_path = "#{@base_path}#{child.first}" + @path_to_sample = full_path execute_line = get_execute_line("#{full_path}/src/main/AndroidManifest.xml") return full_path, execute_line if execute_line end @@ -94,13 +132,17 @@ return false end f.close - "adb shell am start -n #{@package}/#{@launcher_activity}" + "adb shell am start -n \"#{get_launchable_activity}\" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER" end + def get_launchable_activity + full_path_to_launcher = "#{@package}#{@launcher_activity.gsub(@package,'')}" + "#{@package}/#{full_path_to_launcher}" + end def get_package(doc) doc.xpath("//manifest").attr('package').value end