学习 Python

学习 Python

我有一个批处理文件,用于在 Windows 计算机上创建 .apk 文件。现在我需要能够在 Ubuntu 中创建 .apk 文件,但我不知道如何将 .bat 文件转换为脚本以便在 Ubuntu 上运行它。

以下是在 Windows 上运行良好的批处理文件。您能给我一些关于如何在 Ubuntu 上运行它的提示吗?

@echo off
set PAUSE_ERRORS=0
:user_configuration

:: Path to Flex SDK 
set FLEX_SDK=C:\sdk\flex_sdk_4.5.1.21328

:: Path to Android SDK
set ANDROID_SDK=C:\sdk\android

:validation
if not exist "%FLEX_SDK%\bin" goto flexsdk
if not exist "%ANDROID_SDK%\platform-tools" goto androidsdk
goto succeed

:validation
if not exist "%FLEX_SDK%\bin" goto flexsdk
if not exist "%ANDROID_SDK%\platform-tools" goto androidsdk
goto succeed

:flexsdk
echo.
echo ERROR: incorrect path to Flex SDK
echo.
if %PAUSE_ERRORS%==1 pause
exit

:androidsdk
echo.
echo ERROR: incorrect path to Android SDK in 'bat\SetupSDK.bat'
echo.

if %PAUSE_ERRORS%==1 pause
exit

:succeed
set PATH=%PATH%;%FLEX_SDK%\bin
set PATH=%PATH%;%ANDROID_SDK%\platform-tools

:: Android packaging
set AND_CERT_NAME="PeymanApp"
set AND_CERT_PASS=fd
set AND_CERT_FILE=cert\SampleApp.p12
set AND_ICONS=icons/android

set AND_SIGNING_OPTIONS=-storetype pkcs12 -keystore "%AND_CERT_FILE%" -storepass     %AND_CERT_PASS%

:: Application descriptor
set APP_XML=application.xml

:: Files to package
set APP_DIR=bin
set FILE_OR_DIR=-C %APP_DIR% .

:: Your application ID (must match <id> of Application descriptor)
set APP_ID=air.com.doitflash.SampleApp

:: Output packages
set DIST_PATH=dist
set DIST_NAME=PeymanApp

:validation
%SystemRoot%\System32\find /C "<id>%APP_ID%</id>" "%APP_XML%" > NUL
if errorlevel 1 goto badid
goto end_validation

:badid
echo.
echo ERROR: Application ID (APP_ID) does NOT match Application descriptor '%APP_XML%'     (id)

echo.

:end_validation

set TARGET=
set PLATFORM=android

::call bat\Packager.bat
if "%PLATFORM%"=="android" goto android-config

:android-config
set CERT_FILE=%AND_CERT_FILE%
set SIGNING_OPTIONS=%AND_SIGNING_OPTIONS%
set ICONS=%AND_ICONS%
set DIST_EXT=apk
set TYPE=apk
goto start

:start
if not exist "%CERT_FILE%" goto certificate
:: Output file
set FILE_OR_DIR=%FILE_OR_DIR% -C "%ICONS%" .
if not exist "%DIST_PATH%" md "%DIST_PATH%"
set OUTPUT=%DIST_PATH%\%DIST_NAME%%TARGET%.%DIST_EXT%
:: Package

echo true
echo.
call adt -package -target %TYPE%%TARGET% %OPTIONS% %SIGNING_OPTIONS% "%OUTPUT%"     "%APP_XML%" %FILE_OR_DIR% -extdir lib/
echo.
if errorlevel 1 goto failed
goto end

:certificate
echo Certificate not found: %CERT_FILE%
echo.

if %PAUSE_ERRORS%==1 pause
exit

:failed
echo APK setup creation FAILED.

if %PAUSE_ERRORS%==1 pause
exit

:end

答案1

您需要学习编写 bash 脚本。这些脚本相当于 Windows 批处理文件。语法并不难理解。我建议谷歌搜索,因为有很多很棒的免费教程。

我建议BASH 编程 - 简介 HOW-TO

请注意,您需要将 Windows 样式的路径更改为 Linux 样式。例如

my_drive_letter:\my_folder\myfile

变成

/media/my_drive_label/my_folder/my_file

答案2

确保已安装葡萄酒安装 wine,然后在终端中执行以下命令:

wine cmd

这将打开 Windows 命令提示符。.bat从那里开始。

答案3

学习 Python

你可能想要学习 Python

它是简单易学比一些更易读其他脚本语言... ;-)

答案4

我无法帮助重新编码,但有一份文档解释了 shell 脚本的工作原理以及需要使用哪些命令。我想重写脚本应该就足够了:

http://linuxcommand.org/writing_shell_scripts.php

相关内容