[Android] Vungle 升級 6.7.0 紀錄

在檸檬爸的專案裡面有使用到 Vungle 的廣告技術,從 2020 年初之後,就不斷收到 Vungle 寄的升級信如下,主要是因為專案中使用的 Vungle’s SDK Version 6.4 已經不會在繼續符合 Google 的政策,所以不斷催促要求升級,甚至在超過期限之後 Google 會直接把應用程式下架!本篇升級 Vungle 升級 6.7.0 紀錄思考與執行過程。

Vungle 來信內容:

Hi,

We’ve worked with Google to provide a clarification of the message sent on June 23, 2020 regarding Vungle‘s SDKs Version 6.4 and below’s compliance with Google policy.

The language that was referenced in the Google notification might have suggested that our SDK was acting in a way that is deceptive or harmful to our partners, customers, or your users. Rest assured that is not the case. Vungle takes privacy, data, and platform policies very seriously — we understand that this is one of the major reasons you partner with us.

Vungle SDK versions 6.4 and below are being flagged as non-compliant due to a legacy feature called “Sideloading.” The Sideloading functionality exists in legacy SDK versions 6.2 – 6.4, and allows users in China (and ONLY users in China where the Google Play store is not available) to download apps. The Google team has taken the position that this functionality is no longer compliant as they do not allow “installation of applications from unknown sources outside the Google Play store” and as such, we have removed this functionality from SDK 6.5 and above. We have worked closely with the Google team to develop and promote the adoption of our newest SDK versions once we learned of Google’s determination.

We feel it is important to clarify that this is the sole reason your app has been flagged and not due to any harmful behavior around data usage and privacy as may have been implied.

The action Google requires is for you to upgrade your apps to Vungle SDK 6.5+ before July 24, 2020. You may receive another notification from Google to remind you to upgrade if you have not done so already — you will need to upgrade all tracks. You can find our latest Android SDK versions with their adapters in our help center and linked below.

The Vungle team has been working closely with Google on this issue and we apologize that the notification suggested that the Vungle SDK was acting in a way that may have caused confusion or alarm.

Please reach out to tech-support@vungle.com if you have any questions.

Your Vungle Team

升級前準備

根據 Vungle Android SDK 的教學要升級 Vungle 看似只要簡單加入以下的 implementation 到 Gradle 就可以了,但是事情沒有想像中的那麼簡單。 

dependencies {
    implementation 'com.vungle:publisher-sdk-android:6.7.1'
    implementation 'androidx.core:core:1.3.1'
    implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
}

由於筆者的程式原本是使用 com.android.support 的函式庫,這些函式庫與 vungle 6.5+ 中使用的 androidX 會產生衝突:

implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'

以下筆者列出主要的錯誤訊息:

Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules classes.jar (androidx.core:core:1.1.0) and classes.jar (com.android.support:support-compat:27.1.1)

Go to the documentation to learn how to Fix dependency resolution errors.

為什麼會有這些錯誤訊息呢?這邊就要提到官網說到 AndroidX 被開發出來的原因:

AndroidX is a major improvement to the original Android Support Library, which is no longer maintained. androidx packages fully replace the Support Library by providing feature parity and new libraries.

最主要的原因是因為原本 android.support 的函式庫因為版本數眾多過於混亂所以提出一個統整型的函式庫來處理。

升級流程:

由以上初步測試我們能夠發現,直接升級 Vungle 6.4.11 到 Vungle 6.7.0 是行不通的,由於 AndroidX 是開發來取代 android support 的功能的,所以要能夠成功升級到 Vungle 6.7.0 勢必要先升級到 AndroidX。關於升級可以參考連結,幾個必要條件才能夠升級:

  1. AndroidStudio 3.2 以上的環境
  2. targetSdkVersion 需是 28 (android 9.0) 以上
  3. classpath 中 Gradle 的版本需要在 3.2.0 以上 ‘com.android.tools.build:gradle:3.2.0’ 

在啟動 Android Studio 中,Refactor -> Migrate to AndroidX 之後,會發現很多原本依賴的類別都被自動更改了,以下我們列出起個被更改的 Class。

Vungle 升級 6.7.0 紀錄
更改前
更改後
android.support.annotation.NonNull androidx.annotation.NonNull
android.support.multidex.MultiDexApplication androidx.multidex.MultiDexApplication
android.support.v7.app.AppCompatActivity androidx.appcompat.app.AppCompatActivity
android.support.v4.view.ViewPager androidx.viewpager.widget.ViewPager
android.support.v7.widget.RecyclerView androidx.recyclerview.widget.RecyclerView
android.support.annotation.Nullable androidx.annotation.Nullable
android.support.v4.app.Fragment androidx.fragment.app.Fragment
android.support.v4.util.Pair androidx.core.util.Pair
android.support.v7.widget.Toolbar androidx.widget.Toolbar
升級 Vungle

成功升級完 AndroidX 之後,就可以在 build.gradle 中將 vungle 升級到 6.7.0 的版本了,Vungle 的類別有些許的改變例如 (com.vungle.warren.Vungle),但是變化不大,所以稍微修改即可!

其他 Android 文章

歡迎參考其他關於 Android 開發的文章