はじめに

AndroidStudio作成のgradle環境のプロジェクトをコマンド実行します。
gradleコマンドは全環境に依存しているため、プロジェクト毎に関連性を持つGradleをラップしたgradlewコマンドを使います。

前回作成のプロジェクトをコマンド実行してみます
[Android]Gradleファイルで環境ごとに処理を切り分け(APK名・Keystore設定など)

プロジェクトは以下
https://github.com/y-matsumoto/template-project

タスク確認

プロジェクト直下にgradlew.batができてます。こちらを使います。
まずはプロジェクト直下に移動して以下のコマンドを実行し、タスク一覧を確認します

$ gradlew tasks
Parallel execution with configuration on demand is an incubating feature.
:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Android tasks
-------------
androidDependencies - Displays the Android dependencies of the project.
signingReport - Displays the signing info for each variant.
sourceSets - Prints out all the source sets defined in this project.

Build tasks
-----------
assemble - Assembles all variants of all applications and secondary packages.
assembleAndroidTest - Assembles all the Test applications.
assembleDebug - Assembles all Debug builds.
assembleDevelop - Assembles all Develop builds.
assembleProduct - Assembles all Product builds.
assembleRelease - Assembles all Release builds.
assembleStaging - Assembles all Staging builds.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
clean - Deletes the build directory.
compileDevelopDebugAndroidTestSources
compileDevelopDebugSources
compileDevelopDebugUnitTestSources
compileDevelopReleaseSources
compileDevelopReleaseUnitTestSources
compileProductDebugAndroidTestSources
compileProductDebugSources
compileProductDebugUnitTestSources
compileProductReleaseSources
compileProductReleaseUnitTestSources
compileStagingDebugAndroidTestSources
compileStagingDebugSources
compileStagingDebugUnitTestSources
compileStagingReleaseSources
compileStagingReleaseUnitTestSources
mockableAndroidJar - Creates a version of android.jar that's suitable for unit tests.

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
components - Displays the components produced by root project 'template-project'. [incubating]
dependencies - Displays all dependencies declared in root project 'template-project'.
dependencyInsight - Displays the insight into a specific dependency in root project 'template-project'.
help - Displays a help message.
model - Displays the configuration model of root project 'template-project'. [incubating]
projects - Displays the sub-projects of root project 'template-project'.
properties - Displays the properties of root project 'template-project'.
tasks - Displays the tasks runnable from root project 'template-project' (some of the displayed tasks may belong to subprojects).

Install tasks
-------------
installDevelopDebug - Installs the DebugDevelop build.
installDevelopDebugAndroidTest - Installs the android (on device) tests for the DevelopDebug build.
installProductDebug - Installs the DebugProduct build.
installProductDebugAndroidTest - Installs the android (on device) tests for the ProductDebug build.
installStagingDebug - Installs the DebugStaging build.
installStagingDebugAndroidTest - Installs the android (on device) tests for the StagingDebug build.
uninstallAll - Uninstall all applications.
uninstallDevelopDebug - Uninstalls the DebugDevelop build.
uninstallDevelopDebugAndroidTest - Uninstalls the android (on device) tests for the DevelopDebug build.
uninstallDevelopRelease - Uninstalls the ReleaseDevelop build.
uninstallProductDebug - Uninstalls the DebugProduct build.
uninstallProductDebugAndroidTest - Uninstalls the android (on device) tests for the ProductDebug build.
uninstallProductRelease - Uninstalls the ReleaseProduct build.
uninstallStagingDebug - Uninstalls the DebugStaging build.
uninstallStagingDebugAndroidTest - Uninstalls the android (on device) tests for the StagingDebug build.
uninstallStagingRelease - Uninstalls the ReleaseStaging build.

Verification tasks
------------------
check - Runs all checks.
connectedAndroidTest - Installs and runs instrumentation tests for all flavors on connected devices.
connectedCheck - Runs all device checks on currently connected devices.
connectedDevelopDebugAndroidTest - Installs and runs the tests for developDebug on connected devices.
connectedProductDebugAndroidTest - Installs and runs the tests for productDebug on connected devices.
connectedStagingDebugAndroidTest - Installs and runs the tests for stagingDebug on connected devices.
deviceAndroidTest - Installs and runs instrumentation tests using all Device Providers.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
lint - Runs lint on all variants.
lintDevelopDebug - Runs lint on the DevelopDebug build.
lintDevelopRelease - Runs lint on the DevelopRelease build.
lintProductDebug - Runs lint on the ProductDebug build.
lintProductRelease - Runs lint on the ProductRelease build.
lintStagingDebug - Runs lint on the StagingDebug build.
lintStagingRelease - Runs lint on the StagingRelease build.
test - Run unit tests for all variants.
testDevelopDebugUnitTest - Run unit tests for the developDebug build.
testDevelopReleaseUnitTest - Run unit tests for the developRelease build.
testProductDebugUnitTest - Run unit tests for the productDebug build.
testProductReleaseUnitTest - Run unit tests for the productRelease build.
testStagingDebugUnitTest - Run unit tests for the stagingDebug build.
testStagingReleaseUnitTest - Run unit tests for the stagingRelease build.

