การแก้ไขข้อขัดแย้งของ Google Play Services
ปลั๊กอินต่างๆ สำหรับเฟรมเวิร์กที่แตกต่างกันอาจใช้ไลบรารี google-play-services เวอร์ชันที่แตกต่างกัน ซึ่งทำให้โปรเจกต์ของคุณไม่สามารถคอมไพล์หรือเกิดข้อผิดพลาดได้เนื่องจากเวอร์ชันของไลบรารีล้าสมัย
ส่วนต่อไปนี้จะให้แนวทางแก้ไขสำหรับปลั๊กอินต่างๆ
ตำแหน่งของไลบรารี
Anchor link toคุณสามารถค้นหาไลบรารี Google Play Services ได้ที่ <Android SDK>/extras/google
ไลบรารีมีให้ใช้งานในสองรูปแบบ:
-
ไฟล์ jar แบบ Monolithic (มีส่วนประกอบทั้งหมดของ Google Play Services อยู่ในไฟล์เดียว):
sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar -
ไฟล์ aar แบบ Modular (Android Archive) ซึ่งแต่ละส่วนประกอบจะอยู่ในไฟล์แยกกัน:
sdk/extras/google/m2repository/com/google/android/gms/…
ไฟล์ aar สามารถแยกออกมาเป็นไฟล์ jar ได้ (เนื่องจากไม่ใช่ทุกเฟรมเวิร์กที่รองรับ aar ในขณะนี้) โดยการแตกไฟล์ (aar เป็นไฟล์ zip archive) และนำไฟล์ classes.jar ซึ่งเป็นโค้ดของไลบรารีออกมา
1. Cordova
Anchor link toข้อขัดแย้งทั้งหมดของ google play services บน Cordova จะได้รับการแก้ไขโดยอัตโนมัติโดยใช้ gradle บางครั้ง (เช่น เมื่อปลั๊กอินต่างๆ ใช้ไลบรารีเวอร์ชันหลักที่แตกต่างกัน) การแก้ไขอาจล้มเหลว และอาจมีไลบรารีเดียวกันสองเวอร์ชันที่แตกต่างกันปรากฏในบิลด์ผลลัพธ์
2. Unity, Appcelerator Titanium
Anchor link toคุณสามารถค้นหาไลบรารี Google Play Services ได้ในปลั๊กอิน (หรือโปรเจกต์ตัวอย่าง) ซึ่งง่ายต่อการอัปเดต/เปลี่ยนแปลง/ลบออกเพื่อแก้ไขข้อขัดแย้งที่อาจเกิดขึ้น:
- Unity: https://github.com/Pushwoosh/pushwoosh-unity/tree/master/PushwooshUnitySample/Assets/Plugins/Android
- ปลั๊กอิน Unity และ Google Analytics: ปลั๊กอิน Google analytics ใช้ไลบรารี google play ที่ล้าสมัย ซึ่งจำเป็นต้องได้รับการอัปเดต ข้อมูลเพิ่มเติมที่นี่: https://github.com/Pushwoosh/pushwoosh-unity/issues/5
rm -rf Assets/Plugins/Android/google-play-services_lib/libsrm -rf Assets/Plugins/Android/google-play-services_lib/rescp ${ANDROID_HOME}/extras/google/m2repository/com/google/android/gms/play-services-analytics/8.4.0/play-services-analytics-8.4.0.aar Assets/Plugins/Android/cp ${ANDROID_HOME}/extras/google/m2repository/com/google/android/gms/play-services-ads/8.4.0/play-services-ads-8.4.0.aar Assets/Plugins/Android/- Appcelerator Titanium (โปรดทราบว่าเวอร์ชันของโมดูลอาจเปลี่ยนแปลงเร็วกว่าเอกสารนี้!): https://github.com/Pushwoosh/pushwoosh-appcelerator-titanium/tree/master/Module-Source/android/src/com/pushwoosh/module
3. Adobe Air
Anchor link toนำส่วนขยาย ANE มาแตกไฟล์ แก้ไข และแพ็กเกจใหม่
ใช้ตัวอย่างต่อไปนี้กับ PushNotification.ane:
unzip PushNotification.ane -d tmpคำสั่งนี้จะแตกเนื้อหาของไฟล์ .ane ไปยังไดเรกทอรี tmp
ตอนนี้ใน tmp/META-INF/ANE/Android-ARM/ และ tmp/META-INF/ANE/Android-x86/ คุณจะพบไลบรารีทั้งหมด: android-support_, play-services_ ซึ่งอาจถูกแก้ไข/อัปเดต/ลบออกไปแล้ว
หากคุณยังคงทำตามลิงก์ไปยังเอกสารด้านบน ให้เปลี่ยน tmp/META-INF/ANE/Android-ARM/platform.xml และ tmp/META-INF/ANE/Android-x86/platform.xml จากนั้น zip ส่วนขยายกลับไป และทุกอย่างควรจะทำงานได้ตามปกติ
หากคุณได้รับข้อผิดพลาด:
PushNotification.ane is not a valid native extension file.
แพ็กเกจส่วนขยายใหม่โดยใช้ขั้นตอนต่อไปนี้:
- ลบ
tmp/META-INF/ANE/Android-ARM/platform.xmlและtmp/META-INF/ANE/Android-x86/platform.xml - แก้ไขตามคำแนะนำในลิงก์ด้านบนที่
tmp/META-INF/ANE/Android-ARM/android-depends.xmlและtmp/META-INF/ANE/Android-x86/android-depends.xmlแทน - รันคำสั่ง bash ต่อไปนี้:
#rename platform.xml on iOS, required to repackage the extensionmv tmp/META-INF/ANE/iPhone-ARM/platform.xml tmp/META-INF/ANE/iPhone-ARM/platform-iOS.xml
#pack the extension back with adtcd tmp/META-INF/ANE/“${flex.sdk}/bin/adt" -package -target ane PushNotification.ane extension.xml -swc ../../../../SWC-Pushwoosh/PushNotification.swc -platform iPhone-ARM -platformoptions iPhone-ARM/platform-iOS.xml -C iPhone-ARM/ . -platform Android-ARM -platformoptions Android-ARM/android-depends.xml -C Android-ARM/ . -platform Android-x86 -C Android-x86/ . -platformoptions Android-x86/android-depends.xml -platform default -C default/ .คุณสามารถค้นหา PushNotification.swc ได้ที่นี่: https://github.com/Pushwoosh/pushwoosh-adobe-air/blob/master/SWC-Pushwoosh/PushNotification.swc
4. Unreal Engine
Anchor link toUnreal Engine และ Pushwoosh Plugin มักจะขัดแย้งกันเสมอ ซึ่งอธิบายได้ว่า Unreal Engine มี Google Play services เป็นค่าเริ่มต้น และ Engine เวอร์ชันต่างๆ ก็ใช้ไลบรารีเหล่านี้ในเวอร์ชันที่แตกต่างกัน Pushwoosh plugin ก็ใช้ไลบรารีเหล่านี้เช่นกัน แต่เป็นชุดย่อยที่แตกต่างกัน โปรดใช้ความระมัดระวังเสมอเมื่อรวม Pushwoosh Plugin สำหรับ Unreal Engine แม้ว่าโปรเจกต์ของคุณจะดูเหมือนคอมไพล์และทำงานได้ดี แต่ต้องแน่ใจว่าทั้ง Pushwoosh และ Unreal Engine ใช้ Google Play Services เวอร์ชันเดียวกัน การใช้ google-play-services เวอร์ชันต่างๆ ในโปรเจกต์เดียวจะส่งผลให้เกิดพฤติกรรมที่ไม่สามารถคาดเดาได้
ในการแก้ไขข้อขัดแย้ง คุณควรทำดังต่อไปนี้:
1. ตรวจสอบว่าไลบรารี Google Play services ใดบ้างที่ถูกใช้ในโปรเจกต์อยู่แล้ว ตรวจสอบไดเรกทอรี ${UNREAL_PROJECT}/Intermediate/Android/APK/JavaLibs และ ${UNREAL_PROJECT}/Intermediate/Android/APK/libs ตัวอย่างเช่น ใน โปรเจกต์ตัวอย่าง ที่สร้างโดยใช้ Unreal Engine 4.15 มีไลบรารีดังต่อไปนี้:
JavaLibs:
- downloader_library
- play-services-ads-lite-9.2.0
- play-services-auth-base-9.2.0
- play-services-basement-9.2.0
- play-services-drive-9.2.0
- play-services-gass-9.2.0
- play-services-plus-9.2.0
- support-v4-23.0.0
- play-services-ads-9.2.0
- play-services-auth-9.2.0
- play-services-base-9.2.0
- play-services-clearcut-9.2.0
- play-services-games-9.2.0
- play-services-nearby-9.2.0
- play-services-tasks-9.2.0
- pushwoosh-ue-plugin // เพิ่มโดย Pushwoosh plugin
libs:
- SystemUtils.jar
- VrApi.jar
- play-services-gcm-9.2.0.jar // เพิ่มโดย Pushwoosh plugin
- play-services-iid-9.2.0.jar // เพิ่มโดย Pushwoosh plugin
2. หากเวอร์ชันของไลบรารี play-services* ที่ใช้ใน Pushwoosh และ Unreal Engine ไม่ตรงกัน ให้ลบไลบรารีเหล่านี้ออกจาก Pushwoosh plugin
3. ตรวจสอบว่าไลบรารีใดที่ขาดหายไปที่คุณควรเพิ่มลงใน Pushwoosh Plugin ปลั๊กอินต้องการไลบรารี android-support-v4, play-services-base, play-services-basement, play-services-gcm, play-services-iid สำหรับโปรเจกต์ตัวอย่าง มีเพียง play-services-gcm และ play-services-iid เท่านั้นที่ไม่ซ้ำซ้อน ดังนั้นจึงเป็นไลบรารีเดียวที่ควรเพิ่มในกรณีนี้
4. เพิ่มไลบรารีโดยวางไฟล์ .jar จาก Android SDK ใน https://github.com/Pushwoosh/pushwoosh-unreal-engine/tree/master/Plugins/Pushwoosh/lib/Android/libs ตำแหน่งของไลบรารี Google Play ได้อธิบายไว้ที่ตอนต้นของบทความนี้
แบ่งปันความคิดเห็นของคุณกับเรา
Anchor link toความคิดเห็นของคุณช่วยให้เราสร้างประสบการณ์ที่ดีขึ้น หากคุณประสบปัญหาใดๆ ในระหว่างขั้นตอนการรวม SDK โปรดแบ่งปันความคิดเห็นของคุณกับเรา ผ่านแบบฟอร์มนี้