LoginSignup
7
4

More than 3 years have passed since last update.

AWS SDK for Unity を利用したアプリがAndroid上で動作しない【Unity 2019 2.11f1】

Last updated at Posted at 2019-11-14

発生したエラー

AWS SDK for Unityを利用して『S3でリソースをアップロード/取得』ができるツールを作成してビルドしてみたところ
iOS/Unityエディタ上では問題なく動作するが、Android向けにビルドをすると下記のエラーが発生し動作しなくなった

E/Unity: ArgumentException: Object of type 'System.Object[]' cannot be converted to type 'UnityEngine.AndroidJavaObject[]'.
     at System.RuntimeType.CheckValue (System.Object value, System.Reflection.Binder binder, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00000] in <00000000000000000000000000000000>:0
     at System.Reflection.MonoMethod.ConvertValues (System.Reflection.Binder binder, System.Object[] args, System.Reflection.ParameterInfo[] pinfo, System.Globalization.CultureInfo culture, System.Reflection.BindingFlags invokeAttr) [0x00000] in <00000000000000000000000000000000>:0
     at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <00000000000000000000000000000000>:0
     at Amazon.Util.Internal.AmazonHookedPlatformInfo.Init () [0x00000] in <00000000000000000000000000000000>:0
     at Amazon.Util.Internal.AmazonH...

エラー内容を追ってみると、AWS SDKで提供されているメソッドで正しい結果が得られていないため他動作も止まってしまっているようだった。

環境

OS : macOS Mojave 10.14.5
Unity : 2019.2.11f1
AWS SDK : aws-sdk-unity_3.3.627.0

解決策

AWS SDK For .NETのIssueで同様の問題が上がっていた
https://github.com/aws/aws-sdk-net/issues/1262

issueの最後でmatteo-prosperiさんがUnityユーザー向けに .NET Standard 2.0用パッケージをZipで配布しているので、
ダウンロード → 解凍 → 必要なdllファイルをAssets/以下に置くだけでOK(*1)

(*1)コードは.NET向けにリファクタが必要。For Unityのdllは念の為全て削除してからやったほうがいい。

余談

原因や解決方法を調べていると、いろんなことが出てきたので備忘録としてまとめておく。

▶︎ For Unityはもうサポートしてないらしい

他issueを見てみると、AWSの方が「For Unityはすでにサポートされていないので、For .NETを使用するように」と案内を出していた
https://github.com/aws/aws-sdk-net/issues/1440

▶︎ AWS SDK周りなど最新情報を入手するには

下記の公式Blogをチェックするといい。
https://aws.amazon.com/blogs/
https://aws.amazon.com/jp/blogs/mobile/

▶︎ 他のエラーが発生したら

コードストリッピング回避をしていない可能性がある
Assets/以下どこでもいいので、下記の「link.xml」ファイルを作成して対処する

結構見落としがちなので、こちらも必ず設定するように。

link.xml
<linker>
      <!-- if you are using AWSConfigs.HttpClient.UnityWebRequest option-->

  <assembly fullname="UnityEngine">
      <type fullname="UnityEngine.Networking.UnityWebRequest" preserve="all" />
      <type fullname="UnityEngine.Networking.UploadHandlerRaw" preserve="all" />
      <type fullname="UnityEngine.Networking.UploadHandler" preserve="all" />
      <type fullname="UnityEngine.Networking.DownloadHandler" preserve="all" />
      <type fullname="UnityEngine.Networking.DownloadHandlerBuffer" preserve="all" />
  </assembly>

  <assembly fullname="mscorlib">
      <namespace fullname="System.Security.Cryptography" preserve="all"/>
  </assembly>

  <assembly fullname="System">
      <namespace fullname="System.Security.Cryptography" preserve="all"/>
  </assembly>

  <assembly fullname="AWSSDK.Core" preserve="all">
      <namespace fullname="Amazon.Util.Internal.PlatformServices" preserve="all"/>
  </assembly>
  <assembly fullname="AWSSDK.CognitoIdentity" preserve="all"/>
  <assembly fullname="AWSSDK.SecurityToken" preserve="all"/>
  add more services that you need here...
</linker>

最後の add more services that you need here... に使用するサービスを追記する
今回だとS3なので、 <assembly fullname="AWSSDK.S3" preserve="all"/> を追記する

7
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4