質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

3727閲覧

Unity Cloud BuildでFirebaseを使いたい

709

総合スコア28

Firebase

Firebaseは、Googleが提供するBasSサービスの一つ。リアルタイム通知可能、並びにアクセス制御ができるオブジェクトデータベース機能を備えます。さらに認証機能、アプリケーションのログ解析機能などの利用も可能です。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2019/10/12 11:23

編集2019/10/12 11:26

前提・実現したいこと

Unity Cloud Buildを使い、iosアプリにFirebaseの機能を追加する

  • Analytics
  • Auth
  • Database
  • Firestore
  • Messaging
  • Storage

発生している問題・エラーメッセージ

5720: ▸ Compiling netstandard.cpp 5721: ▸ Compiling mscorlib_CodeGen.c 5722: ▸ Compiling mscorlib9.cpp 5723: ▸ Compiling mscorlib8.cpp 5724: ▸ Compiling mscorlib7.cpp 5725: ▸ Compiling mscorlib6.cpp 5726: ▸ Linking tuyopon 5727: ▸ ❌; Undefined symbols for architecture armv7 5728: ▸ > Symbol: _SWIGRegisterStringCallback_FirebaseMessaging 5729: ▸ > Referenced from: _SWIGStringHelper__cctor_mE5F36F659A4B2283BE917F75E5B861D8F6F03DBD in Firebase.Messaging.o 5730: ▸ ❌; ld: symbol(s) not found for architecture armv7 5731: ▸ ❌; clang: error: linker command failed with exit code 1 (use -v to see invocation) 5732: ▸ Compiling mscorlib5.cpp 5733: ▸ Compiling mscorlib4.cpp 5734: ▸ Compiling mscorlib3.cpp 5735: ▸ Compiling mscorlib2.cpp 5736: ▸ Compiling mscorlib19.cpp 5737: ▸ Compiling mscorlib18.cpp 5738: ▸ Compiling mscorlib17.cpp 5739: ▸ Compiling mscorlib16.cpp 5740: ▸ Compiling mscorlib15.cpp

該当のソースコード

Xcodeの設定を変えるScriptです。

c#