Other tasks
-----------
clean
jarDevelopDebugClasses
jarDevelopReleaseClasses
jarProductDebugClasses
jarProductReleaseClasses
jarStagingDebugClasses
jarStagingReleaseClasses
lintVitalDevelopRelease - Runs lint on just the fatal issues in the DevelopRelease build.
lintVitalProductRelease - Runs lint on just the fatal issues in the ProductRelease build.
lintVitalStagingRelease - Runs lint on just the fatal issues in the StagingRelease build.

To see all tasks and more detail, run gradlew tasks --all

To see more detail about a task, run gradlew help --task <task>

BUILD SUCCESSFUL

Total time: 4.033 secs

Androidプロジェクトのビルド

タスクにより端末にインストールや、ビルド、APKファイル作成を指定環境ごとに作成します。

試しにassembleReleaseタスクを実行します

$ gradlew assembleDebug
Parallel execution with configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDevelopDebugBuild UP-TO-DATE
:app:checkDevelopDebugManifest
:app:preDevelopReleaseBuild UP-TO-DATE
:app:preProductDebugBuild UP-TO-DATE
:app:preProductReleaseBuild UP-TO-DATE
:app:preStagingDebugBuild UP-TO-DATE
:app:preStagingReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72221Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2221Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42221Library UP-TO-DATE
:app:prepareDevelopDebugDependencies
:app:compileDevelopDebugAidl UP-TO-DATE
:app:compileDevelopDebugRenderscript UP-TO-DATE
:app:generateDevelopDebugBuildConfig UP-TO-DATE
:app:generateDevelopDebugAssets UP-TO-DATE
:app:mergeDevelopDebugAssets UP-TO-DATE
:app:generateDevelopDebugResValues UP-TO-DATE
:app:generateDevelopDebugResources UP-TO-DATE
:app:mergeDevelopDebugResources UP-TO-DATE
:app:processDevelopDebugManifest UP-TO-DATE
:app:processDevelopDebugResources UP-TO-DATE
:app:generateDevelopDebugSources UP-TO-DATE
:app:processDevelopDebugJavaRes UP-TO-DATE
:app:compileDevelopDebugJavaWithJavac UP-TO-DATE
:app:compileDevelopDebugNdk UP-TO-DATE
:app:compileDevelopDebugSources UP-TO-DATE
:app:preDexDevelopDebug UP-TO-DATE
:app:dexDevelopDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDevelopDebug
:app:zipalignDevelopDebug
:app:assembleDevelopDebug
:app:checkProductDebugManifest
:app:prepareProductDebugDependencies
:app:compileProductDebugAidl UP-TO-DATE
:app:compileProductDebugRenderscript UP-TO-DATE
:app:generateProductDebugBuildConfig UP-TO-DATE
:app:generateProductDebugAssets UP-TO-DATE
:app:mergeProductDebugAssets UP-TO-DATE
:app:generateProductDebugResValues UP-TO-DATE
:app:generateProductDebugResources UP-TO-DATE
:app:mergeProductDebugResources UP-TO-DATE
:app:processProductDebugManifest UP-TO-DATE
:app:processProductDebugResources UP-TO-DATE
:app:generateProductDebugSources UP-TO-DATE
:app:processProductDebugJavaRes UP-TO-DATE
:app:compileProductDebugJavaWithJavac UP-TO-DATE
:app:compileProductDebugNdk UP-TO-DATE
:app:compileProductDebugSources UP-TO-DATE
:app:preDexProductDebug UP-TO-DATE
:app:dexProductDebug UP-TO-DATE
:app:packageProductDebug
:app:zipalignProductDebug
:app:assembleProductDebug
:app:checkStagingDebugManifest
:app:prepareStagingDebugDependencies
:app:compileStagingDebugAidl UP-TO-DATE
:app:compileStagingDebugRenderscript UP-TO-DATE
:app:generateStagingDebugBuildConfig UP-TO-DATE
:app:generateStagingDebugAssets UP-TO-DATE
:app:mergeStagingDebugAssets UP-TO-DATE
:app:generateStagingDebugResValues UP-TO-DATE
:app:generateStagingDebugResources UP-TO-DATE
:app:mergeStagingDebugResources UP-TO-DATE
:app:processStagingDebugManifest UP-TO-DATE
:app:processStagingDebugResources UP-TO-DATE
:app:generateStagingDebugSources UP-TO-DATE
:app:processStagingDebugJavaRes UP-TO-DATE
:app:compileStagingDebugJavaWithJavac UP-TO-DATE
:app:compileStagingDebugNdk UP-TO-DATE
:app:compileStagingDebugSources UP-TO-DATE
:app:preDexStagingDebug UP-TO-DATE
:app:dexStagingDebug UP-TO-DATE
:app:packageStagingDebug
:app:zipalignStagingDebug
:app:assembleStagingDebug
:app:assembleDebug

BUILD SUCCESSFUL

Total time: 5.978 secs

BUILD SUCCESSFULで成功です。
template-project\app\build\outputs\apkディレクトリにdebugモードで各環境(develop,staging,product)でapkファイルが作成されます。

環境毎に実行する場合はassembleDevelop,assembleStaging,assembleProductタスクを実行してください。debug,releaseでファイルが作成されます。
ant,mavenより簡単で早いですね。

その他おすすめの備忘録

Tagged with:
 

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>