getAPKExpansionZipFile()返回null [英] getAPKExpansionZipFile() returns null

查看:804
本文介绍了getAPKExpansionZipFile()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的比赛有100兆,我需要使用扩展文件。我把低于code在MainActivity在功能上的onCreate()

Since my game has 100Mb I need to use expansion file. I put below code in the MainActivity in function onCreate()

    ZipResourceFile expansionFile = null;

    try {
        expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getApplicationContext(),2,0);
    } catch (IOException e) {
        e.printStackTrace();
    }

我不使用补丁扩展文件,只要主,所以我想将0作为一个版本是正确的。当我登录检查expansionFile加载成功,我得到空值。

I don't use patch expansion file, just main, so I guess putting 0 as a version is correct. When I log to check if expansionFile was successfully loaded I get null value.

    if(expansionFile == null)
        Gdx.app.log("EXPANSION_FILE", "NULL");
    else
        Gdx.app.log("EXPANSION_FILE", "NOT NULL");

我也跟着在 https://developer.android.com/google/说明播放/膨胀files.html
我把手工main.2.com.my.game.obb文件夹我的Nexus设备上:

I followed instructions on https://developer.android.com/google/play/expansion-files.html and I put manually main.2.com.my.game.obb file in folder on my Nexus device:

Internal storage\Android\obb\com.my.game\

有Android中\\ OBB从其他游戏文件夹以外OBB文件,所以这是一个正确的地方。它为什么不装入OBB扩展文件任何线索?

There are other obb files in Android\obb folder from other games, so this has to be a correct place. Any clues of why it doesn't mount the obb expansion file?

更新

我实施 DownloaderActivity 并下载扩展文件没有任何问题。这是给我不是一个zip压缩包日志信息。我找到了一种方法,以避免它。我压缩文件OBB并将其上传到开发者控制台。它会自动转换成OBB反正但是这一次,当我下载了它在我的Nexus它不再让我对子presourceFile 空值,它并没有给我没有一个zip压缩文件的消息了。但我仍无法从它,因为我使用的AssetManager从Libgdx访问文件。

I implemented DownloaderActivity and it downloads expansion file without any problems. It was giving me "Not a zip archive" log message. I found a way to avoid it. I zipped OBB file and uploaded it to Developer Console. It automatically converted into OBB anyway but this time when I downloaded it on my Nexus it no longer gives me null value for ZipResourceFile and it doesn't give me "Not a zip archive" message anymore. But still I can't access files from it since I'm using AssetManager from Libgdx.

我找到了另一种方式,而我现在正在测​​试。

I found another way, which I'm testing now.

推荐答案

解决方案到getAPKExpansionZipFile()返回null是不使用JOBB工具,但压缩所有内容并上传的问题。谷歌播放会自动将其转换为OBB。

Solution to the problem where getAPKExpansionZipFile() returns null is to not use JOBB tool, but zip all the content and upload it. Google Play will convert it automatically to the OBB.

的完整解决方案,从扩展文件加载图片:

我创造了我自己的游戏类的静态变量,它是子presourceFile 的一个实例。我做了静态的,因为我想加载 MainActivity 类的扩展文件,并用它在我的的FileHandle 类从它那里得到的图像。如果你找到一个不同的方式,它是给你的。这是我做的。

I created a static variable in my own Game class which is an instance of ZipResourceFile . I made it static, because I wanted to load the expansion file in MainActivity class and use it in my FileHandle class to get images from it. If you find a different way it's up to you. This is how I did it.

公共静态子presourceFile expansionFile;

public static ZipResourceFile expansionFile;

然后在你的 MainActivity 类加载扩展文件。我做它的OnCreate()函数。

Then in your MainActivity class load expansion file. I did it in OnCreate() function.

    try {
        GameInfo.expansionFile = APKExpansionSupport.getAPKExpansionZipFile(getBaseContext(),22,0);     
    } catch (IOException e) {
        e.printStackTrace();
    }

传递值的功能是这些:

Passed values to the function are these:

getAPKExpansionZipFile(Context ctx, int mainVersion, int patchVersion)

mainVersion需要是完全相同的清单文件宣称:

mainVersion needs to be exactly the same as declared in Manifest file :

android:versionCode="22"

此外,您的扩展文件需要有在其名称相同数量的:

Also your expansion file needs to have the same number in its name:

main.mainVersion.com.name.title

创建您自己的FileHandle类。这是它看起来在扩展文件如image.png你的具体文件。

Create your own FileHandle class. This is where it looks for your specific file for example "image.png" in the expansion file.

public class CustomFileHandle extends FileHandle
{
    public CustomFileHandle (String fileName) {     
        super(fileName);
    }

    @Override
    public InputStream read()
    {
        InputStream input = null;

        try {           
            input = GameInfo.expansionFile.getInputStream(file.getPath().replace('\\', '/'));
        } catch (IOException e) {
            e.printStackTrace();
        }   
        return input;
    }
}

创建自己的FileHandleResolver类。这就是你使用自定义的FileHandle。

Create your own FileHandleResolver class. This is where you use your custom FileHandle.

public class CustomFileHandleResolver implements FileHandleResolver
{
    @Override
    public FileHandle resolve(String fileName) {
        return new CustomFileHandle(fileName);
    }
}

创建AssetManager的实例和FileHandleResolver传递给构造函数。

Create instance of AssetManager and pass your FileHandleResolver to constructor.

assetManager = new AssetManager(new CustomFileHandleResolver());

如果我没有漏掉任何一步那么这就是你需要做的,从扩展文件加载文件的内容。正如我在开始时提到的我发现这个问题用JOBB工具收拾文件到OBB文件。它使getAPKExpansionZipFile()返回NULL。所以我只是压缩所有文件来代替。看看这里更详细的解释: https://developer.android.com/google/播放/膨胀files.html

If I did not omit any step then this is what you need to do to load your files from expansion file. As I mentioned in the begining I found the problem with using JOBB Tool to pack the files into OBB file. It makes getAPKExpansionZipFile() to return null. So I just zipped all the files instead. Look here for more detailed explanation : https://developer.android.com/google/play/expansion-files.html

这篇关于getAPKExpansionZipFile()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