by Rahul Chowdhury
通過拉胡爾·喬杜里
要記住的Facepalm:我在未先測試SDK的情況下對其進行了改進。 (A Facepalm to Remember: I bumped up the version of an SDK without testing it first.)
It all started when Google made its App Shortcuts API available for developers on Android. I was super excited to add this to my hash tagging Android app, Magnify. So I started digging through their documentation for steps to implement it.
一切始于Google向Android開發人員提供其App Shortcuts API時。 我很高興將其添加到我的哈希標記Android應用Magnify中 。 因此,我開始仔細閱讀他們的文檔 ,以了解實施該文檔的步驟。
The first thing I noticed was the required API version for Android targetSdkVersion
was higher than what I was using. “No big deal,” I thought. And I bumped it up to a newer version.
我注意到的第一件事是Android targetSdkVersion
所需的API版本高于我所使用的API版本。 “沒什么大不了的,”我想。 我將其升級到了新版本。
錯誤” (The “Mistake”)
Bumping up my SDK version wasn’t a mistake. The mistake was that I didn’t test the app extensively on the latest version of Android. I just added the shortcut feature, tested that out thoroughly, then pushed my changes — without realizing that a major API change had been made to this new version of the SDK.
提高我的SDK版本并不是一個錯誤。 錯誤是我沒有在最新版本的Android上進行廣泛的測試。 我只是添加了快捷方式功能,對其進行了全面測試,然后推送了更改-但沒有意識到對這個新版本的SDK進行了重大的API更改。
Android Nougat enforces a check on the scope of files shared across apps in the system. If you try to share a file that is saved within the scope of your app with some external app using the traditional file://
approach, your app will hit a FileUriExposedException
, causing your app to bring up that ugly crash dialog that no developer — and certainly no user — wants to ever see.
Android Nougat會強制檢查系統中各個應用之間共享的文件范圍。 如果您嘗試使用傳統的file://
方法與某些外部應用程序共享保存在應用程序范圍內的file://
,則您的應用程序將遇到FileUriExposedException
,從而導致您的應用程序顯示出一個丑陋的崩潰對話框,沒有開發人員可以打開該對話框肯定沒有用戶-想要見識。
How I fixed this exception is beyond the scope of this article. Instead let me share how this one silly mistake affected my app.
我如何解決此異常超出了本文的范圍。 相反,讓我分享這個愚蠢的錯誤如何影響我的應用程序。
問題” (The “Problem”)
Before, when I targeted Android Marshmallow users, my app always managed to sneak out through that hidden door known as “compatibility mode” when running on Nougat. So I was totally chilled out knowing that my app ran fine on the latest version of the OS.
以前,當我以Android Marshmallow用戶為目標時,我的應用程序在Nougat上運行時,總是設法通過被稱為“兼容模式”的隱藏門偷偷溜走。 因此,當我知道我的應用程序在最新版本的操作系統上運行良好時,我感到非常激動。
android { defaultConfig { minSdkVersion 18 targetSdkVersion 23 //Targeting Marshmallow }}
But now things were slightly different for my poor little app. Since it said that it was targeting the latest version of Android, the OS assumed that it had been tested well for all new API updates, and should be punished for any violations. In my case, this was FileUriExposedException
, as I was sharing photos using the traditional file://
approach instead of upgrading to a safe and robust solution.
但是現在對于我可憐的小應用程序來說,情況有所不同。 由于它說的是針對最新版本的Android的操作系統,因此該操作系統假定它已經針對所有新的API更新進行了良好的測試,并應就任何違規行為受到懲罰。 就我而言,這是FileUriExposedException
,因為我使用傳統的file://
方法共享照片,而不是升級到安全可靠的解決方案。
android { defaultConfig { minSdkVersion 18 targetSdkVersion 25 //Targeting Nougat 7.1 }}
The ultimate penalty? “Unfortunately, Magnify has stopped working.”
終極懲罰? “很遺憾,Magnify已停止工作。 ”
“更大的問題” (The “Bigger Problem”)
Though the crash was a serious problem itself, I had yet to discover an even bigger problem. Since Android Nougat was only available to around 0.6% Android phone users at that time — and to around 2–3% of people using my app — this was a crash that could have been hidden for weeks.
盡管墜機本身是一個嚴重的問題,但我還沒有發現更大的問題。 由于當時只有約0.6%的Android手機用戶以及大約2-3%的使用我的應用的用戶可以使用Android Nougat,因此該崩潰本可以隱藏數周。
Fortunately, one of my app users had a Google Pixel running Nougat, and it was she who brought to my attention that the app was broken. I patched it up and rolled out another update with the fix to this crash, which thankfully most users were unaware of, as I was notified of the issue within a day or two.
幸運的是,我的一個應用程序用戶有一個運行Nougat的Google Pixel,正是她引起了我的注意,該應用程序已損壞。 我對其進行了修補,并針對此崩潰修復了問題并發布了另一個更新,但值得慶幸的是,由于一兩天內收到有關此問題的通知,大多數用戶沒有意識到這一點。
Phew! That was really really close.
! 那真的非常接近。
我該如何解決? (How did I solve it?)
Yeah yeah, I said that I won’t be getting deep into solving the problem, but it’s kind of hard for me to watch a fellow developer struggle on the same problem I had, knowing that I could have helped and added some happy moments to their life.
是的,我說我不會深入解決問題,但是我很難看著開發人員在我遇到的同樣問題上苦苦掙扎,因為知道我本可以提供幫助并給他們增加一些快樂的時光他們的生活。
Here’s how I did it:
這是我的做法:
file:// scheme is now not allowed to be attached with Intent on targetSdkVersion 24 (Android Nougat…Android Nougat is almost be publicly released. And as an Android developer, we need to prepare ourself to adjust…inthecheesefactory.com
現在不允許將file://方案與??Intent一起附加在targetSdkVersion 24(Android牛軋糖上。Android牛軋 糖幾乎已公開發布。作為Android開發人員,我們需要做好自我調整的準備... inthecheesefactory.com
故事的道德啟示 (Moral of the story)
Never ever — and I repeat never ever — roll out an update to your software without very, very extensive testing when you have bumped up the version of your SDK. Chances are there are some API changes you were unaware of — some of which might break your software for good.
當您提高SDK版本的功能時,再也不會,而且我也永遠不會重復-對軟件進行更新,而無需進行非常非常廣泛的測試。 您可能沒有意識到某些API更改,其中一些可能永久破壞了您的軟件。
Make sure you ship your updates only after proper testing. A little time spent testing can save a lot of time getting back the trust of your users.
確保僅在經過適當測試后才發布更新。 花一點時間進行測試可以節省大量時間來恢復用戶的信任。
Oh, and:
哦,還有:
There are no mistakes, save one: the failure to learn from a mistake. — Robert Fripp
除了一個錯誤,沒有錯誤:沒有從錯誤中學習。 —羅伯特·弗里普
Because you don’t end a dope article without a kickass quote. ? ??
因為您不會在沒有kickass引號的情況下結束濃湯文章。 ? ??
If you enjoyed this story, please do recommend it to other people by hitting the ? button on this page, and follow me for more stories about programming.
如果您喜歡這個故事,請通過點擊來將其推薦給其他人。 按鈕,然后關注我以了解有關編程的更多故事。
翻譯自: https://www.freecodecamp.org/news/a-facepalm-to-remember-i-bumped-up-the-version-of-an-sdk-without-testing-it-first-acb16da33d41/