$DO_CLEAR ||= true
$SDK_VERSION ||= '19.0.1' #NOT OK
#$SDK_VERSION = '23.0.1'
#$SDK_VERSION = 'show'
#$SDK_VERSION = '23.0.2' #NOT OK
$ENV_KEYS = ['MAIN_CLASS', 'PACKAGE_PATH', 'PACKAGE']
$ENV_KEYS << 'JAVA_HOME'
$ENV_KEYS << 'ANDROID_HOME'
$ENV_KEYS << 'DEV_HOME'
$ENV_KEYS << 'AAPT_PATH'
$ENV_KEYS << 'DX_PATH'
$ENV_KEYS << 'ANDROID_JAR'
$ENV_KEYS << 'ADB'
def subst_env_vars(s)
s.gsub(/%([A-Z_]+)%/){
env_var = $1
val = ENV[env_var]
raise "Can't FOUND ENV['#{env_var}']" if val.nil?
val
}
end
AndroidManifest = open('AndroidManifest.xml').read
main_activity = nil
if AndroidManifest =~ %r{<application\s+.*?<(activity|service).*?android:name="([^"]+)"}m
main_activity = $2
main_activity = main_activity[1 .. -1] if main_activity[0 .. 0] == "."
ENV['MAIN_CLASS'] = main_activity
puts "Main Activity name: '#{ENV['MAIN_CLASS']}'"
else
raise "Can't match MAIN ACTIVITY name in manifest"
end
main_activity_java = main_activity + '.java'
puts "Main Activity JAVA filename: '#{main_activity_java}'"
puts "Search '#{main_activity_java}' in 'src/...'"
files = Dir['src/**/' + main_activity_java]
if files.size == 1
puts "FOUND! in '#{files[0]}'"
else
if files.size == 0
raise "Can't found '#{main_activity_java}'"
else
puts "Found TOO MANY files:"
files.each{ |f|
puts f
}
raise "UPS!"
end
end
main_java = files[0]
puts "main_java='#{main_java}'"
#main_java=src/com/example/mysecondapp/MainActivity.java
#на нужно ^^^^^^^^^^^^^^^^^^^^^^^
if main_java =~ %r|^src/(.*?)/#{main_activity_java}$|i
$PACKAGE_PATH = $1
ENV['PACKAGE_PATH'] = $1
puts "PACKAGE_PATH=#{ENV['PACKAGE_PATH']}"
else
raise "Can't match PACKAGE_PATH main activity file name '#{main_java}'"
end
if AndroidManifest =~ %r{<manifest.*?\s+package="([^"]+)"}m
ENV['PACKAGE'] = $1
puts "PACKAGE=#{ENV['PACKAGE']}"
else
raise "Can't match PACKAGE name in manifest (attrib 'package')"
end
ENV['JAVA_HOME'] = "C:\\prog\\sdk\\jdk\\1.7"
ENV['ANDROID_HOME'] = "C:\\prog\\sdk\\android-studio\\sdk"
ENV['DEV_HOME'] = Dir.getwd
ENV['AAPT_PATH'] = "%ANDROID_HOME%/build-tools/#{$SDK_VERSION}/aapt.exe"
ENV['DX_PATH'] = "%ANDROID_HOME%/build-tools/#{$SDK_VERSION}/dx.bat"
ENV['ANDROID_JAR'] = "%ANDROID_HOME%/platforms/android-#{$SDK_VERSION[0 .. 1]}/android.jar"
ENV['ADB'] = "%ANDROID_HOME%/platform-tools/adb.exe"
if !File::exist?(subst_env_vars(ENV['AAPT_PATH']))
puts "Invalid $SDK_VERSION='#{$SDK_VERSION}'"
puts "VALID Versions is:"
Dir[subst_env_vars("%ANDROID_HOME%/build-tools/*").gsub('\\', '/')].each{ |d|
puts File::basename(d)
}
exit
end
#set AAPT_PATH=%ANDROID_HOME%/build-tools/19.0.1/aapt.exe
puts "ENV variables ready"
open('set_env.bat', 'w'){ |h|
$ENV_KEYS.each{ |k|
puts "#{k}=#{ENV[k]}"
h.puts "SET #{k}=#{ENV[k]}"
}
}
def get_uts(ts = nil, format = "%03d")
ts ||= Time.now
ts.strftime('%H:%M:%S.') + (format % (ts.usec / 1000))
end
def abs_dt
now = Time.now
$started ||= now
$prev_time ||= now
s = sprintf("%0.3f, +%0.3f", now - $started, now - $prev_time)
$prev_time = now
s
end
def wrap_cmd(cmd_orig, comment = nil, called_from = nil)
called_from ||= caller[0]
cmd = subst_env_vars(cmd_orig)
# begin
s = Time.now
$logger << "#{get_uts(s)} COMMENT: #{comment}" if comment
$logger << "#{get_uts(s)} CMD original: '#{cmd_orig}'"
$logger << "#{get_uts(s)} CMD: '#{cmd}', Time offset: #{abs_dt}"
o = `#{cmd} 2>&1`
exitstatus = $?.exitstatus
e = Time.now
dt = (e - s).to_f
$logger << "#{get_uts(e)} exitstatus=#{exitstatus} DT=#{dt}sec, Time offset: #{abs_dt}"
$logger << (("*" * 34) + " CMD OUTPUT " + (("*" * 34)))
$logger.raw(o)
$logger << "*" * 80
if (exitstatus != 0)
puts ""
raise "Some thing wrong... exitstatus=#{exitstatus}"
puts "\7\7\7"
sleep(10)
end
# rescue
# end
end
Dir::mkdir_p('logs')
log_name = Time.now.strftime('logs/BUILD_%Y-%m-%d_%H-%M-%S.log')
$logger = MyLoggerWithEcho.new(log_name)
wrap_cmd('clear.bat') if $DO_CLEAR
Dir::mkdir_p('bin')
Dir::mkdir_p('obj')
Dir::mkdir_p('logs')
#wrap_cmd('%AAPT_PATH% package -f -m -S %DEV_HOME%/res -J %DEV_HOME%/src -M %DEV_HOME%/AndroidManifest.xml -I %ANDROID_JAR%', 'create R.java')
wrap_cmd('%AAPT_PATH% package -f -m -S %DEV_HOME%/res -J %DEV_HOME%/bin -M %DEV_HOME%/AndroidManifest.xml -I %ANDROID_JAR%', 'create R.java')
wrap_cmd('%JAVA_HOME%/bin/javac -d %DEV_HOME%/obj -cp %ANDROID_JAR% -sourcepath %DEV_HOME%/src %DEV_HOME%/src/%PACKAGE_PATH%/*.java bin/%PACKAGE_PATH%/R.java', 'compile, convert class->dex and create APK')
wrap_cmd('%DX_PATH% --dex --output=%DEV_HOME%/bin/classes.dex %DEV_HOME%/obj', 'compile, convert class->dex and create APK')
wrap_cmd('%AAPT_PATH% package -f -M %DEV_HOME%/AndroidManifest.xml -S %DEV_HOME%/res -I %ANDROID_JAR% -F %DEV_HOME%/bin/AndroidTest.unsigned.apk %DEV_HOME%/bin', 'compile, convert class->dex and create APK')
wrap_cmd('%JAVA_HOME%/bin/keytool -genkey -validity 10000 -dname "CN=AndroidDebug, O=Android, C=US" -keystore %DEV_HOME%/AndroidTest.keystore -storepass android -keypass android -alias androiddebugkey -keyalg RSA -keysize 2048', 'create key and signed APK')
wrap_cmd('%JAVA_HOME%/bin/jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore %DEV_HOME%/AndroidTest.keystore -storepass android -keypass android -signedjar %DEV_HOME%/bin/AndroidTest.signed.apk %DEV_HOME%/bin/AndroidTest.unsigned.apk androiddebugkey', 'create key and signed APK')
wrap_cmd('%ADB% uninstall %PACKAGE%', 'UNinstall APK on device')
wrap_cmd('%ADB% install %DEV_HOME%/bin/AndroidTest.signed.apk', 'INSTALL APK on device')
wrap_cmd('%ADB% shell am start -n %PACKAGE%/%PACKAGE%.%MAIN_CLASS%', 'START APK on device')
Вообще есть приблуда/виджет как раз то что на картинке что-то типа таск менеджера, выводит список работающих приложений, вот хочу такую же написать, а в перспективе авто прибивание ненужных программ :) Вопрос куда копать? Есть ли апи для этого и как для начала получить список работающих программ/активити/сервисов?
1) броузер упадет с ошибкой,
2) отключат свет
3) +100500 других вариантов и их сочетаний
?
Что-то мне подсказывает, что никакие пляски с бубном здесь не помогут и придется тянуть эти гигабайты заново...
Особенно если учесть что и обычные закачки далеко не всегда возобновляемые... да хотя бы тот же горячо любимый гугл диск