facebook twitter hatena line email

「Unity/実機/iOS」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
 
(同じ利用者による、間の45版が非表示)
行3: 行3:
 
*iOSを選択
 
*iOSを選択
 
*OpenDownloadPageからプレイヤーをDL
 
*OpenDownloadPageからプレイヤーをDL
*PlayerSettingsを選択
+
*Edit/ProjectSetting/Playerを選択しPlayerSettingsを開く
*Inspector/端末マーク/OtherSetting
+
*Inspector/端末マークタブ選択/OtherSetting
*Bundle Identifierの"com.company.ProjectName"を適宜変更する
+
*Bundle Identifierの"com.company.ProjectName"を適宜変更する(デフォから変えないとbuild時にエラーとなる)
*buildボタンを押しiPhone用のxcodeプロジェクトDir一式を作成する
+
*File/BuildSettingsからbuildボタンを押しiPhone用のxcodeプロジェクトDir一式を作成する
 
*あとはxcodeプロジェクトを実機で動作させる方法と同じ
 
*あとはxcodeプロジェクトを実機で動作させる方法と同じ
 +
*最新xcodeを起動する
 +
*縦向き・横向きで確認する
 +
 +
==No `Podfile' found in the project directory.エラー==
 +
cocoapodsが入ってるか確認。
 +
$ sudo gem update --system
 +
$ sudo gem install cocoapods
 +
$ pod setup
 +
> Setup completed
 +
 +
==Consider adding the following to ~/.profile: エラーの場合==
 +
デフォだとja_JP.UTF-8になるっぽいのでutf8に変更してあげる
 +
$ vi  ~/.profile
 +
export LANG=en_US.UTF-8
 +
$ source ~/.profile
 +
$ echo $LANG
 +
en_US.UTF-8
 +
 +
==After the failure, "pod repo update" was executed and succeeded. "pod install" was then attempted again, and still failed. エラーの場合==
 +
xcodeのプロジェクトのdirに入って以下実行
 +
$ pod repo update
 +
$ pod install
  
 
==Bundle Identifier has not been set up correctly==
 
==Bundle Identifier has not been set up correctly==
 
*上記のBundle Identifierがデフォルトの"com.company.ProjectName"だと起こるエラー。適宜変更する
 
*上記のBundle Identifierがデフォルトの"com.company.ProjectName"だと起こるエラー。適宜変更する
 +
 +
==Code Signing Error: Signing for "Unity-iPhone" requires a development team. Select a development team in the project editor.==
 +
*xcodeのgeneralのteamが選択されてない
 +
 +
==Verify the Developer App certificate for your account is trusted on your device. Open Settings on  and navigate to General -> Device Management, then select your Developer App certificate to trust it.==
 +
*実機の設定/一般/デバイス管理/アプリを許可する
 +
 +
==which may not be supported by this version of Xcode.エラー==
 +
unsupported os versionとでてる
 +
===This iPhone 6 is running iOS 11.4.1 (15G77), ===
 +
#開発端末のxcodeの中身を確認する
 +
$ cd ~/Library/Developer/Xcode/iOS\ DeviceSupport/
 +
$ ls
 +
10.0.2 (14A456) 10.3.1 (14E304)
 +
もしくは
 +
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
 +
$ ls
 +
10.0 10.1 10.2
 +
#https://github.com/iGhibli/iOS-DeviceSupport/tree/master/DeviceSupport から
 +
#上記どちか存在するDIRに11.4.1をいれてビルド、もしくはxcode再起動すれば良い。
 +
#11.4 (15F79) と 11.4 を入れたら動いた。
 +
 +
参考:https://qiita.com/_CHUBURA/items/ffd280e50ed623989045
 +
 +
===This iPhone XS is running iOS 13.3 (17C54),===
 +
#こちらに  ~/Library/Developer/Xcode/iOS\ DeviceSupport/
 +
#https://github.com/iGhibli/iOS-DeviceSupport/tree/master/DeviceSupport
 +
#13.3 (17C54).zipを解凍して入れると良い。
 +
 +
=="'autorelease' is unavailable: not available in automatic reference counting mode"エラーとなるとき==
 +
target/BuildPhases/CopileSourcesの適用したいmmなどのファイルを選択して、以下をいれる。
 +
-fno-objc-arc
 +
参考:https://blog.77jp.net/automaticreferencecountingarc%E3%81%A7arc%E9%9D%9E%E5%AF%BE%E5%BF%9C%E3%81%AE%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%81%AE%E5%88%A9%E7%94%A8%E6%96%B9%E6%B3%95-ios-%E9%80%86%E5%BC%95
 +
 +
==iosで"dyld_shared_cache_extract_dylibs failed"エラーとなる時==
 +
macの容量が足りない可能性があるので、不要なファイルを消して容量を増やす。
 +
 +
参考:https://rils-k.hatenablog.com/entry/2019/03/03/002057
 +
 +
==ios14対応==
 +
以下エラーが出るとき
 +
<pre>
 +
This app has crashed because it attempted to access privacy-sensitive data without a usage description.
 +
The app's Info.plist must contain an NSUserTrackingUsageDescription key with a string value explaining
 +
to the user how the app uses this data.
 +
</pre>
 +
以下をinfo.plistに追加
 +
<pre>
 +
<key>NSUserTrackingUsageDescription</key>
 +
<string>Dummy</string>
 +
</pre>
 +
 +
==ビルド時にErrors were encountered while preparing your device for development. Please check the Devices and Simulators Window. のエラーが出るとき==
 +
iPhone端末を再起動すればよい。
 +
 +
==iosビルド時に"Invalid bitcode version"エラーが出るとき==
 +
詳細エラー
 +
ld: could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1316.0.21.2.3_0' Reader: '1300.0.29.3_0')', using libLTO version 'LLVM version 13.0.0, (clang-1300.0.29.3)' for architecture arm64
 +
対応方法はxcodeを13.0.0から13.4.1へバージョンアップすると直った。
 +
 +
==iosビルド時に"STATE_ERROR.VALIDATION_ERROR.90206"エラーが出るとき==
 +
詳細エラー
 +
Invalid Bundle. The bundle at '~/Frameworks/UnityFramework.framework' contains disallowed file 'Frameworks'. With error code STATE_ERROR.VALIDATION_ERROR.90206 for id
 +
 +
対応方法:xcodeの部分のBuildSetttingのBuildOptionの"Always embed swift standard libraries"が、Yesになってるので、Noへ変更。
 +
 +
参考:https://zenn.dev/sukedon/articles/0454e2187b08c3
 +
 +
===自動修正する場合===
 +
未検証だけど以下を追加でもなおるかも。
 +
 +
Assets/Editor/XcodeSwiftVersionPostProcess.cs
 +
<pre>
 +
using UnityEditor;
 +
using UnityEditor.Callbacks;
 +
using UnityEditor.iOS.Xcode;
 +
 +
public static class XcodeSwiftVersionPostProcess
 +
{
 +
    [PostProcessBuild]
 +
    public static void OnPostProcessBuild(BuildTarget target, string path)
 +
    {
 +
        if (target != BuildTarget.iOS)
 +
        {
 +
            return;
 +
        }
 +
        var project = new PBXProject();
 +
        project.ReadFromFile(PBXProject.GetPBXProjectPath(path));
 +
        project.SetBuildProperty(project.GetUnityMainTargetGuid(), "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
 +
        project.SetBuildProperty(project.GetUnityFrameworkTargetGuid(), "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
 +
        project.WriteToFile(PBXProject.GetPBXProjectPath(path));
 +
    }
 +
}
 +
</pre>
 +
 +
==iosビルド時に"NSPhotoLibraryUsageDescription"のエラーがメールできてるとき==
 +
詳細エラー
 +
Missing Purpose String in Info.plist - Your app‘s code references one or more APIs that access sensitive user data. The app‘s Info.plist file should contain a NSPhotoLibraryUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. If you're using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required.
 +
 +
対応方法:NSPhotoLibraryUsageDescriptionをinfo.plistへ追加
 +
 +
参考:https://nobushiueshi.com/unityios%E3%83%93%E3%83%AB%E3%83%89%E6%99%82%E3%81%ABnsphotolibraryaddusagedescription%E3%81%A8nsphotolibraryusagedescription%E3%82%92%E8%87%AA%E5%8B%95%E3%81%A7%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B/
 +
 +
==iosビルド時に"You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)"エラーとなる場合==
 +
詳細エラー
 +
error build: 'Library/Developer/Xcode/DerivedData/Unity-iPhone-gmubznzegicgstbzezoypyxvvddz/Build/Products/ReleaseForRunning-iphoneos/PromisesObjC/FBLPromises.framework/FBLPromises(FBLPromise.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file 'Library/Developer/Xcode/DerivedData/Unity-iPhone-gmubznzegicgstbzezoypyxvvddz/Build/Products/ReleaseForRunning-iphoneos/PromisesObjC/FBLPromises.framework/FBLPromises' for architecture arm64
 +
 +
Bitcodeを無効化すれば直る。やり方は、xcodeのTargetsをUnity-iPhone/BuildSettings/EnableBitcodeをNoにする。
 +
 +
参考:https://zenn.dev/dhirooka/scraps/f904ae5d101db6
 +
 +
==info.plistの言語を日本語にする==
 +
===手動設定する場合===
 +
info.plistの
 +
CFBundleDevelopmentRegionをjaへ
 +
CFBundleLocalizationsをjaへ
 +
 +
===unityで自動で設定する場合===
 +
Assets/Editor/XcodeProjectUpdater.cs
 +
<pre>
 +
using UnityEngine;
 +
using UnityEditor;
 +
using UnityEditor.Callbacks;
 +
using UnityEditor.iOS.Xcode;
 +
using System.IO;
 +
 +
public class XcodeProjectUpdater
 +
{
 +
    [PostProcessBuild]
 +
    static void OnPostprocessBuild(BuildTarget buildTarget, string path)
 +
    {
 +
        if (buildTarget != BuildTarget.iOS) return;
 +
        string plistPath = Path.Combine(path, "Info.plist");
 +
        PlistDocument plist = new PlistDocument();
 +
        plist.ReadFromFile(plistPath);
 +
        plist.root.SetString ("CFBundleDevelopmentRegion", "ja");
 +
        plist.WriteToFile(plistPath);
 +
    }
 +
}
 +
</pre>
 +
 +
参考:https://kimizuka.hatenablog.com/entry/2018/09/27/201054
 +
 +
xcodeのInfoPlistのTargetMembershipのUnityiPhoneにチェックを付ける
 +
 +
参考:https://nekosuko.jp/1802/
 +
 +
==xcodeのbitcodeを自動でnoにする場合==
 +
Assets/Editor/XcodeBitCodeNoPostProcess.cs
 +
<pre>
 +
using UnityEditor;
 +
using UnityEditor.Callbacks;
 +
using UnityEditor.iOS.Xcode;
 +
 +
public static class XcodeBitCodeNoPostProcess
 +
{
 +
    [PostProcessBuild]
 +
    public static void OnPostProcessBuild(BuildTarget target, string path)
 +
    {
 +
        if (target != BuildTarget.iOS)
 +
        {
 +
            return;
 +
        }
 +
        var project = new PBXProject();
 +
        project.ReadFromFile(PBXProject.GetPBXProjectPath(path));
 +
        project.SetBuildProperty(project.GetUnityMainTargetGuid(), "ENABLE_BITCODE", "NO");
 +
        project.SetBuildProperty(project.GetUnityFrameworkTargetGuid(), "ENABLE_BITCODE", "NO");
 +
        project.WriteToFile(PBXProject.GetPBXProjectPath(path));
 +
    }
 +
}
 +
</pre>
 +
参考:https://waken.hatenablog.com/

2023年4月10日 (月) 18:20時点における最新版

目次

iOS実機で動かす

  • File/BuildSettingsを選択
  • iOSを選択
  • OpenDownloadPageからプレイヤーをDL
  • Edit/ProjectSetting/Playerを選択しPlayerSettingsを開く
  • Inspector/端末マークタブ選択/OtherSetting
  • Bundle Identifierの"com.company.ProjectName"を適宜変更する(デフォから変えないとbuild時にエラーとなる)
  • File/BuildSettingsからbuildボタンを押しiPhone用のxcodeプロジェクトDir一式を作成する
  • あとはxcodeプロジェクトを実機で動作させる方法と同じ
  • 最新xcodeを起動する
  • 縦向き・横向きで確認する

No `Podfile' found in the project directory.エラー

