- Home /
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?
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.