6

I have added a dynamic feature module to my project and everything works fine when trying on emulator or direct run on a device (using the run button) but when I try to generate a APK using command line (:app:assembleRelease) the dynamic feature modules wont be included in the final APK and it's missing. I know I can create a Android App Bundle and then create a APK from .aab with all the modules. but the question is:

is there a way to create full apk (all modules such as: Dynamic features included) directly form source?

Adnan Abdollah Zaki
  • 4,328
  • 6
  • 52
  • 58
seyed Jafari
  • 1,235
  • 10
  • 20

2 Answers2

3

I think you can't create full apk directly form source.

You should take 3 steps:

  1. Build app bundle:

    ./gradlew clean bundleRelease

  2. Generate one apk by bundletool with switch --mode=universal

    java -jar bundletool-all-0.10.2.jar build-apks --bundle=app.aab --output=release.apks --ks=release.keystore --ks-pass=pass:xxxxxx --ks-key-alias=xxxxxxkey --key-pass=pass:xxxxxx --mode=universal

  3. Unzip generated file:

    unzip release.apks

AdamN
  • 476
  • 5
  • 13
1

With the command line, you should use :app:bundleRelease which will build an Android App Bundle (.San), then use bundletool to generate the APKs and deploy them to the device.

The full documentation can be found here: https://developer.android.com/studio/command-line/bundletool

Pierre
  • 15,865
  • 4
  • 36
  • 50
  • 1
    supporting comment for @Pierre reply by copying the commands from link mentioned. https://developer.android.com/studio/build/building-cmdline#bundle_build_gradle bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks --ks=/MyApp/keystore.jks --ks-pass=file:/MyApp/keystore.pwd --ks-key-alias=MyKeyAlias --key-pass=file:/MyApp/key.pwd https://developer.android.com/studio/command-line/bundletool#generate_apks – Ranjan Kumar Jul 06 '19 at 08:54
  • thanks for the answer. what I'm actually looking for is like shortcut from source to APK without first generating AAB then APK. is there anyway you can think of? – seyed Jafari Jul 06 '19 at 09:17
  • File a feature request in the Android Gradle Plugin, I think a task exists, but I'm not sure it's exposed or documented. – Pierre Jul 06 '19 at 10:38