cocoapodsが入ってるか確認。

$ sudo gem update --system 
$ sudo gem install cocoapods
$ pod setup
> Setup completed

Consider adding the following to ~/.profile: エラーの場合

デフォだとja_JP.UTF-8になるっぽいのでutf8に変更してあげる

$ vi  ~/.profile
export LANG=en_US.UTF-8
$ source ~/.profile
$ echo $LANG
en_US.UTF-8

After the failure, "pod repo update" was executed and succeeded. "pod install" was then attempted again, and still failed. エラーの場合

xcodeのプロジェクトのdirに入って以下実行

$ pod repo update
$ pod install

Bundle Identifier has not been set up correctly

  • 上記のBundle Identifierがデフォルトの"com.company.ProjectName"だと起こるエラー。適宜変更する

Code Signing Error: Signing for "Unity-iPhone" requires a development team. Select a development team in the project editor.

  • xcodeのgeneralのteamが選択されてない

Verify the Developer App certificate for your account is trusted on your device. Open Settings on and navigate to General -> Device Management, then select your Developer App certificate to trust it.

  • 実機の設定/一般/デバイス管理/アプリを許可する

which may not be supported by this version of Xcode.エラー

unsupported os versionとでてる

This iPhone 6 is running iOS 11.4.1 (15G77),

  1. 開発端末のxcodeの中身を確認する
$ cd ~/Library/Developer/Xcode/iOS\ DeviceSupport/
$ ls 
10.0.2 (14A456)	10.3.1 (14E304)

もしくは

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
$ ls 
10.0		10.1		10.2
  1. https://github.com/iGhibli/iOS-DeviceSupport/tree/master/DeviceSupport から
  2. 上記どちか存在するDIRに11.4.1をいれてビルド、もしくはxcode再起動すれば良い。
  3. 11.4 (15F79) と 11.4 を入れたら動いた。

参考:https://qiita.com/_CHUBURA/items/ffd280e50ed623989045

This iPhone XS is running iOS 13.3 (17C54),

  1. こちらに ~/Library/Developer/Xcode/iOS\ DeviceSupport/
  2. https://github.com/iGhibli/iOS-DeviceSupport/tree/master/DeviceSupport
  3. 13.3 (17C54).zipを解凍して入れると良い。

"'autorelease' is unavailable: not available in automatic reference counting mode"エラーとなるとき

target/BuildPhases/CopileSourcesの適用したいmmなどのファイルを選択して、以下をいれる。

-fno-objc-arc

参考:https://blog.77jp.net/automaticreferencecountingarc%E3%81%A7arc%E9%9D%9E%E5%AF%BE%E5%BF%9C%E3%81%AE%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%81%AE%E5%88%A9%E7%94%A8%E6%96%B9%E6%B3%95-ios-%E9%80%86%E5%BC%95

