phrase / phrase-android

Phrase Over the Air Android SDK
https://phrase.com
Other
6 stars 1 forks source link

Cannot update translation ota in Android #72

Open AndroidDeveloperEob opened 2 months ago

AndroidDeveloperEob commented 2 months ago

last working version: 3.1.6 Implementation in Application (3.1.6):

  Phrase.setup(
            this,
            BuildConfig.PHRASE_DISTRIBUTION_ID,
            BuildConfig.PHRASE_SECRET,
            storeLocale
        )
      getCoreSemanticAppVersion()?.let {
            Phrase.setAppVersion(it)
        } ?: ExceptionReporter.logException(
            IllegalStateException("Invalid app version. Cannot get core semantic app version")
        )
        Phrase.updateTranslations()

tested versions from 3.5.0 to 3.10.0-rc2 Previous implementation not working:

  Phrase.setup(
            this,
            BuildConfig.PHRASE_DISTRIBUTION_ID,
            BuildConfig.PHRASE_SECRET,
            storeLocale
        )
        getCoreSemanticAppVersion()?.let {
            Phrase.setAppVersion(it)
        } ?: ExceptionReporter.logException(
            IllegalStateException("Invalid app version. Cannot get core semantic app version")
        )
        Phrase.updateTranslations()

New implementation from 3.7.0:

        Phrase.setup(
            this,
            BuildConfig.PHRASE_DISTRIBUTION_ID,
            BuildConfig.PHRASE_SECRET,
            storeLocale
        )
        getCoreSemanticAppVersion()?.let {
            Phrase.setAppVersion(it)
        } ?: ExceptionReporter.logException(
            IllegalStateException("Invalid app version. Cannot get core semantic app version")
        )
        Phrase.updateTranslations(object : TranslationsSyncCallback {
            override fun onSuccess(translationsChanged: Boolean) {
                if (translationsChanged) {
                    Phrase.applyPendingUpdate()
                }
            }

            override fun onFailure() {
                ExceptionReporter.logException(IllegalStateException("Failed to update translations"))
            }
        })

Ends with calling onFailure() Errors (2 types):

Could you tell me why Phrase.updateTranslations() stopped working and we can call it in code? How can I fix the issue with not updating Strings (after resetting app translations does not update Errors related to No such file or directory).

hahmed-dev commented 2 months ago

Hi @AndroidDeveloperEob , thanks for sharing all the details, if I understand correctly, translations were being updated as expected in version 3.1.6 and failure to update translations was observed only after 3.5.0?

AndroidDeveloperEob commented 2 months ago

Yes, That is the correct understanding.

hahmed-dev commented 2 months ago

Thanks, I will check and get back to see what could have caused this behaviour for you.

hahmed-dev commented 2 months ago

Hi @AndroidDeveloperEob , the timeout error

Error(e=kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 700 ms) this error occurs when changing from Phrase.updateTranslations() to Phrase.updateTranslations with listener and running an app

It occurs when fetching translations takes longer than 700 ms. Although in the latest candidate release 3.10.0-rc2 there are changes to further optimise the time it takes to fetch translations, I had a couple of questions around that:

Further more you can enable Debug log level by following the instructions provided here

AndroidDeveloperEob commented 2 months ago

did you face the timeout issue on this version (3.10.0-rc2) as well? <-yes, mostly TimeoutCancellaionException could you give a rough estimate how many keys are being fetched, if it could be a factor in request taking too much time (1000 keys + values) x 22 (languages)

Do you have any specific test flow that I should follow for retrieving logs? (First run, clean start, etc) ?

hahmed-dev commented 2 months ago

The usual flow of triggering translation update should give some additional information around translations being fetched and their storage in the cache.

AndroidDeveloperEob commented 2 months ago

Stacktracet:

