使用 packagingOptions 移除第三方 SDK 中的檔案

Pony Chen
Pony Chen
Feb 23, 2017 · 2 min read

前陣子公司專案需要用到 Google VR SDK for Android,但在加入了這個 SDK 之後,一打開 app 即出現 UnsatisfiedLinkedError。主要的原因是,我們之前因為別的 SDK 只提供 32 bits 的 so file,為了避免在 64 bits 的機器上發生找不到 so 的狀況發生,我們只好把全部的 64 bits so 移除掉。但 Google VR SDK 內包含 arm64-v8a 的檔案:

因此我們需要在 gradle 內設定,讓他打包時不要跟著把不需要的檔案放進來,可以使用 packagingOptions 來辦到,作法如下:

android {
...
...
packagingOptions{
exclude 'lib/arm64-v8a/libpano_video_renderer.so'
}
}

這樣就能讓系統去找到正確的資料夾了。

參考資料:

[1] https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade