Expansion file stopped working when you upgraded version of APK

0

Recently I updated an APK and chose the option to reuse the expansion file (this file contains videos).

Old Version

1(1.0.0) -> main.1.br.com.myapp.obb

New version

2(1.0.1) -> selecionei o mesmo

After propagating in the store (Google Play), the application has updated normally, downloaded and recognized OBB. But when I play the video, the application ends with the error below:

E/AndroidRuntime(12752): java.lang.NullPointerException
E/AndroidRuntime(12752): at com.android.vending.expansion.zipfile.APEZProvider.openAssetFile(APEZProvider.java:182)

Update

I've added some of the files to help identify the error.

ProviderVideoZipUri.java

public class ProviderVideoZipUri extends APEZProvider {
  @Override
  public String getAuthority(){
    return "br.com.appname.provider.ProviderVideoZipUri";
  }
}

AndroidManifest.xml

<provider
    android:name="br.com.appname.provider.ProviderVideoZipUri"
    android:authorities="br.com.appname.provider.ProviderVideoZipUri"
    android:exported="false" />

Has anyone ever had this problem?

Thank you very much

    
asked by anonymous 01.09.2014 / 21:57

1 answer

1

As much on the Android platform, even more related to google is not always well documented, the <provider> expansion statement gets two parameters. In particular, where the APK version is not the same as the Extension version.

As I said in the comments, you need to put <meta-data> tags to inform the versions.

<provider
    android:name="br.com.appname.provider.ProviderVideoZipUri"
    android:authorities="br.com.appname.provider.ProviderVideoZipUri"
    android:exported="false">

    <meta-data android:name="mainVersion" android:value="1"></meta-data>
    <meta-data android:name="patchVersion" android:value="2"></meta-data>
</provider>

Whenever you update APK you should put the mainVersion and patchVersion you wanted to use (the one you uploaded). Otherwise it will assume mainVersion and patchVersion being versionCode of your apk.

In the case of the next update, you will have mainVersion = 1 and patchVersion = 1 .

Note: In the source code of APEZProvider , it uses these two meta-data .

The code snippet is:

int patchFileVersion;
int mainFileVersion;
int appVersionCode = packInfo.versionCode;
String[] resourceFiles = null;
if ( null != pi.metaData ) {
    mainFileVersion = pi.metaData.getInt("mainVersion", appVersionCode);
    patchFileVersion = pi.metaData.getInt("patchVersion", appVersionCode);
    String mainFileName = pi.metaData.getString("mainFilename", NO_FILE);
    if ( NO_FILE != mainFileName ) {
        String patchFileName = pi.metaData.getString("patchFilename", NO_FILE);
        if ( NO_FILE != patchFileName ) {
            resourceFiles = new String[] { mainFileName, patchFileName };
        } else {
            resourceFiles = new String[] { mainFileName };
        }
    }
} else {
    mainFileVersion = patchFileVersion = appVersionCode;
}

In fact, if you do not declare meta-data , it does else than mainFileVersion = patchFileVersion = appVersionCode . That generates the problem.

The rest of the code is available here , as I do not know the validity of the link, I made a copy at GIST .

Source: link

    
03.09.2014 / 15:19