1using UnityEngine; 2using UnityEditor; 3using UnityEditor.Callbacks; 4#if UNITY_IOS 5using UnityEditor.iOS.Xcode; 6using System.Collections.Generic; 7#endif 8using System.IO; 9 10using System.Xml; 11 12 13public class PostBuildProcess { 14 15 [PostProcessBuild] 16 public static void OnPostProcessBuild (BuildTarget buildTarget, string path) { 17#if UNITY_IOS 18 19 20 PBXProject proj = new PBXProject (); 21 string projPath = Path.Combine (path, "Unity-iPhone.xcodeproj/project.pbxproj"); 22 proj.ReadFromFile(PBXProject.GetPBXProjectPath(path)); 23 24 var projectGuid = proj.TargetGuidByName(PBXProject.GetUnityTargetName()); 25 proj.SetBuildProperty(projectGuid, "CLANG_ENABLE_MODULES", "YES"); 26 27 proj.WriteToFile(PBXProject.GetPBXProjectPath(path)); 28 proj.ReadFromString (File.ReadAllText (projPath)); 29 30 string target = proj.TargetGuidByName ("Unity-iPhone"); 31 proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-lz"); 32 proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC"); 33 proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-lsqlite3"); 34 proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-lc++"); 35 36 37 38 List<string> frameworks = new List<string> () { 39 "AdSupport.framework", 40 "CoreData.framework", 41 "SystemConfiguration.framework", 42 "libz.dylib", 43 "libsqlite3.dylib", 44 "libicucore.tbd", 45 "UserNotifications.framework" 46 }; 47 48 foreach (var framework in frameworks) { 49 proj.AddFrameworkToProject (target, framework, false); 50 } 51 //List of frameworks that will be added to project 52 53 54 //Add each by name 55 if (!File.Exists(path + "/GoogleService-Info.plist")) 56 { 57 FileUtil.CopyFileOrDirectory("GoogleService-Info.plist", path + "/GoogleService-Info.plist"); 58 } 59 //Add 60 File.WriteAllText (projPath, proj.WriteToString ()); 61 62 //Set Push Notification Capability 63 CreateEntitlements(path,"tuyopon"); 64 SetCapabilities(path); 65 SetBackgroundMode(path); 66 67 68#endif 69 } 70 #if UNITY_IOS 71 private static void SetBackgroundMode(string path) 72 { 73 var plistPath = Path.Combine(path, "Info.plist"); 74 75 PlistDocument plist = new PlistDocument(); 76 plist.ReadFromFile(plistPath); 77 78 plist.root.SetBoolean("FirebaseAppDelegateProxyEnabled",false); 79 80 PlistElementArray bgModes = plist.root.CreateArray("UIBackgroundModes"); 81 bgModes.AddString("remote-notification"); 82 83 plist.WriteToFile(plistPath); 84 } 85 86 private static void CreateEntitlements(string path,string your_appname) 87 { 88 XmlDocument document = new XmlDocument (); 89 XmlDocumentType doctype = document.CreateDocumentType ("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); 90 document.AppendChild (doctype); 91 92 XmlElement plist = document.CreateElement ("plist"); 93 plist.SetAttribute ("version", "1.0"); 94 XmlElement dict = document.CreateElement ("dict"); 95 plist.AppendChild (dict); 96 document.AppendChild (plist); 97 98 XmlElement e = (XmlElement) document.SelectSingleNode ("/plist/dict"); 99 100 XmlElement key = document.CreateElement ("key"); 101 key.InnerText = "aps-environment"; 102 e.AppendChild (key); 103 104 XmlElement value = document.CreateElement ("string"); 105 value.InnerText = "development"; 106 e.AppendChild (value); 107 108 string entitlementsPath = path + "/Unity-iPhone/"+your_appname+".entitlements"; 109 document.Save(entitlementsPath); 110 111 string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; 112 PBXProject proj = new PBXProject (); 113 proj.ReadFromString (File.ReadAllText (projPath)); 114 string target = proj.TargetGuidByName ("Unity-iPhone"); 115 string guid = proj.AddFile("GoogleService-Info.plist", path+"GoogleService-Info.plist"); 116 proj.SetBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", "Unity-iPhone/"+your_appname+".entitlements"); 117 proj.AddFileToBuild(target, guid); 118 proj.WriteToFile(projPath); 119 } 120 121 private static void SetCapabilities(string path) 122 { 123 string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; 124 PBXProject proj = new PBXProject (); 125 proj.ReadFromString (File.ReadAllText (projPath)); 126 127 string[] lines = proj.WriteToString().Split ('\n'); 128 List<string> newLines = new List<string> (); 129 bool editFinish = false; 130 131 for (int i = 0; i < lines.Length; i++) { 132 133 string line = lines [i]; 134 135 if (editFinish) { 136 newLines.Add (line); 137 } else if (line.IndexOf ("isa = PBXProject;") > -1) { 138 do { 139 newLines.Add (line); 140 line = lines [++i]; 141 } while (line.IndexOf("TargetAttributes = {") == -1); 142 143 // 以下の内容はxcodeprojの内容にあるproject.pbxprojを参照してください 144 newLines.Add("TargetAttributes = {"); 145 newLines.Add("****** = {");//見えなくしています 146 newLines.Add("DevelopmentTeam = ******;");//見えなくしています 147 newLines.Add("SystemCapabilities = {"); 148 newLines.Add("com.apple.BackgroundModes = {"); 149 newLines.Add("enabled = 1;"); 150 newLines.Add("};"); 151 newLines.Add("com.apple.Push = {"); 152 newLines.Add("enabled = 1;"); 153 newLines.Add("};"); 154 newLines.Add("};"); 155 newLines.Add("};"); 156 editFinish = true; 157 158 } else { 159 newLines.Add (line); 160 } 161 } 162 163 File.WriteAllText(projPath, string.Join ("\n", newLines.ToArray ())); 164 } 165#endif 166}

####firebaseのframework
イメージ説明
####Assets/Firebase/Editor/__???__Dependenciesのファイル
イメージ説明

xml

1<!-- Copyright (C) 2018 Google Inc. All Rights Reserved. 2 3FirebaseApp iOS and Android Dependencies. 4--> 5 6<dependencies> 7 <!--<iosPods> 8 <iosPod name="Firebase/***" version="6.5.0" minTargetSdk="8.0"> 9 </iosPod> 10 </iosPods>--> 11 <androidPackages> 12 <androidPackage spec="com.google.firebase:firebase-common:18.0.0"> 13 </androidPackage> 14 <androidPackage spec="com.google.firebase:firebase-analytics:17.0.1"> 15 </androidPackage> 16 <androidPackage spec="com.google.firebase:firebase-app-unity:6.3.0"> 17 <repositories> 18 <repository>Assets/Firebase/m2repository</repository> 19 </repositories> 20 </androidPackage> 21 </androidPackages> 22</dependencies> 23 24

補足情報

Unity 2019.2.6f1(Cloud Buildも同じ)
Xcode 10.2 (Cloud Build)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

まず、Assets/Plugins/iOSにFirebase.hを追加しました
*.framework/Modules/module.modulemapを読んでこのように書き換えました。
firebaseのMessagingの機能は使わないことにしました。
使う場合は
http://blog.abars.biz/archives/52394874.html

C#