2024-06-14 09:16:28.973 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            I  Initializing Phrase SDK 3.9.0
2024-06-14 09:16:28.980 12987-13045 Phrase OTA              pl.eobuwie.eobuwieapp.dev            E  Reading cached Translation failed: No cached file /data/user/0/pl.eobuwie.eobuwieapp.dev/files/.phrase_cache/887f557a173965e68714964b74b068b3185327d23d7343c1fb0ce7bae12e8308df9137538f52303cacc1924f37a94812115a856fac557a654f9ca1319b840d89.xml present
2024-06-14 09:16:28.992 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Setting custom Application Version: 2.37.0
2024-06-14 09:16:29.022 12987-13140 Phrase OTA              pl.eobuwie.eobuwieapp.dev            I  Fetching Translations: https://ota.phraseapp.com/49a2c5f89196b5a22ffa958c947218b8/8Y7hQFQ6Zz9ii32XH7nZEqgLFWegMXINODulaKG1F1U/pl_PL/xml?client=android&unique_identifier=secret&sdk_version=3.9.0&app_version=2.37.0
2024-06-14 09:16:30.600 12987-13140 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Downloading Translations to File: /data/user/0/pl.eobuwie.eobuwieapp.dev/cache/.phrase_cache/tmp-locale-8755835356314630555.xml
2024-06-14 09:16:30.967 12987-13140 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Writing Translations to Locale Cache: /data/user/0/pl.eobuwie.eobuwieapp.dev/files/.phrase_cache/887f557a173965e68714964b74b068b3185327d23d7343c1fb0ce7bae12e8308df9137538f52303cacc1924f37a94812115a856fac557a654f9ca1319b840d89.xml
2024-06-14 09:16:30.968 12987-13045 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Reading cached Translations for: pl_PL (887f557a173965e68714964b74b068b3185327d23d7343c1fb0ce7bae12e8308df9137538f52303cacc1924f37a94812115a856fac557a654f9ca1319b840d89)
2024-06-14 09:16:31.156 12987-13046 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Parsed cached Translations in 0.186s
2024-06-14 09:16:31.158 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Store Translations Version 347 for pl_PL (887f557a173965e68714964b74b068b3185327d23d7343c1fb0ce7bae12e8308df9137538f52303cacc1924f37a94812115a856fac557a654f9ca1319b840d89)
2024-06-14 09:16:31.158 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            I  Loading pending update for: pl_PL (887f557a173965e68714964b74b068b3185327d23d7343c1fb0ce7bae12e8308df9137538f52303cacc1924f37a94812115a856fac557a654f9ca1319b840d89)
2024-06-14 09:16:31.159 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Reusing Locale Cache for: pl_PL (887f557a173965e68714964b74b068b3185327d23d7343c1fb0ce7bae12e8308df9137538f52303cacc1924f37a94812115a856fac557a654f9ca1319b840d89)
2024-06-14 09:16:31.159 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Set TranslationRepository for: pl_PL (887f557a173965e68714964b74b068b3185327d23d7343c1fb0ce7bae12e8308df9137538f52303cacc1924f37a94812115a856fac557a654f9ca1319b840d89)
2024-06-14 09:16:46.576 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Creating Delegate for: pl.eobuwie.eobuwieapp.MainActivity@b3a2cc9
2024-06-14 09:16:46.586 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Create Context Wrapper for: androidx.appcompat.view.ContextThemeWrapper@e2e6dfc
2024-06-14 09:16:46.590 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Setting default Locale Code: en_US
2024-06-14 09:16:46.590 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Locale "pl_PL" did not change, skipping update
2024-06-14 09:16:51.579 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Setting custom Locale Code: el_GR
2024-06-14 09:16:51.580 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Locale changed: el_GR
2024-06-14 09:16:51.590 12987-13267 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Reading cached Translations for: el_GR (fdcfd7cfc578761270ee76ffb18b1c2ed6894265e2a20f577363d4d6417e527d1fdaf698012999f35f01bd436461fc150d92ba49c6b9ee8f7a7307cc4789969e)
2024-06-14 09:16:51.594 12987-13267 Phrase OTA              pl.eobuwie.eobuwieapp.dev            E  Reading cached Translation failed: No cached file /data/user/0/pl.eobuwie.eobuwieapp.dev/files/.phrase_cache/fdcfd7cfc578761270ee76ffb18b1c2ed6894265e2a20f577363d4d6417e527d1fdaf698012999f35f01bd436461fc150d92ba49c6b9ee8f7a7307cc4789969e.xml present
2024-06-14 09:16:51.595 12987-12987 Phrase OTA              pl.eobuwie.eobuwieapp.dev            D  Reset TranslationRepository for: el_GR (fdcfd7cfc578761270ee76ffb18b1c2ed6894265e2a20f577363d4d6417e527d1fdaf698012999f35f01bd436461fc150d92ba49c6b9ee8f7a7307cc4789969e)
2024-06-14 09:16:51.596 12987-13140 Phrase OTA              pl.eobuwie.eobuwieapp.dev            I  Fetching Translations: https://ota.phraseapp.com/49a2c5f89196b5a22ffa958c947218b8/8Y7hQFQ6Zz9ii32XH7nZEqgLFWegMXINODulaKG1F1U/el_GR/xml?client=android&unique_identifier=secret&sdk_version=3.9.0&last_update=1718349391&app_version=2.37.0
2024-06-14 09:16:52.035 12987-13140 Phrase OTA              pl.eobuwie.eobuwieapp.dev            E  Fetching Translations failed
                                                                                                    java.io.IOException: No such file or directory
                                                                                                        at java.io.UnixFileSystem.createFileExclusively0(Native Method)
                                                                                                        at java.io.UnixFileSystem.createFileExclusively(UnixFileSystem.java:349)
                                                                                                        at java.io.File.createTempFile(File.java:2007)
                                                                                                        at com.phrase.android.sdk.repo.PhraseDiskCache.put(SourceFile:1)
                                                                                                        at com.phrase.android.sdk.repo.PhraseApi.fetchLocale$sdk_release(SourceFile:55)
                                                                                                        at com.phrase.android.sdk.PhraseImpl.a(SourceFile:9)
                                                                                                        at com.phrase.android.sdk.PhraseImpl$$ExternalSyntheticLambda0.run(D8$$SyntheticClass:0)
                                                                                                        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
                                                                                                        at java.util.concurrent.FutureTask.run(FutureTask.java:264)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                        at java.lang.Thread.run(Thread.java:1012)
hahmed-dev commented 2 months ago

Thank you for sharing the logs @AndroidDeveloperEob will look into this and get back to you.

hahmed-dev commented 2 months ago

@AndroidDeveloperEob while we are investigating this internally, the logs shared state SDK version 3.9.0

2024-06-14 09:16:51.596 12987-13140 Phrase OTA              pl.eobuwie.eobuwieapp.dev            I  Fetching Translations: https://ota.phraseapp.com/49a2c5f89196b5a22ffa958c947218b8/8Y7hQFQ6Zz9ii32XH7nZEqgLFWegMXINODulaKG1F1U/el_GR/xml?client=android&unique_identifier=secret&sdk_version=3.9.0&last_update=1718349391&app_version=2.37.0

sdk_version=3.9.0

Just to confirm once again with 3.10.0-rc2 also results in the exact same exception? i.e. Fetching Translations failed