Android
adMob
FacebookSDK
Unity2017

続Unity2017+Androidで色んなSDKを入れた場合のエラー備忘録

Admobメディエーションで、AppLovinSDKをいれる際に下記エラーがでたら

iOS版はこちら → 続Unity2017+iOSで色んなSDKを入れた場合のエラー備忘録

Exception: JNI: Init'd AndroidJavaClass with null ptr!
UnityEngine.AndroidJavaClass..ctor (System.IntPtr jclass) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:622)
UnityEngine.AndroidJavaObject.get_JavaLangClass () (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:600)
UnityEngine.AndroidJavaObject.FindClass (System.String name) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:591)
UnityEngine.AndroidJavaClass._AndroidJavaClass (System.String className) (at /Users/builduser/buildslave/unity/build/Runtime/Export/AndroidJavaImpl.cs:611)
UnityEngine.AndroidJavaClass..ctor (System.String className) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/AndroidJavaBindings.gen.cs:92)
AppLovin.getDefaultPlugin () (at Assets/Plugins/AppLovin/AppLovin.cs:106)
AppLovin.SetSdkKey (System.String sdkKey) (at Assets/Plugins/AppLovin/AppLovin.cs:560)
GameSceneSingleton.RequestRewardBasedVideo () (at Assets/Scripts/Common/GameSceneSingleton.cs:232)
GameManager.Awake () (at Assets/Scripts/Common/GameManager.cs:371)

AppLovin.SetSdkKey(Constant.SDK_APPLOVIN_API_KEY);
AppLovin.InitializeSdk();

がUnityエディター上だとエラーになってしまうので、

下記のように分岐で解決

#if UNITY_EDITOR
// Do not process with unityEditor

#elif UNITY_ANDROID
// AppLovin
AppLovin.SetSdkKey(Constant.SDK_APPLOVIN_API_KEY);
AppLovin.InitializeSdk();


#elif UNITY_IOS
#endif

AndroidOS5以上(API21)なのに、multi-dexエラーがでる場合

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

stderr[

trouble writing output: Too many field references: 97536; max is 65536.
You may try using --multi-dex option.
References by package:
     2 android.accounts
    29 android.app

ビルド方法がinternalになっているから、gradleにすればOK

他にも、「support-core-utils-*.aar」ファイル等が衝突して起きる場合もあるので、その場合は、このaarファイルを削除して試してみるといいかも

「No resource found that matches the given name (at 'resource' with value '@xml/filepaths').」 というリソースファイルが見つかりませんというエラー。

AndroidManifestの

AndroidManifest.xml
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/filepaths"></meta-data>

で指定しているファイルがない場合に発生する。
たとえばこういうの。

image.png

何のファイル名か教えてくれない重複エラー

CommandInvokationFailure: Gradle build failed. 
/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home/bin/java -classpath "/Applications/Unity/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-2.14.jar" org.gradle.launcher.GradleMain "assembleRelease"

stderr[
Note: there were 11 duplicate class definitions.
      (http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)
Warning: com.crashlytics.android.beta.ActivityLifecycleCheckForUpdatesController$1: can't find superclass or interface io.fabric.sdk.android.ActivityLifecycleManager$Callbacks
Warning: com.crashlytics.android.beta.Beta: can't find superclass or interface io.fabric.sdk.android.Kit

MinifyのReleaseでproguardを使用しないようにすると、治った。

他にも、gradle(new)でエクスポートし、android studioでビルドすると一応通ったが、挙動が色々おかしかった。。汗

参考: http://answers.unity3d.com/questions/1397172/gradle-build-errors.html

エラーの通りですが、PlayResolverで更新。



10-20 14:46:30.916 14742 14771 E Unity   : InitializationException: Java class com/google/firebase/messaging/cpp/RegistrationIntentService not found.  Please verify the AAR which contains the com/google/firebase/messaging/cpp/RegistrationIntentService class is included in your app.
10-20 14:46:30.916 14742 14771 E Unity   : On Android, Firebase requires C/C++ and Java components
10-20 14:46:30.916 14742 14771 E Unity   : that are distributed with the Firebase and Android SDKs.
10-20 14:46:30.916 14742 14771 E Unity   : 
10-20 14:46:30.916 14742 14771 E Unity   : It's likely the required dependencies for Firebase were not included
10-20 14:46:30.916 14742 14771 E Unity   : in your Unity project.
10-20 14:46:30.916 14742 14771 E Unity   : Assets/Plugins/Android/ in your Unity project should contain
10-20 14:46:30.916 14742 14771 E Unity   : AAR files in the form firebase-*.aar
10-20 14:46:30.916 14742 14771 E Unity   : You may have disabled the Android Resolver which would
10-20 14:46:30.916 14742 14771 E Unity   : have added the AAR dependencies for you.
10-20 14:46:30.916 14742 14771 E Unity   : 
10-20 14:46:30.916 14742 14771 E Unity   : Do the following to enable the Android Resolver in Unity:
10-20 14:46:30.916 14742 14771 E Unity   : * Select the menu option 'Assets -> Play Services Resolver -> 
10-20 14:46:30.916 14742 14771 E Unity   :   Android Resolver -> Settings'
10-20 14:46:30.916 14742 14771 E Unity   : * In the Android Resolver settings check
10-20 14:46:30.916 14742 14771 E Unity   :   'Enable Background Resolution'
10-20 14:46:30.916 14742 14771 E Unity   : * Select the menu option 'Assets -> Play Services Resolver ->
10-20 14:46:30.916 14742 14771 E Unity   :   Android Resolver -> Resolve Client Jars' to force Android
10-20 14:46:30.916 14742 14771 E Unity   :   dependency resolution.
10-20 14:46:30.916 14742 14771 E Unity   : * Rebuil

下記のようにUnityEditor上で更新

image.png

下記support〜が重複している場合

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl; See the Console for details.

重複しているいらないsupportを削除

image.png

DllNotFoundException: App Firebase.Messaging.FirebaseMessagingPINVOKE+SWIGExceptionHelper..cctorエラー

FirebaseSDKのアップデート時に遭遇、Firebase周りのSDKを一旦すべてプロジェクトファイルから消してやったらおなった。
消す際要注意

An assembly with the same name `Google.VersionHandlerImpl' has already been imported. Consider removing one of the references or sign the assemblyエラー

Unityを再起動して、versionHandlerのポップアップで古い方のサポートライブラリを削除するにYesしたらなおった。。