Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by OleksandrFirsov · Nov 05, 2014 at 08:14 PM · androidobbapk expansion files

OBB expansion files problem

Here's the deal. I've got the Google Play Obb expansion plugin. I've created build with sceneLoader as my 0 scene. I've attached DownloadObbExample script to Main Camera:

 using UnityEngine;
 using System.Collections;
 
 public class DownloadObbExample : MonoBehaviour {
     
     void OnGUI()
     {
         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);
             
             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)
                 if (GUI.Button(new Rect(10, 100, 100, 100), "Fetch OBBs"))
                     GooglePlayDownloader.FetchOBB();
         }
         
     }
 }


I didn't attach GooglePlayDownloader to MainCamera(and I don't need to).Though I modified it, by putting my key:

 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", "my key here");
         // 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";
             
         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("{0}/main.{1}.{2}.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("{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");
         }
     }
 }

Here are my player settings: Bundle ID:com.firsov.jetsim Bundle version:1 Bundle version code: 1

And here's the manifest:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest
     xmlns:android="http://schemas.android.com/apk/res/android"
     package="com.unity3d.player"
     android:installLocation="preferExternal"
     android:versionCode="1"
     android:versionName="1">
     <supports-screens
         android:smallScreens="true"
         android:normalScreens="true"
         android:largeScreens="true"
         android:xlargeScreens="true"
         android:anyDensity="true"/>
 
     <application
         android:icon="@drawable/app_icon"
         android:label="@string/app_name">
         <activity android:name="com.unity3d.player.UnityPlayerProxyActivity"
                   android:label="@string/app_name"
                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
         <activity android:name="com.unity3d.player.UnityPlayerActivity"
                   android:label="@string/app_name"
                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
         </activity>
         <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
                   android:label="@string/app_name"
                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
             <meta-data android:name="android.app.lib_name" android:value="unity" />
             <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="false" />
         </activity>
         <activity android:name="com.unity3d.player.VideoPlayer"
                   android:label="@string/app_name"
                   android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
         </activity>
         
 <!-- patched manifest starts here -->
         <activity android:name="com.unity3d.plugin.downloader.UnityDownloaderActivity" />
         <service android:name="com.unity3d.plugin.downloader.UnityDownloaderService" />
         <receiver android:name="com.unity3d.plugin.downloader.UnityAlarmReceiver" />
 
     </application>
     <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
     <uses-permission android:name="android.permission.INTERNET" />
     <uses-permission android:name="android.permission.WAKE_LOCK" />
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 </manifest>



Anybody knows what can cause the problem? Because I've been trying to figure it out for 2 days now(. And do I need to upload the game to Google Play before testing this feature?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by startvr · Dec 20, 2016 at 09:58 PM

On line 29 of the GooglePlayDownloader.cs you need to add the License key from your Google play Store listing. it can be found on the Services and API's page. it's a long string key probably 100 characters or so. This key is used to link to your project and fetch the .obb file associated with the app.

Comment
Add comment · Share
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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unity 3D split apk not loading the .OBB file 0 Answers

Android Split Binary Problem (Help Please) 1 Answer

Android APK Expansion Files Process? 3 Answers

Can't find OBB when downloaded from Play Store on some devices (4.3.1) 1 Answer

How to work with (main|patch).obb ? 2 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