iosで"dyld_shared_cache_extract_dylibs failed"エラーとなる時

macの容量が足りない可能性があるので、不要なファイルを消して容量を増やす。

参考:https://rils-k.hatenablog.com/entry/2019/03/03/002057

ios14対応

以下エラーが出るとき

This app has crashed because it attempted to access privacy-sensitive data without a usage description.
The app's Info.plist must contain an NSUserTrackingUsageDescription key with a string value explaining
to the user how the app uses this data.

以下をinfo.plistに追加

<key>NSUserTrackingUsageDescription</key>
<string>Dummy</string>

ビルド時にErrors were encountered while preparing your device for development. Please check the Devices and Simulators Window. のエラーが出るとき

iPhone端末を再起動すればよい。

iosビルド時に"Invalid bitcode version"エラーが出るとき

詳細エラー

ld: could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1316.0.21.2.3_0' Reader: '1300.0.29.3_0')', using libLTO version 'LLVM version 13.0.0, (clang-1300.0.29.3)' for architecture arm64

対応方法はxcodeを13.0.0から13.4.1へバージョンアップすると直った。

iosビルド時に"STATE_ERROR.VALIDATION_ERROR.90206"エラーが出るとき

詳細エラー

Invalid Bundle. The bundle at '~/Frameworks/UnityFramework.framework' contains disallowed file 'Frameworks'. With error code STATE_ERROR.VALIDATION_ERROR.90206 for id 

