Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dynamic feature moduleの基本 / Cookpad.apk #2

star_zero
February 18, 2019

Dynamic feature moduleの基本 / Cookpad.apk #2

star_zero

February 18, 2019
Tweet

More Decks by star_zero

Other Decks in Programming

Transcript

  1. DFM/build.gradle apply plugin: 'com.android.dynamic-feature' android { compileSdkVersion 28 defaultConfig {

    minSdkVersion 21 targetSdkVersion 28 } } dependencies { implementation project(':app') implementation project(':core') }
  2. app/build.gradle apply plugin: 'com.android.application' android { // ... dynamicFeatures =

    [":feature_one", "feature_two"] } dependencies { implementation project(':core') }
  3. Dynamic Delivery val manager = SplitInstallManagerFactory.create(this) if (manager.installedModules.contains(MODULE_NAME)) { //

    インストール済み return } val request = SplitInstallRequest.newBuilder() .addModule(MODULE_NAME) .build() manager.startInstall(request)
  4. Dynamic Delivery val listener = SplitInstallStateUpdatedListener { state -> when

    (state.status()) { // ... SplitInstallSessionStatus.REQUIRES_USER_CONFIRMATION -> { // ダウロード確認ダイアログを表示 startIntentSender( state.resolutionIntent()?.intentSender, null, 0, 0, 0) } } } // 登録 manager.registerListener(listener) // 登録解除 manager.unregisterListener(listener)
  5. Dynamic Delivery •モジュールダウンロード後にアクセスするには
 SplitCompat Libraryが必要 <application … android:name="com.google.android.play.core.splitcompat.SplitCompatApplication"> </application> class

    FeatureActivity : AppCompatActivity() { override fun attachBaseContext(newBase: Context?) { super.attachBaseContext(newBase) SplitCompat.install(this) } }
  6. bundletool $ bundletool build-apks \ --bundle=app.aab \ --output=app.apks \ --ks=release.keystore

    \ --ks-pass=pass:sample \ --ks-key-alias=sample \ --key-pass=pass:sample \ --mode=universal # モジュールをすべて含めるオプション $ unzip app.apks # universal.apkが作られる ※universalは <dist:fusing dist:include=“false”/> は含めない