2016年9月10日 星期六

play-games-plugin-for-unity 與 googleads-mobile-unity 混用

雖然有人把google play services和admob的Unity3D plugin都寫好了,但同時使用也是要動手微調一下,不然可能就會碰到以下2種錯誤。
Failed to re-package resources
Unable to convert classes into dex format
先把Unity和plugin的版本列出

Unity3D 5.3

Unity3D的google play services plugin 0.9.34
https://github.com/playgameservices/play-games-plugin-for-unity

Unity3D的admob plugin 3.0.5
https://github.com/googleads/googleads-mobile-unity/releases

將2種plugin合起來用需要做些修改,可參考以下網址:
https://ndesostyle.wordpress.com/2016/02/10/conflict-with-latest-googleads-mobile-and-play-games-plugin-for-unity/

網頁上的重點是這一段字後面的影片連結:
Fixing google play games and admob plugin Unity. Video tutorial is Available  Youtube

可惜裡面用的版本有點舊了,我再把改的過程記錄一下。

1.先裝play-games-plugin-for-unity,若碰到
Unity3D No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').
錯誤,可先看之前這篇的方法
http://chadgod.blogspot.tw/2016/09/unity3d-no-resource-found-that-matches.html
沒問題後再把admob plugin裝上

2.打開Assets/GooglePlayGames/Editor/GPGSUpgrader.cs
在97行的地方把以下2行註解掉
//string clientDir = "Assets/Plugins/Android/google-play-services_lib";
//GPGSUtil.DeleteDirIfExists(clientDir);

3.打開Assets/GooglePlayGames/Editor/GPGSDependencies.cs
在67行的地方註解掉
//svcSupport.DependOn("com.android.support",
//"support-v4",
//"23.1+");
後面加上
svcSupport.DependOn("com.google.android.gms",
"play-services-ads",
PluginVersion.PlayServicesVersionConstraint);

4.打開Assets/Plugins/Android/GoogleMobileAdsPlugin/AndroidManifest.xml
在23~25行註解掉
<!-- <activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" /> -->

5.改好後回到Unity3D編輯器會跳出一個對話框內容如下
Remove or replace support-v4 version 23.4.0 with version 23.1.1?
我選了ok

6.這時就可以先Build看看了,若成功就可以到以下網址看Unity的admob範例
https://developers.google.com/mobile-ads-sdk/docs/games?hl=zh-tw#unity

7.若失敗也只能在找看看有沒有其它方法了,附上使用的android sdk,提供一些線索。
Tools
Android SDK Tools 25.1.7
Android SDK Platform-tools 24.0.2
Android SDK Build-tools 23.0.2

Android 6.0

Extras
Android Support Repository 36
Google Play services 32
Google Repository 32
Google Play APK Expansion library 1
Google Play Licensing Library 1
Intel x86 Emulator Accelerator(HAXM installer) 6.0.3



沒有留言:

張貼留言