Reputation: 566
I've met with another strange issue with APK Expansion files (.obb-files). My expansion file mounts fine on all my test devices:
I've created encrypted .obb file with jobb-utilite:
jobb -o obb-filename -d files-dir -k password -pn applicationId -pv versionCode
In my app I read .obb file with following code:
public void initialize(final Context context) {
final StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
final File mainObbFile = getMainObbFile();
final OnObbStateChangeListener listener = new OnObbStateChangeListener() {
@Override
public void onObbStateChange(String path, int state) {
super.onObbStateChange(path, state);
if (state == OnObbStateChangeListener.MOUNTED) {
// work with obb file
} else {
throw new RuntimeException("OnObbStateChangeListener::onObbStateChange - can't mount .obb file (state = " + state + ").");
}
}
};
final String key = BuildConfig.MAIN_XAPK_KEY;
if (storageManager.isObbMounted(mainObbFile.getAbsolutePath())) {
// work with obb file
} else if (!storageManager.mountObb(mainObbFile.getAbsolutePath(), key, listener)) {
throw new RuntimeException("Can't create listener for mounting .obb file.");
}
}
And everything works fine. But on Meizu m3 note (API 22) we got strange error: "OnObbStateChangeListener::onObbStateChange - can't mount .obb file (state = 21)".
Previously, I have met with this problem and it was solved with another generation of .obb-file. But in this case it did not help. Also, I've tried to generate .obb file with fixed jobb tool (https://github.com/monkey0506/jobbifier.git), and it doesn't work.
May be anyone knows, what's wrong, why sometimes .obb files doesn't work on some devices?..
UPDATE
Also, I've checked mounting of non-encrypted .obb file on Meizu. It works.
Thanks in advance.
Upvotes: 7
Views: 959
Reputation: 5587
I got same problem with Error code 21
i removed the -k password
from:
jobb -o obb-filename -d files-dir -pn applicationId -pv versionCode
and passed null in mountObb
method instead password
storageManager.mountObb(mainObbFile.getAbsolutePath(), null, listener)
I don't know why jobb
not work with password, if someone know please share.
Upvotes: 0
Reputation: 2115
I had the same problem, and i figured out that many times Error 21 is caused by Linux Files Permissions over the obb, and the problem is that Android cannot have access to it so the StorageManager launches Error 21. When you create the .obb file, change permissions and user group to the file, something like:
$chmod 664 <obb-filename>.obb
$chown user:group <obb-filename>.obb
Then try again, worked for me.
Upvotes: 2