Android - Build (Gradle) / Run the app

About

Gradle is the build system that packages up and compiles Android Apps. Android Studio automatically generates Gradle files for your application, including:

  • the build.gradle for your app and module
  • and the settings.gradle for your app.

You do not need to create these files.

Android Studio uses Gradle to compile and build your app. There is a build.gradle file for each module of your project, as well as a build.gradle file for the entire project.

Gradle

Build

You can run Gradle from the terminal but you can also use the run button which will automatically run the Gradle scripts in your project.

cd project/Path
./gradlew assembleDebug
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
:app:prepareComAndroidSupportDesign2311Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources UP-TO-DATE
:app:transformClassesWithDexForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders UP-TO-DATE
:app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug UP-TO-DATE
:app:zipalignDebug UP-TO-DATE
:app:assembleDebug UP-TO-DATE

BUILD SUCCESSFUL

Total time: 2 mins 9.708 secs

Apk

The build will output an APK in the following directory:

app\build\outputs\apk

Installation

with adb

adb install -r app/build/outputs/apk/app-debug-unaligned.apk
2101 KB/s (1411332 bytes in 0.655s)
        pkg: /data/local/tmp/app-debug-unaligned.apk
Success

Main activity start

Starting the main activity

adb shell am start -n com.example.nicolasgerard.sunshine/com.example.nicolasgerard.sunshine.MainActivity
Starting: Intent { cmp=com.example.nicolasgerard.sunshine/.MainActivity }

Version

Support

Sync Project with Gradle Files

If your project is having Gradle issues, sometimes clicking the Sync Project with Gradle Files button helps.

Documentation / Reference


Powered by ComboStrap