1using UnityEngine; 2using UnityEditor; 3using UnityEditor.Callbacks; 4#if UNITY_IOS 5using UnityEditor.iOS.Xcode; 6using System.Collections.Generic; 7using System.IO; 8using System.Text; 9using System.Xml; 10#endif 11public class BuildProcess 12{ 13 14 [PostProcessBuild] 15 public static void OnPostProcessBuild(BuildTarget buildTarget, string path) 16 { 17#if UNITY_IOS 18 var project = new PBXProject(); 19 project.ReadFromFile(PBXProject.GetPBXProjectPath(path)); 20 21 var projectGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName()); 22 // Enable Modules (C and Objective-C)をYESに設定する 23 project.SetBuildProperty(projectGuid, "CLANG_ENABLE_MODULES", "YES"); 24 25 project.WriteToFile(PBXProject.GetPBXProjectPath(path)); 26 string projPath = Path.Combine (path, "Unity-iPhone.xcodeproj/project.pbxproj"); 27 28 PBXProject proj = new PBXProject (); 29 proj.ReadFromString (File.ReadAllText (projPath)); 30 31 string target = proj.TargetGuidByName ("Unity-iPhone"); 32 33 proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-ObjC"); 34//    ↓ module.modulemap内の「link」に書かれているものを追加する。 35// ↓ link "z"ならproj.AddBuildProperty (target, "OTHER_LDFLAGS", "-lz"); 36 proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-lz"); 37 proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-lc++"); 38 proj.AddBuildProperty(target, "OTHER_LDFLAGS", "-licucore"); 39 proj.AddBuildProperty (target, "OTHER_LDFLAGS", "-lsqlite3"); 40 41//    ↓ module.modulemap内の「link framework」に書かれているものを追加する。 42// ↓ link framework "CoreData"なら"CoreData.framework" 43 List<string> frameworks = new List<string> () { 44 "CoreData.framework", 45 "AddressBook.framework", 46 "Security.framework", 47 "StoreKit.framework", 48 "SystemConfiguration.framework", 49 "UIKit.framework", 50 "Foundation.framework", 51 "SafariServices.framework", 52 "CFNetwork.framework" 53 }; 54 55 foreach (var framework in frameworks) { 56 proj.AddFrameworkToProject (target, framework, false); 57 } 58 59 File.WriteAllText (projPath, proj.WriteToString ()); 60 CreateEntitlements(path,"tuyopon"); 61 62 SetBackgroundMode(path); 63#endif 64 65 } 66 #if UNITY_IOS 67 private static void SetBackgroundMode(string path) 68 { 69 var plistPath = Path.Combine(path, "Info.plist"); 70 71 PlistDocument plist = new PlistDocument(); 72 plist.ReadFromFile(plistPath); 73 74 plist.root.SetBoolean("FirebaseAppDelegateProxyEnabled",false); 75 76 PlistElementArray bgModes = plist.root.CreateArray("UIBackgroundModes"); 77 bgModes.AddString("remote-notification"); 78 79 plist.WriteToFile(plistPath); 80 } 81 82 private static void CreateEntitlements(string path,string your_appname) 83 { 84 XmlDocument document = new XmlDocument (); 85 XmlDocumentType doctype = document.CreateDocumentType ("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd", null); 86 document.AppendChild (doctype); 87 88 XmlElement plist = document.CreateElement ("plist"); 89 plist.SetAttribute ("version", "1.0"); 90 XmlElement dict = document.CreateElement ("dict"); 91 plist.AppendChild (dict); 92 document.AppendChild (plist); 93 94 XmlElement e = (XmlElement) document.SelectSingleNode ("/plist/dict"); 95 96 XmlElement key = document.CreateElement ("key"); 97 key.InnerText = "aps-environment"; 98 e.AppendChild (key); 99 100 XmlElement value = document.CreateElement ("string"); 101 value.InnerText = "development"; 102 e.AppendChild (value); 103 104 string entitlementsPath = path + "/Unity-iPhone/"+your_appname+".entitlements"; 105 document.Save(entitlementsPath); 106 107 string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj"; 108 PBXProject proj = new PBXProject (); 109 proj.ReadFromString (File.ReadAllText (projPath)); 110 string target = proj.TargetGuidByName ("Unity-iPhone"); 111 string guid = proj.AddFile (entitlementsPath, entitlementsPath); 112 proj.SetBuildProperty(target, "CODE_SIGN_ENTITLEMENTS", "Unity-iPhone/"+your_appname+".entitlements"); 113 proj.AddFileToBuild(target, guid); 114 proj.WriteToFile(projPath); 115 } 116 #endif 117 118} 119

後、なぜか一部ファイルがgithub上になかったので.gitignoreを書き換えました。
すると・・・
イメージ説明
やっとエラーの赤から成功の緑になります!

投稿2019/10/22 12:30

709

総合スコア28

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問