2

当我尝试将 APK 扩展功能添加到我当前的应用程序时,我遇到了那个烦人的编译错误。“XAPKFile 无法解析为类型”。

是我用来将 APK 扩展文件添加到我的项目中的指南。

4

2 回答 2

1

我已经用了几个小时,直到我通过谷歌找到了一个地方,有人定义了这个:

private static class XAPKFile {
        public final boolean mIsMain;
        public final int mFileVersion;
        public final long mFileSize;

        XAPKFile(boolean isMain, int fileVersion, long fileSize) {
            mIsMain = isMain;
            mFileVersion = fileVersion;
            mFileSize = fileSize;
        }
}

所以,如果你遇到同样的错误,你唯一需要检查的是你是否定义了这个类。Android 不提供它。这可能是因为您可能不想将 FileSize 放在代码中......或者只是因为有一个错误。

于 2013-03-05T15:57:32.903 回答
0

您可以在 extras 项目的SampleDownloaderActivity中找到这个类,其中还包括一个非常有用的 APK 扩展文件实现示例。如果您下载了Google Play 扩展库通过 SDK 管理器),您可以在以下位置找到它:

YourPathToAndroidSdk/extras/google/play_apk_expansion/downloader_library

为方便起见,我将此类与 XAPKFile 的 xAPKS 数组一起复制粘贴到此处(在扩展库的 v3 中可以找到):

/**
 * This is a little helper class that demonstrates simple testing of an
 * Expansion APK file delivered by Market. You may not wish to hard-code
 * things such as file lengths into your executable... and you may wish to
 * turn this code off during application development.
 */

private static class XAPKFile {
    public final boolean mIsMain;
    public final int mFileVersion;
    public final long mFileSize;

    XAPKFile(boolean isMain, int fileVersion, long fileSize) {
        mIsMain = isMain;
        mFileVersion = fileVersion;
        mFileSize = fileSize;
    }
}

/**
 * Here is where you place the data that the validator will use to determine
 * if the file was delivered correctly. This is encoded in the source code
 * so the application can easily determine whether the file has been
 * properly delivered without having to talk to the server. If the
 * application is using LVL for licensing, it may make sense to eliminate
 * these checks and to just rely on the server.
 */
private static final XAPKFile[] xAPKS = {
        new XAPKFile(
                true, // true signifies a main file
                3, // the version of the APK that the file was uploaded
                   // against
                687801613L // the length of the file in bytes
        ),
        new XAPKFile(
                false, // false signifies a patch file
                4, // the version of the APK that the patch file was uploaded
                   // against
                512860L // the length of the patch file in bytes
        )            
};
于 2015-11-13T09:54:31.053 回答