访问与URI APK扩展文件(与谷歌邮编扩展库)会导致系统崩溃,如果扩展文件的版本是APK版本code不同版本、文件、邮编、不同

2023-09-04 06:05:06 作者:Frustrated. 失落。

我的APK版本code是第3版与它我使用它装载有APK版本code 1(文件名主膨胀文件类似于main.1.ex.etc.eg.obb )。扩展文件下载优良的设备上。

My apk version code is version 3. with it I am using main expansion file which was loaded with apk version code 1 (file name is similar to main.1.ex.etc.eg.obb). The expansion file downloads fine on a device.

扩展文件有媒体文件,所以我用 APEZProvider 从谷歌邮编扩展库与 VideoView 。

The expansion file has media file, so I using APEZProvider from the Google Zip Expansion Library to play it with VideoView.

调用 VideoView.start()将导致空指针异常。

Calling VideoView.start() causes an Nullpointer exception.

我已经发现迄今: 在 APEZProvider.initIfNecessary()返回主膨胀文件的版本为3,而不是1。因此试图打开子presourceFile (mAPKExtensionFile)返回null。 APEZProvider.openAssetFile()引起 NullPointerException异常 mAPKExtensionFile

What I have found so far: In APEZProvider.initIfNecessary() returns Main expansion file version as 3 instead of 1. Thus trying to open ZipResourceFile (mAPKExtensionFile) returns null. APEZProvider.openAssetFile() causes NullPointerException as mAPKExtensionFile is null.

APEZProvider 相关code。在谷歌邮编扩展库类:

Relevant code from APEZProvider class in Google Zip Expansion Library:

  private boolean initIfNecessary() {
    if ( !mInit ) {
        Context ctx = getContext();
        PackageManager pm = ctx.getPackageManager();
        ProviderInfo pi = pm.resolveContentProvider(getAuthority(), PackageManager.GET_META_DATA);
        PackageInfo packInfo;
        try {
            packInfo = pm.getPackageInfo(ctx.getPackageName(), 0);
        } catch (NameNotFoundException e1) {
            e1.printStackTrace();
            return false;
        }
        int patchFileVersion;
        int mainFileVersion;
        int appVersionCode = packInfo.versionCode;
        if ( null != pi.metaData ) {
            mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
            patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);          
        } else {
            mainFileVersion = patchFileVersion = appVersionCode;
        }
        try {
            mAPKExtensionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainFileVersion, patchFileVersion);
            return true;
        } catch (IOException e) {
            e.printStackTrace();                
        }
    }
    return false;       
}



@Override
public AssetFileDescriptor openAssetFile(Uri uri, String mode)
        throws FileNotFoundException {
    initIfNecessary();
    String path = uri.getEncodedPath();
    if ( path.startsWith("/") ) {
        path = path.substring(1);
    }
    return mAPKExtensionFile.getAssetFileDescriptor(path);      
}

我不知道这行的code在上面: ProviderInfo PI = pm.resolveContentProvider(getAuthority(),PackageManager.GET_META_DATA); 这是是否正确?

这是为PackageManager.resolveContentProvider()。Android的参考

From Android reference for PackageManager.resolveContentProvider().

公共抽象ProviderInfo resolveContentProvider(字符串名称,诠释标志)

public abstract ProviderInfo resolveContentProvider (String name, int flags)

自:API级别1 查找它的基本路径名称中的单个内容提供商。  参数

Since: API Level 1 Find a single content provider by its base path name. Parameters

名称:寻找供应商的名称

name: The name of the provider to find.

标记:附加选项标志。目前应该始终为0。

flags: Additional option flags. Currently should always be 0.

有人可以证实,如果我做错事或者是一个错误。

Can someone confirm if i am doing something wrong or is it a bug.

编辑:一切正常,当我上传我的应用程序的第一次 - 它只有当我更新导致不同版本的codeS的APK出现此问题

everything works as expected when I upload my app for the first time - its only when I update the apk resulting in different version codes that this problem occurs.

推荐答案

ZIP文件提供者类包含元数据,你可以在你的Andr​​oidManifest.zip文件的地方,如果的APK扩展文件的版本号不匹配的版本号你的APK。

The Zip file provider class contains metadata that you can place in your AndroidManifest.zip file if the version number of the APK Expansion File does not match the version number of your APK.

<provider android:name=".APEZProvider"
              android:authorities="my.application.authority"
              android:exported="false"
              android:multiprocess="true"
    >
   <meta-data android:name="mainVersion"
              android:value="1"></meta-data>
   <meta-data android:name="patchVersion"
              android:value="2"></meta-data>
</provider>
 
精彩推荐