Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by swampman860912 · Sep 30, 2016 at 09:01 PM · c#publishingobb

Using expansion files .obb

I need some help I have been fighting this for the passed week and I am at the end of my rope. If i can't get this to work this is pretty much a make a break for my game so any help with be appreciated. I have done plenty of research online but everything i find is either out of date of gives me bits and pieces of the information i need.

I downloaded the unity plugin that helps to download the .obb file from google play. I tried to edit my android manifest file I have two inside the temp folder of my application one regular and one main which should i be editing I have no clue.

I followed the instructions on this web page: https://www.exoa.fr/tutorial-unity-4-apk-splitting-google-play-obb/ but it really only gives you bits and pieces of information.

So here is what I got here is the regular android manifest file:

 <activity android:label="@string/app_name" android:name="com.unity3d.player.UnityPlayerActivity" android:screenOrientation="sensorLandscape" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
   <intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
     <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
   </intent-filter>
   <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
 </activity>
 <activity android:name="com.unity3d.plugin.downloader.UnityDownloaderActivity" />
 <service android:name="com.unity3d.plugin.downloader.UnityDownloaderService" />
 <receiver android:name="com.unity3d.plugin.downloader.UnityAlarmReceiver" />
  
  
  
  
  
  
  
  
  
  
  
  


and here is the main andriodmanifest file:

 <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name">
   <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" />
 </activity>
  
  


Here is DownloadOBBexample edited:

using UnityEngine; using System.Collections; using TMPro; using MadLevelManager;

public class DownloadObbExample : MonoBehaviour {

 private string expPath;
 private string logtxt;
 private bool alreadyLogged = false;
 private string nextScene = "Splash";
 private bool downloadStarted;


 public string line00;
 public string line01;
 public string line02;
 public string line03;
 public TextMeshProUGUI words;

 //public Texture2D background;
 //public GUISkin mySkin;

 void Start ()
 {
     words.GetComponent<TextMeshPro> ();
     words.text = "";

 }

 void Update()
 {

     if (!GooglePlayDownloader.RunningOnAndroid ()) 
     {
         words.GetComponent<TextMeshPro> ();
         words.text = line00;

     }

     string expPath = GooglePlayDownloader.GetExpansionFilePath();

     if (expPath == null)
     {
         words.GetComponent<TextMeshPro> ();
         words.text = line01;
         //GUI.Label(new Rect(10, 10, Screen.width-10, 20), "External storage is not available!");
     }
     else
     {
         string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
         string patchPath = GooglePlayDownloader.GetPatchOBBPath(expPath);

         if( alreadyLogged == false )
         {
             alreadyLogged = true;
             log( "expPath = "  + expPath );
             log( "Main = "  + mainPath );
             log( "Main = " + mainPath.Substring(expPath.Length));

             if (mainPath != null)
                 StartCoroutine(loadLevel());

         }


         //GUI.Label(new Rect(10, 10, Screen.width-10, 20), "Main = ..."  + ( mainPath == null ? " NOT AVAILABLE" :  mainPath.Substring(expPath.Length)));
         //GUI.Label(new Rect(10, 25, Screen.width-10, 20), "Patch = ..." + (patchPath == null ? " NOT AVAILABLE" : patchPath.Substring(expPath.Length)));
         if (mainPath == null || patchPath == null)

             words.GetComponent<TextMeshPro> ();
             words.text = line02;

             GooglePlayDownloader.FetchOBB();
              StartCoroutine(loadLevel());

             //GUI.Label(new Rect(Screen.width-600, Screen.height-230, 430, 60), "The game needs to download 200MB of game content. It's recommanded to use WIFI connexion.");


     }

 }



 void log( string t )
 {
     logtxt += t + "\n";
     print("MYLOG " + t);
 }




 //void OnGUI()
 //{

     //GUI.skin = mySkin;
     //GUI.DrawTexture(new Rect(0,0,background.width,background.height),background);

 //
     //if (!GooglePlayDownloader.RunningOnAndroid())
     //{
     //    GUI.Label(new Rect(10, 10, Screen.width-10, 20), "Use GooglePlayDownloader only on Android device!");
     //    return;
     //}
     
     //string expPath = GooglePlayDownloader.GetExpansionFilePath();
     //if (expPath == null)
     //{
     //        GUI.Label(new Rect(10, 10, Screen.width-10, 20), "External storage is not available!");
     //}
     //else
     //{
     //    string mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);
     //    string patchPath = GooglePlayDownloader.GetPatchOBBPath(expPath);

     //    if( alreadyLogged == false )
     //    {
     //        alreadyLogged = true;
     //        log( "expPath = "  + expPath );
     //        log( "Main = "  + mainPath );
     //        log( "Main = " + mainPath.Substring(expPath.Length));

     //        if (mainPath != null)
     //            StartCoroutine(loadLevel());

     //    }

         
         //GUI.Label(new Rect(10, 10, Screen.width-10, 20), "Main = ..."  + ( mainPath == null ? " NOT AVAILABLE" :  mainPath.Substring(expPath.Length)));
         //GUI.Label(new Rect(10, 25, Screen.width-10, 20), "Patch = ..." + (patchPath == null ? " NOT AVAILABLE" : patchPath.Substring(expPath.Length)));
     //    if (mainPath == null || patchPath == null)

     //        GUI.Label(new Rect(Screen.width-600, Screen.height-230, 430, 60), "The game needs to download 200MB of game content. It's recommanded to use WIFI connexion.");

     //    if (GUI.Button(new Rect(Screen.width-500, Screen.height-170, 250, 60), "Start Download !"))
     //    {
     //        GooglePlayDownloader.FetchOBB();
     //        StartCoroutine(loadLevel());
     //}
     //}

 //}

 protected IEnumerator loadLevel() 
 { 
     string mainPath;
     do
     {
         yield return new WaitForSeconds(0.5f);
         mainPath = GooglePlayDownloader.GetMainOBBPath(expPath);    
         log("waiting mainPath "+mainPath);
     }
     while( mainPath == null);

     if( downloadStarted == false )
     {
         downloadStarted = true;
         string uri = "file://" + mainPath;
         //string uri = "file://" + mainPath;
         log("downloading " + uri);
         WWW www = WWW.LoadFromCacheOrDownload(uri , 0);        

         // Wait for download to complete
         yield return www;

         if (www.error != null)
         {
             log ("wwww error " + www.error);
         }
         else
         {
             MadLevel.LoadLevelByName (nextScene);
         }
     }
 }

}

Here is my GooglePlayDownloader script edited:

using UnityEngine; using System.Collections; using System.IO; using System;

public class GooglePlayDownloader { private static AndroidJavaClass detectAndroidJNI; public static bool RunningOnAndroid() { if (detectAndroidJNI == null) detectAndroidJNI = new AndroidJavaClass("android.os.Build"); return detectAndroidJNI.GetRawClass() != IntPtr.Zero; }

 private static AndroidJavaClass Environment;
 private const string Environment_MEDIA_MOUNTED = "mounted";

 static GooglePlayDownloader()
 {
     if (!RunningOnAndroid())
         return;

     Environment = new AndroidJavaClass("android.os.Environment");
     
     using (AndroidJavaClass dl_service = new AndroidJavaClass("com.unity3d.plugin.downloader.UnityDownloaderService"))
     {
     // stuff for LVL -- MODIFY FOR YOUR APPLICATION!
         dl_service.SetStatic("BASE64_PUBLIC_KEY", "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAohYcx5dRdrmzZk3wWv2Ao01NzsfMkzWENaYNme+246avxyu6v2a+cxvq6XtKTh062d5IRQVRU7pXfmyeMNTugnd4b5KqCS3t6Gx7yxGfLY831P+hYgwxCw3NsvBrCnribNDLlAiyC/l0naDQW+Iw7ZhTLprfU/BrpyCRQjkQUGcXVgxMLJjFwJa3jKjKTxESZnKZlHwcP48DCxromQ1brymvtUbiMVpPWte3z1FNbpj6ZW4a5h10LHYJ+bfpOtQUhwuKe7624TWhkZaA534rUSusZzAfGQ/JNc3S3Q5DG2/objLe+fKOSRlzHU6Hu6ww2Inl3owDmPEC+ItHOh3V/wIDAQAB");
     // used by the preference obfuscater
         dl_service.SetStatic("SALT", new byte[]{1, 43, 256-12, 256-1, 54, 98, 256-100, 256-12, 43, 2, 256-8, 256-4, 9, 5, 256-106, 256-108, 256-33, 45, 256-1, 84});
     }
 }
 
