Pro Yearly is on sale from $80 to $50! »

in-app updates on Android - Overview & Fitfalls -

2ddbd112dbc8c6572fe79821584c1465?s=47 Kurun
November 11, 2019

in-app updates on Android - Overview & Fitfalls -

2ddbd112dbc8c6572fe79821584c1465?s=128

Kurun

November 11, 2019
Tweet

Transcript

  1. in-app updates on Android - Overview & Fitfalls - potatotips

    #66 (2019/11/11) @kurun_pan
  2. • potatotipsࢀՃ2ճ໨ʢલճͷ#65͕ॳࢀՃʣ • ຊۀ ‣ Linux Software Engineer ‣ ϑϧελοΫΤϯδχΞ

    ✓ Linux kernel, Driver, Middleware, Applicationͳ ͲඞཁͳΒԿͰ΋ ✓ ࠷ۙ͸GUIϑϨʔϜϫʔΫؔ࿈ • ϓϥΠϕʔτ ‣ ओʹAndroidΞϓϦΛ։ൃ Self-introduction @kurun_pan @Kurun-pan
  3. • In-app updates overview • Updates flow type • Sample

    code • Pitfall points • Summary Agenda
  4. • ʙ2017ɹಠࣗ ‣ ΞϓϦىಈ࣌ʹGoogle PlayετΞʢWebʣ͔Β৘ใΛऔಘ ‣ PackageManagerͰऔಘͨ͠όʔδϣϯ৘ใͱൺֱ ‣ ৽͍͠όʔδϣϯ͕͋Ε͹ɺμΠΞϩάͰϢʔβʹ௨஌ ‣

    Ϣʔβ͕ڐ୚͢Ε͹ɺGoogle PlayετΞΞϓϦʹϦϯΫ • ʙ2019/9ɹFirebase Remote ConfigΛར༻ ‣ ΞϓϦىಈ࣌ʹRemote ConfigͰ࠷৽όʔδϣϯΛऔಘ ✓ ࠷৽όʔδϣϯ͸PlayετΞʹ൓өޙʹखಈͰઃఆ ‣ ͦΕҎ֎͸ɺجຊతʹ্هͱಉ͡ How to notify new updates to user so far
  5. • Google PlayετΞΞϓϦͰ͸ͳ͘ɺࣗΞϓϦ಺ͰΞοϓσʔτՄೳ ‣ ߋ৽ݕ஌, μ΢ϯϩʔυ, Πϯετʔϧ·ͰશͯରԠ ‣ Play Core

    ( com.google.android.play:core ) ϥΠϒϥϦͰఏڙ ‣ AOSPͰ͸ͳ͍ͷͰɺιʔείʔυ͸ӾཡෆՄʢͳ͸ͣ…ʣ • ྺ࢙ ‣ 2018/11 Google Dev SummitͰൃදɺϕʔλ൛ϦϦʔε ‣ 2019/5 Google IOͰਖ਼ࣜ൛ϦϦʔε In-app updates overview
  6. 2छྨͷΞοϓσʔτϑϩʔ͕બ୒Մೳ Updates flow 'MFYJCMF *NNFEJBUF 6* ΞϓϦฒྻಈ࡞ μ΢ϯϩʔυத͸ΞϓϦར༻Մೳ جຊతʹ͸ෆՄ Ξοϓσʔτ

    Ϣʔβ͕ڋ൱Մೳ ڧ੍ʁ ˞ͨͩ͠ɺӈ্✖Ϙλϯ໭ΔϘλϯͰεΩοϓՄೳʜ
  7. Flexible flow WiFi઀ଓ࣌ ϞόΠϧ௨৴઀ଓ࣌ ৽͍͠ ߋ৽͋Γ μ΢ϯϩʔυ ׬ྃ μ΢ϯϩʔυ։࢝ Ϣʔβ

    ֬ೝ YES NO μ΢ϯϩʔυ׬ྃˍ Πϯετʔϧ։࢝ͷ௨஌ Ϣʔβ֬ೝ YES NO Πϯετʔϧ׬ྃޙɺࣗಈͰΞϓϦ࠶ىಈ YES YES NO ͜ͷঢ়ଶ͔ΒɺGoogle PlayετΞͰී௨ʹΞϓϦߋ৽΋Մೳɻ Google PlayετΞͰߋ৽தʹΞϓϦىಈͨ͠৔߹ʹͲ͏ͳΔ͔ʁͳͲɺؾʹͳΔ఺΋ɻ ※ΞϓϦ಺Ͱμ΢ϯϩʔυͨ͠σʔλ͸ར༻ͤͣɺ࠶౓μ΢ϯϩʔυ͔Β։࢝͞ΕΔ༷ࢠ NO
  8. Immediate flow WiFi઀ଓ࣌ ϞόΠϧ௨৴઀ଓ࣌ ৽͍͠ ߋ৽͋Γ ×Ϙλϯ/໭ΔϘλϯ͕ԡ͞Εͨ৔߹ Πϯετʔϧ׬ྃޙɺࣗಈͰΞϓϦ࠶ىಈ YES Wifi઀ଓ଴ͪ

    μ΢ϯϩʔυ։࢝ Wi-Fi ઀ଓ࣌ʹ μ΢ϯϩʔυ NO WiFi઀ଓ׬ྃ YES NO WiFi઀ଓ͔ͭ ߋ৽Ϙλϯ͕ ԡ͞Εͨ μ΢ϯϩʔυ׬ྃ μ΢ϯϩʔυը໘Ͱ͜ͷը໘Λดͨ͡Βɺ ͦͷޙͷϑϩʔ͸Flexibleͱಉ͡ʹͳΓ·͢
  9. Sample code • ࣌ؒͷؔ܎Ͱ࣮૷ྫ͸ׂѪ͠·͢ • αϯϓϧίʔυˣΛ࡞੒͓͖ͯ͠·ͨ͠ ‣ ಛʹ೉͍͜͠ͱ͸ͳ͘ɺ΄΅άάͬͯग़ͯ͘Δ৘ใͰ࡞Ε·͢ • αϯϓϧίʔυ

    ‣ https://github.com/Kurun-pan/android-in-app-updates-sample/ blob/master/app/src/main/java/com/example/ in_app_updates_sample/MainActivity.kt
  10. Pitfall points No.1 val appUpdateInfoTask = appUpdateManager.appUpdateInfo appUpdateInfoTask.addOnSuccessListener { appUpdateInfo

    -> when (appUpdateInfo.updateAvailability()) { UpdateAvailability.UPDATE_AVAILABLE -> { val updateTypes = arrayOf(AppUpdateType.FLEXIBLE, AppUpdateType.IMMEDIATE) run loop@{ updateTypes.forEach { type -> if (appUpdateInfo.isUpdateTypeAllowed(type)) { appUpdateManager.startUpdateFlowForResult(appUpdateInfo, type, this, REQUEST_UPDATE_CODE) return@loop } } } } else -> { Log.d(TAG, "updateAvailability = " + appUpdateInfo.updateAvailability()) } } } • In-app update API͸ɺجຊGoogle Play ετΞΞϓϦͱͷ௨৴APIͩͱߟ͑ͯྑ͍ • ΫϩʔζυͳϦϦʔεͰ΋େৎ෉ͳͷ ͰɺετΞͰ഑৴ˍΠϯετʔϧޙ͔Β ػೳ ‣ Google PlayετΞ͕ΞϓϦߋ৽Λೝࣝ ͯ͘͠ΕΔ͜ͱ͕ඞཁ Կ౓΍ͬͯ΋updateAvailability͕UPDATE_NOT_AVAILABLE͔͠དྷͳ͍ → FakeAppUpdateManagerར༻΋͘͠͸ɺԿΒ͔ͷܗͰPlayετΞʹϦϦʔεඞཁ PlayετΞʹ͋Δ࠷৽όʔδϣϯίʔυ͕10ͳΒɺ σόοά࣌ͷόʔδϣϯίʔυΛ9ҎԼʹ͓͚ͯ͠ ͹ɺUPDATE_AVAILABLE͕ؼͬͯ͘ΔͷͰ͸ʁ →ࢥ͍ࠐΈʢؒҧ͍ʣ
  11. Unit test code sample ςετ༻ͱͯ͠ɺFakeAppUpdateManager͕༻ҙ͞Ε͍ͯ·͢ ͳ͓ɺFakeAppUpdateManager͸Ͳ͏ؤுͬͯ΋࣮ࡍͷUIදࣔ͸͞Ε·ͤΜ @Test fun test_FlexibleUpdateSuccess() {

    fakeAppUpdateManager.partiallyAllowedUpdateType = AppUpdateType.FLEXIBLE fakeAppUpdateManager.setUpdateAvailable(10) ActivityScenario.launch(MainActivity::class.java) assertTrue(fakeAppUpdateManager.isConfirmationDialogVisible) fakeAppUpdateManager.userAcceptsUpdate() fakeAppUpdateManager.downloadStarts() fakeAppUpdateManager.downloadCompletes() Espresso.onView( allOf( isDescendantOfA(instanceOf(Snackbar.SnackbarLayout::class.java)), instanceOf(AppCompatButton::class.java) ) ).perform(ViewActions.click()) assertTrue(fakeAppUpdateManager.isInstallSplashScreenVisible) fakeAppUpdateManager.installCompletes() } ←ɹڐՄ͢ΔΞοϓσʔτϑϩʔΛࢦఆ ←ɹ৽͍͠ߋ৽ͷόʔδϣϯίʔυΛࢦఆ ←ɹϢʔβૢ࡞ɿߋ৽ϘλϯΛԡ͢ ←ɹγεςϜಈ࡞ɿμ΢ϯϩʔυ։࢝ ←ɹγεςϜૢ࡞ɿμ΢ϯϩʔυ׬ྃ ←ɹγεςϜૢ࡞ɿΠϯετʔϧ׬ྃ ςεταϯϓϧ ←ɹϢʔβૢ࡞ɿΠϯετʔϧˍϦελʔτOK https://github.com/Kurun-pan/android-in-app-updates-sample/blob/master/app/src/androidTest/java/com/example/in_app_updates_sample/MainActivityTest.kt
  12. Pitfall points No.2 Google PlayετΞΞϓϦͷߋ৽ݕ஌ΞϧΰϦζϜ(Ωϟογϡߋ৽λΠϛϯά)͕ෆ໌ ※Google PlayετΞ΁ͷϦϦʔε൓ө׬ྃλΠϛϯάͱ͸ҟͳΔ ΞοϓσʔτҎ֎ͷλϒ΍ΞϓϦͷ ϖʔδͰߋ৽Λೝ͍ࣝͯ͠Δ͚ͩͰ ͸ɺUPDATE_NOT_AVAILABLE

    ͜ͷλϒʹϦετΞοϓ͞ΕͨΒɺ UPDATE_AVAILABLE NG OK ΞοϓσʔτλϒʢΞοϓσʔτอཹதʣʹϦετΞοϓ͞Εͳ͍৔߹ͷରॲํ๏ ɹɾGoogle PlayετΞΞϓϦΛ׬શʹऴྃ ( KILL ) ͯ͠ɺ࠶౓্ཱͪ͛Δ ɹɾ΋͘͠͸ɺઃఆ > ετϨʔδ > ͦͷଞͷΞϓϦ > Google Play ετΞͰΩϟογϡ࡟আ
  13. Pitfall points No.3 Google PlayετΞΞϓϦͷςʔϚͷμʔΫϞʔυ͕൓ө͞Ε͍ͯΔʢ༷ʹݟ͑Δʣ ։ൃऀ͕ࣗΞϓϦͷσβΠϯʹ߹ΘͤͯΧελϚΠζՄೳʁ จࣈ͕ݟ͑ਏ͍

  14. Summary • Firebase Remote ConfigΛར༻ͨ͠ํ๏͔Βɺ؆୯ʹΞϓϦ಺ߋ৽ʹҠߦͰ͖ͨ ‣ ৽όʔδϣϯϦϦʔεຖʹRemote Configͷ஋Λมߋ͢Δඞཁ͕ͳָͯ͘ ‣ ӡ༻తʹ΋ࠓͷͱ͜Ζಛʹ໰୊ͳͦ͞͏

    • ඍົͳ఺ ‣ Google PlayετΞΞϓϦ͕Πϯετʔϧ͞Ε͍ͯͳ͍தࠃͳͲΛߟ͑Δͱඍົ͔΋ ✓ ͦ΋ͦ΋ͷಈ͖͕Ͳ͏ͳΔʁ ‣ Immediateϑϩʔ͸ɺ໭ΔϘλϯͰ؆୯ʹը໘͕ফͤΔ ‣ ΞϓϦͷσβΠϯʹΑͬͯ͸ɺμʔΫϞʔυ࣌ʹҧ࿨ײ͕ग़ͯ͘Δ͔΋ • Qiitaʹ΋هࣄΛॻ͖·ͨ͠ʢࠓճઆ໌͍ͯ͠ͳ͍ίʔυͷղઆ΋͋Γʣ ‣ https://qiita.com/kurun_pan/items/0e4d916d106f64942195