Search Unity

Question Hi, AssetBundle.LoadFromFile unable read header error.

Discussion in 'Asset Database' started by sbsim, Jul 13, 2022.

  1. sbsim

    sbsim

    Joined:
    Apr 27, 2022
    Posts:
    2
    Hi, AssetBundle.Loadfromfile works normally in the editor,

    but I am getting Unable read header error in Android, can you help?

    UnityVersion is 19.4.38f1

    AssetBundle build option is here.

    DeterministicAssetBundle
    ChunkBasedCompression
    StrictMode

    Ab build target is Android

    and heres code.

    Code (CSharp):
    1. Img_Card.sprite = BundleMgr.m_Instance.FindAssetBundleSprite("card.ui", "Card_0_" + 1.ToString());
    2.  
    3.         public Sprite FindAssetBundleSprite(string strPath, string strSpriteName)
    4.         {
    5.             AssetBundle ab = null;
    6.  
    7.             StringBuilder sb = new StringBuilder();
    8.             sb.Clear();
    9.  
    10.             sb.Append(Application.persistentDataPath);
    11.             sb.Append("/AssetBundles/");
    12.  
    13.             sb.Append(strPath);
    14.             ab = AssetBundle.LoadFromFile(sb.ToString()); << error here.
    15.             m_dicBundle.Add(strPath, ab);
    16.  
    17.             foreach (Sprite sprite in ab.LoadAllAssets<Sprite>())
    18.             {
    19.                 if (sprite.name == strSpriteName)
    20.                 {
    21.                     return sprite;
    22.                 }
    23.             }
    24.  
    25.             return null;
    26.         }
    error :

    Error Unity Unable to read header from archive file: /storage/emulated/0/Android/data/com.DefaultCompany.com.unity.template.mobile2D/files/AssetBundles/card.ui

    And the asset bundle called card.ui is properly located in the location indicated in the code, and it is possible to open the file and view the contents normally.

    Add.

    Androidpermission

    <?xml version="1.0" encoding="utf-8"?>
    <!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN-->
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity3d.player" xmlns:tools="http://schemas.android.com/tools">
    <permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:protectionLevel="normal"/>
    <permission android:name="android.permission.READ_EXTERNAL_STORAGE" android:protectionLevel="normal"/>
    <permission android:name="android.permission.ACCESS_NETWORK_STATE" android:protectionLevel="normal"/>
    <permission android:name="android.permission.INTERNET" android:protectionLevel="normal"/>
    <application>
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="[USER=863766]@StyLe[/USER]/UnityThemeSelector" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:resizeableActivity="false" android:hardwareAccelerated="false">
    <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    <meta-data android:name="android.notch_support" android:value="true" />
    </activity>
    <meta-data android:name="unity.splash-mode" android:value="0" />
    <meta-data android:name="unity.splash-enable" android:value="True" />
    <meta-data android:name="unity.launch-fullscreen" android:value="True" />
    <meta-data android:name="unity.allow-resizable-window" android:value="False" />
    <meta-data android:name="notch.config" android:value="portrait|landscape" />
    <meta-data android:name="unity.build-id" android:value="8a83a561-1381-400e-9d68-4fcde27b9c18" />
    <receiver android:name="com.unity.androidnotifications.UnityNotificationManager" android:exported="true" />
    <receiver android:name="com.unity.androidnotifications.UnityNotificationRestartOnBootReceiver" android:enabled="false" android:exported="true">
    <intent-filter>
    <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
    </receiver>
    </application>
    <uses-feature android:glEsVersion="0x00030000" />
    <uses-feature android:name="android.hardware.vulkan.version" android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
    <uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    </manifest>


    Add

    My android version is 11.

    and i can write assetbundle data.

    but i can not read assetbundle.

    220715 Add

    File.ReadAllBytes read this assetbundle data.

    but AssetBundle.LoadFromFile is unable to read header.

    AssetBundle.LoadFromMemoryAsync is dinied.

    this is all same path...

    Add

    LoadFromMemory is

    Error libprocessgroup set_timerslack_ns write failed: Operation not permitted.

    and this is same path too.


    Thank you.
     
    Last edited: Jul 15, 2022
    arufolo-wellovate likes this.
  2. sbsim

    sbsim

    Joined:
    Apr 27, 2022
    Posts:
    2
    It's been resolved. Previously, when receiving the bundle patch, due to a certificate problem, the receiving part of the bundle patch was modified, but the modified part was copied and pasted on the manifest side as it is, and the manifest data was overwritten with the bundle data.