7

Both gradlew packageDebug and gradlew assembleDebug will create my APK. assembleDebug appears to rely on packageDebug, so what else is it doing for me? Is there some reason I should be using one or the other?

2 Answers 2

5

If you run the gradle tasks:

gradle packageDebug --info
gradle assembleDebug --info

the secuence of gradle tasks executed are the same, except one, the last:

zipalignDebug

And referencing to zipalign, this task perform optimizations on apk file. This process is carried out once generated and signed the apk. That's why when you run on the two tasks, you see a generated apk file.

1

Use assembleDebug, it's NOT equivalent to packageDebug. assembleDebug contains packageDebug and perform other tasks as well.

Below you will find a list of all tasks included in assembleDebug, one of them is packageDebug.

app:assembleDebug - Assembles all Debug builds
    app:checkDebugManifest
    app:compileDebugAidl
    app:compileDebugJava
    app:compileDebugNdk
    app:compileDebugRenderscript
    app:dexDebug      
    app:generateDebugAssets
    app:generateDebugBuildConfig
    app:generateDebugResValues
    app:generateDebugResources
    app:generateDebugSources
    app:mergeDebugAssets
    app:mergeDebugResources
    app:packageDebug  
    app:preBuild      
    app:preDebugBuild 
    app:preDexDebug   
    app:preReleaseBuild
    app:prepareComAndroidSupportSupportV132000Library - Prepare com.android.support:support-v13:20.0.0
    app:prepareComAndroidSupportSupportV42000Library - Prepare com.android.support:support-v4:20.0.0
    app:prepareDebugDependencies
    app:processDebugJavaRes
    app:processDebugManifest
    app:processDebugResources
    app:validateDebugSigning
    app:zipalignDebug 

Additionally, from the Gradle Plugin documentation:

An Android project has at least two outputs: a debug APK and a release APK. Each of these has its own anchor task to facilitate building them separately:

- assemble
   - assembleDebug
   - assembleRelease

They both depend on other tasks that execute the multiple steps needed to build an APK. The assemble task depends on both, so calling it will build both APKs

4
  • Why does assembleDebug call preReleaseBuild? (none of the other dependent tasks have Release in their name)
    – riper
    Commented Oct 27, 2014 at 13:43
  • I am not sure. It seems that every build takes into account other build types for the very initial steps. assembleRelease call preDebugBuild too. If you run a task with -profile flag and open HTML report you will notice that these unexpected steps take no time, actually profile report says that it did not work Commented Oct 27, 2014 at 14:06
  • How did you find out which tasks are included with assembleDebug?
    – dazza5000
    Commented Mar 11, 2016 at 0:52
  • 1
    @dazza5000 just type ./gradlew tasks --all in Android Studio terminal Commented Mar 11, 2016 at 11:46

Not the answer you're looking for? Browse other questions tagged or ask your own question.