 public static string GetExpansionFilePath()
 {
     populateOBBData();

     if (Environment.CallStatic<string>("getExternalStorageState") != Environment_MEDIA_MOUNTED)
         return null;
         
     const string obbPath = "Android/obb/main.2.com.SwampWare.JeanPierre.obb";
         
     using (AndroidJavaObject externalStorageDirectory = Environment.CallStatic<AndroidJavaObject>("getExternalStorageDirectory"))
     {
         string root = externalStorageDirectory.Call<string>("getPath");
         return String.Format("{0}/{1}/{2}", root, obbPath, obb_package);
     }
 }
 public static string GetMainOBBPath(string expansionFilePath)
 {
     populateOBBData();

     if (expansionFilePath == null)
         return null;
     string main = String.Format("main.7.com.SwampWare.JeanPierre.obb", expansionFilePath, obb_version, obb_package);
     if (!File.Exists(main))
         return null;
     return main;
 }
 public static string GetPatchOBBPath(string expansionFilePath)
 {
     populateOBBData();

     if (expansionFilePath == null)
         return null;
     string main = String.Format("main.7.com.SwampWare.JeanPierre.obb", expansionFilePath, obb_version, obb_package);
     //string main = String.Format("{0}/patch.{1}.{2}.obb", expansionFilePath, obb_version, obb_package);
     if (!File.Exists(main))
         return null;
     return main;
 }
 public static void FetchOBB()
 {
     using (AndroidJavaClass unity_player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
     {
         AndroidJavaObject current_activity = unity_player.GetStatic<AndroidJavaObject>("currentActivity");
 
         AndroidJavaObject intent = new AndroidJavaObject("android.content.Intent",
                                                         current_activity,
                                                         new AndroidJavaClass("com.unity3d.plugin.downloader.UnityDownloaderActivity"));
 
         int Intent_FLAG_ACTIVITY_NO_ANIMATION = 0x10000;
         intent.Call<AndroidJavaObject>("addFlags", Intent_FLAG_ACTIVITY_NO_ANIMATION);
         intent.Call<AndroidJavaObject>("putExtra", "unityplayer.Activity", 
                                                     current_activity.Call<AndroidJavaObject>("getClass").Call<string>("getName"));
         current_activity.Call("startActivity", intent);
 
         if (AndroidJNI.ExceptionOccurred() != System.IntPtr.Zero)
         {
             Debug.LogError("Exception occurred while attempting to start DownloaderActivity - is the AndroidManifest.xml incorrect?");
             AndroidJNI.ExceptionDescribe();
             AndroidJNI.ExceptionClear();
         }
     }
 }
 
 // This code will reuse the package version from the .apk when looking for the .obb
 // Modify as appropriate
 private static string obb_package;
 private static int obb_version = 0;
 private static void populateOBBData()
 {
     if (obb_version != 0)
         return;
     using (AndroidJavaClass unity_player = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
     {
         AndroidJavaObject current_activity = unity_player.GetStatic<AndroidJavaObject>("currentActivity");
         obb_package = current_activity.Call<string>("getPackageName");
         AndroidJavaObject package_info = current_activity.Call<AndroidJavaObject>("getPackageManager").Call<AndroidJavaObject>("getPackageInfo", obb_package, 0);
         obb_version = package_info.Get<int>("versionCode");
     }
 }

}

I am not sure whats going on but I have the application published and when I install it on my device it makes it to the first scene and the unity screen blinks like its downloading something and it just sits there. Its kind of hard to trouble shoot when i cannot see what is in the console any recommendations on troubleshooting options or tutorials on this would be greatly appreciated.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
â–¼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

243 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issues publishing to Google Play with OBB expansion files using Gradle 0 Answers

Unfortunately, (GameName) has stopped (report ,ok) 0 Answers

Executable published for Linux are very slow to start 0 Answers

Trying to create a freaking math clone. new learner and very low coding skills. Having trouble with setting the time limit for the process.Need Help? 1 Answer

Save a list for refrence? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges