2017年10月4日 星期三

Android Studio Plugin入門

雖然是寫Android Studio的Plugin,但開發是在IntelliJ IDEA上,
先到  https://www.jetbrains.com/idea/download/
選擇好自己的作業系統,我是下載Community版。

開始安裝,因為要開發Plugin,左下角的那個插頭圖示需要設為Enable,但沒什麼作用。

裝好後,隨便new一個專案,然後進入設定,把Plugin裝好。

之後IntelliJ IDEA會要求重啟,重啟後new Project就可以找到開發Plugin的項目了。

new好了一個新的Plugin專案後,在src上按右鍵,選擇Action

方便測試,參數都填入一樣的字串plugintest,Groups選ToolsMenu(Tools),Actions選ToolsBasicGroup(Tools Basic Group)

按下OK後,上方會會出現提示,選擇右邊的藍字就好了。

在plugintest.java的actionPerformed函式加入以下程式碼。
Project project = e.getProject();
Messages.showMessageDialog(project, "plugintest","title",Messages.getInformationIcon());
接下來可以先測試一下,按下右上方的箭頭執行。

會再執行一個IntelliJ IDEA,選擇Tools選項會看到多了一個項目,點擊後會跳出一個對話框,代表成功了。

在專案上案右鍵選Prepare Plugin Module 'plugintest' For Deployment,就可以打包了

將產生的jar拿給Android Studio安裝會顯示不相容的錯誤。

回到IntelliJ IDEA在resources->META-INF->plugin.xml內
<idea-version since-build="145.0"/>
把這行找出,注意編號的值,需要修改,至於改成多少可以參考一下 其它的Plugin,例如:
Coverage、Gradle、Properties、Setings Repository等...,我是改成143.0

修改完成後,在Tools下按下plugintest就會跳出對話框了。

以上是Android Studio在2.1.3版的情況,但在2.2.3版按下增加的功能會跳不出對話框 ,還需要回IntelliJ IDEA作些修改。

在src->plugintest.java內要補上類似package com.my.test;的程式碼,就像在寫android時一樣,名稱自己決定,寫好後也要把plugintest.java移至相同的位置。

別忘了在resources->META-INF->plugin.xml內找到
<action id="plugintest" class="plugintest" text="plugintest" description="plugintest">
把class的值加上剛才自己定的包名,例如com.my.test.plugintest。這樣2.2.3版就可以顯示對話框了。

另外在plugin.xml內有一行
<depends>com.intellij.modules.lang</depends>
碰到其它錯誤時,可視需要打開,或修改。

2017年4月6日 星期四

Unity3d 同時使用 google play service 與 admob

之前有寫過這2個外掛合用需要做些修改,現在不用了。

Unity3D 的版本 5.3.4f1

play-games-plugin-for-unity 版本 0.9.36
https://github.com/playgameservices/play-games-plugin-for-unity

Google Mobile Ads Unity Plugin 版本 v3.4.0
https://github.com/googleads/googleads-mobile-unity/releases/tag/v3.4.0

2個外掛換了最新的版本,主要是想試試獎勵式廣告。
在admob上設好後,等一段時間再試,才會成功,基本上沒什麼問題,
要注意的是 google play service 出現2個警告:

Found dependencies: com.android.support:support-v4 required by (this app)

WARNING: No compatible versions of com.android.support:support-v4 required by (com.google.android.gms:play-services-basement:9.4.0), will try using the latest version 23.4.0

但還是可以正常使用登入與遊戲存檔和顯示廣告。

提一下碰到的坑,Android SDK更新如下:(好久沒更新了)
Android Support Repository 36 -> 47
Google Play services 32 -> 39
Google Repository 32 -> 46
Intel x86 Emulator Accelerator(HAXM installer) 6.0.3 -> 6.1.1

更新後遊戲內登入google就會crash,我猜是Google Play services這個更新的問題,
所以我先回復成舊版,讓功能正常比較重要。

2016年9月26日 星期一

Google Domains信用卡無法結帳(You appear to be in a country where Google Domains is not yet available.)

之前買的Google Domains服務快到期了,於是再去購買,只是會出現如下的錯誤訊息:
Oops! We couldn't checkout your cart. Please try again later. 
這時才想起來,去年也是卡在這裡,而且還有另一個訊息:
You appear to be in a country where Google Domains is not yet available.
記得只要把地址改一改就行了,於是就去Google Wallet去改信用卡的地址,只是改完後,還是一樣無法結帳。
後來只好按下這一串You appear to be in a country where Google Domains is not yet available.後方的Learn more,就會顯示一個對話框:

接著選 Wait, i have a US  Billing address.然後就會有個介面跳到改信用卡的地址或增加信用卡,我再增加一張信用卡就可以買了,地址別忘了要美國的地址,奇怪的地方在於增加的信用卡是重復輸入的,改的也是Google Wallet的設定。但自己去Google Wallet改好像沒用。

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



2016年9月8日 星期四

Unity3D No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').


在Unity3D 5.3 加上google play service的功能會先去下載下面的plugin
https://github.com/playgameservices/play-games-plugin-for-unity
不意外的,又有如標題的錯誤了.

大部份解法都是去android sdk目錄下的 extras\google\google_play_services 找檔案來用,但我實在是找不到那些神奇的檔案。
不過下面這個網址倒是有不一樣的解法,可以參考看看
https://app-c.net/tutorial/unity/version5_2/

他是直接把 @integer/google_play_services_version 這變數換成字串,如下
<meta-data android:name="com.google.android.gms.version"
android:value="4323000" />

到這裡可以編釋了,過了一段時間回頭看這個值又變回@integer/google_play_services_version了,估計是在
Window->GooglePlayGames->setup->Android setup...
的設定完成後就變回去了,所以說不定一開始把這個欄位刪除也可以先編釋。

順便提一下使用EnableSaveGames()碰到的問題:
在設定PlayGamesClientConfiguration時,有加上EnableSaveGames(),而且
在google play開發平台上該設定的都有設定,但登入後遊戲就是會跳掉,那麼可參考如下:
https://developers.google.com/games/services/console/configuring
其實就是進入手機上的設定->應用程式->Google Play 服務->管理空間->清除所有資料。
就沒問題了。害我以為改錯什麼,又浪費了我好幾個小時...