NIFCLOUD-mbaas / UserCommunity

ニフクラ mobile backend ユーザーコミュニティ
https://mbaas.nifcloud.com/
81 stars 18 forks source link

Unity(Android版)でPush通知を使おうとするもアプリが落ちる #619

Open wakepon opened 7 years ago

wakepon commented 7 years ago

NCMBを利用してPush通知を実装しようと思っているのですが、以下のようなログを吐きつつアプリが落ちてしまいます。

■落ちる直前のログ D/Unity ( 7295): Created framebuffer: resolution[1080x1920], rgba[8/8/8/8], depth+stencil[24/8], samples[0] E/AndroidRuntime( 7295): Unity version : 5.5.0f3 W/ActivityManager( 879): Force finishing activity com.waken.Alphabeast/com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerNativeActivity I/REC@0 ( 879): am_finish_activity: {0,766182542,171,com.waken.Alphabeast/com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerNativeActivity,crashed} I/Unity ( 7295): windowFocusChanged: false I/Unity ( 7295): onPause D/Unity ( 7295): Setting up 1 worker threads for Enlighten. D/Unity ( 7295): Thread -> id: ffffffff93604300 -> priority: 1 D/Unity ( 7295): ASensorManager_destroyEventQueue returned 0 W/ActivityManager( 879): Activity pause timeout for ActivityRecord{2dab048e u0 com.waken.Alphabeast/com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerNativeActivity t171 f} I/Unity ( 7295): ##unity-automation:{"messageType":"MemoryLeaks","allocatedMemory":12263,"memoryLabels":[{"Permanent":5984},{"NewDelete":5067},{"Manager":56},{"BaseObject":240},{"String":200},{"ScriptManager":600},{"CloudService":32},{"SceneManager":84}]} D/Unity ( 7295): SetWindow 0 0x0 I/Unity ( 7295): onDestroy I/WindowState( 879): WIN DEATH: Window{1605da43 u0 com.waken.Alphabeast/com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerNativeActivity}

■環境 NCMB 2.2.0 Unity 5.5.0.f3 プラットフォーム Android (AdMob 3.1.3)

■やったこと Firebaseにてプロジェクト作成 NCMBのウェブサイトにてAPIキーの設定 *Unity側でSender IDの設定

■わかっていること iOSでは、うまく動作している Unity EditorでNCMBSettingの「Android Sender Id」の部分を空にすると落ちない。 *Issues#567 に同じような現象が報告されていて、そこではAdMobと絡めると、という風に言われている。

Gamekozo commented 7 years ago

同じ症状なのですが、もう解決されましたか? 僕の場合はAndroid Manufestに不要な設定を入れているのが原因でした。 具体的には <activity android:name="com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerProxyActivity" android:launchMode="singleTop" という具合に、勝手な思い込みで「android:launchMode="singleTop"」を入れていたことで発生しました。 Proxy的な役割ですので、不要と判断し削除したところ問題なく動作するようになっています。 参考になれば幸いです。

wakepon commented 7 years ago

コメントありがとうございます。非常にありがたいです。 そして上記の問題は未だ解決しておりません。

Gamekozoさんのおっしゃられるのは、com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerProxyActivityに、android:launchMode="singleTop"を入れていたのが良くなかったということでしょうか?

残念ながら、そのような設定は入っておりませんでした。ちなみに、これは何をどのようにする設定なのでしょうか?Android Manufestに詳しくなく、ご教授いただければ幸いです。

Gamekozo commented 7 years ago

状況が違ったようですね。失礼いたしました。

こちらでは下記の環境で動作しております。 Google Mobile Ads Unity Plugin v3.3.0 NCMB 2.2.0

Android Manufestに関しては詳しく存じ上げませんが、WIN DEATHがでていることから Activietyの記載に何らかの問題があると思われます。

NCMB 2.2.0に添付されているAndroid Manufest(Assets/Plugins/Android/にあります) をもう一度見返して、 Activityはすべて同じように記載されているか、 <activity android:name="com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerProxyActivity" の他にUnityPlayerProxyActivityとつくActivityが複数記載されていないかなどご確認いただくと 良いかもしれません。

また、YOUR_PACKAGE_NAMEをcom.waken.Alphabeastにすべて置き換えてあるかなどの確認も 必要かと思います。

あまりお役に立てませんがご回答させていただきました。

wakepon commented 7 years ago

ありがとうございます。 絶望的な気持ちになっていたので、そのものズバリの回答でなかったとしても、すごくメンタル面で助かりました! Manufestをもう一度見直してみようと思います!

Gamekozo commented 7 years ago

調べていてUnity5.5ではUnityPlayerNativeActivityがdeprecatedとなっていることがわかりました。 もし、まだうまくいっていないなら、下記のように修正してみてはいかがでしょうか。 お役に立てばいいのですが。

<!---<activity android:name="com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerProxyActivity"-->
    <activity android:name="com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerActivity"
        android:label="@string/app_name"
        android:launchMode="singleTop"
        android:screenOrientation="portrait"
        android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
        <!--
        <activity android:name="com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:label="@string/app_name"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
        </activity>

        <activity android:name="com.nifty.cloud.mb.ncmbgcmplugin.UnityPlayerNativeActivity"
            android:launchMode="singleTop"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
            <meta-data android:name="android.app.lib_name" android:value="unity" />
            <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
        </activity>-->
wakepon commented 7 years ago

ありがとうございます! ちょっと、今すぐには試せないのですが、来週には試せると思うので結果が分かり次第、また報告させていただきます!

wakepon commented 7 years ago

その後、色々と試しました。

NCMBのサンプルプロジェクトでは動作が確認できたので、それに、AdMobのプラグインを追加してみました。

すると、

CommandInvokationFailure: Unable to convert classes into dex format. /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/bin/java -Xmx2048M -Dcom.android.sdkmanager.toolsdir="/Users/wakepon/Library/Android/sdk/tools" -Dfile.encoding=UTF8 -jar "/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/sdktools.jar" -

stderr[ Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat; ...

stderr[ Uncaught translation error: java.lang.IllegalArgumentException: already added: Lcom/google/ads/AdRequest; ...

といったエラーが出てしまいます。

Google Play関連のプラグインが重複しているようなので、android-support-v4.jar、google-play-services.jarを削除することでビルドエラーを回避しました。

すると起動時にアプリが落ちるという現象が再現できました。

おそらく、自分の本プロジェクトの方でもビルドエラー回避のためにいくつかjarファイルを削除したのだと思います(うろ覚え)

jarファイルを削除する以外でビルドエラーを回避する方法があれば良いのですが、なければ諦めようかと思います。