対応方法:xcodeの部分のBuildSetttingのBuildOptionの"Always embed swift standard libraries"が、Yesになってるので、Noへ変更。

参考:https://zenn.dev/sukedon/articles/0454e2187b08c3

自動修正する場合

未検証だけど以下を追加でもなおるかも。

Assets/Editor/XcodeSwiftVersionPostProcess.cs

using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public static class XcodeSwiftVersionPostProcess
{
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }
        var project = new PBXProject();
        project.ReadFromFile(PBXProject.GetPBXProjectPath(path));
        project.SetBuildProperty(project.GetUnityMainTargetGuid(), "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
        project.SetBuildProperty(project.GetUnityFrameworkTargetGuid(), "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES", "NO");
        project.WriteToFile(PBXProject.GetPBXProjectPath(path));
    }
}

iosビルド時に"NSPhotoLibraryUsageDescription"のエラーがメールできてるとき

詳細エラー

Missing Purpose String in Info.plist - Your app‘s code references one or more APIs that access sensitive user data. The app‘s Info.plist file should contain a NSPhotoLibraryUsageDescription key with a user-facing purpose string explaining clearly and completely why your app needs the data. If you're using external libraries or SDKs, they may reference APIs that require a purpose string. While your app might not use these APIs, a purpose string is still required.

対応方法:NSPhotoLibraryUsageDescriptionをinfo.plistへ追加

参考:https://nobushiueshi.com/unityios%E3%83%93%E3%83%AB%E3%83%89%E6%99%82%E3%81%ABnsphotolibraryaddusagedescription%E3%81%A8nsphotolibraryusagedescription%E3%82%92%E8%87%AA%E5%8B%95%E3%81%A7%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B/

iosビルド時に"You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)"エラーとなる場合

詳細エラー

error build: 'Library/Developer/Xcode/DerivedData/Unity-iPhone-gmubznzegicgstbzezoypyxvvddz/Build/Products/ReleaseForRunning-iphoneos/PromisesObjC/FBLPromises.framework/FBLPromises(FBLPromise.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file 'Library/Developer/Xcode/DerivedData/Unity-iPhone-gmubznzegicgstbzezoypyxvvddz/Build/Products/ReleaseForRunning-iphoneos/PromisesObjC/FBLPromises.framework/FBLPromises' for architecture arm64

Bitcodeを無効化すれば直る。やり方は、xcodeのTargetsをUnity-iPhone/BuildSettings/EnableBitcodeをNoにする。

参考:https://zenn.dev/dhirooka/scraps/f904ae5d101db6

info.plistの言語を日本語にする

手動設定する場合

info.plistの CFBundleDevelopmentRegionをjaへ CFBundleLocalizationsをjaへ

unityで自動で設定する場合

Assets/Editor/XcodeProjectUpdater.cs

using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System.IO;

public class XcodeProjectUpdater
{
    [PostProcessBuild]
    static void OnPostprocessBuild(BuildTarget buildTarget, string path)
    {
        if (buildTarget != BuildTarget.iOS) return;
        string plistPath = Path.Combine(path, "Info.plist");
        PlistDocument plist = new PlistDocument();
        plist.ReadFromFile(plistPath);
        plist.root.SetString ("CFBundleDevelopmentRegion", "ja");
        plist.WriteToFile(plistPath);
    }
}

参考:https://kimizuka.hatenablog.com/entry/2018/09/27/201054

xcodeのInfoPlistのTargetMembershipのUnityiPhoneにチェックを付ける

参考:https://nekosuko.jp/1802/

xcodeのbitcodeを自動でnoにする場合

Assets/Editor/XcodeBitCodeNoPostProcess.cs

using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public static class XcodeBitCodeNoPostProcess
{
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }
        var project = new PBXProject();
        project.ReadFromFile(PBXProject.GetPBXProjectPath(path));
        project.SetBuildProperty(project.GetUnityMainTargetGuid(), "ENABLE_BITCODE", "NO");
        project.SetBuildProperty(project.GetUnityFrameworkTargetGuid(), "ENABLE_BITCODE", "NO");
        project.WriteToFile(PBXProject.GetPBXProjectPath(path));
    }
}

参考:https://waken.hatenablog.com/