Expansion file stopped working when updating APK version

Asked

Viewed 802 times

0

I recently 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 updated normally, downloaded and recognized the 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)

Updating

I added part 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" />

Someone’s been through this trouble?

Thank you very much

  • You’re putting the apk and patch version as meta-data (mainVersion and patchVersion) in the statement of its APEZProvider?

  • I couldn’t find where to set up (mainVersion and patchVersion) on Apezprovider. I own a "Providervideozipuri" class that inherits Apezprovider. In the download routines I set up the version. Interesting that by changing the version to 3, renaming the OBB to "main.3.br.com.myapp.obb" and uploading this new OBB to the store, it worked. I didn’t want to have to change the OBB every APK update. Thank you!

  • 1

    The configuration is in the manifest, inside the tag provider. In fact you would only trade one or the other. If you updated the apk version, change the mainVersion, if updated the exchange expansion the patchVersion.

  • If I understand correctly, I am declaring "Provider" without this TAG. I updated the question with parts of the code.

1 answer

1


As much thing on the Android platform, even more related to google is not always well documented, the statement of <provider> of Expansion takes two parameters. Which are used in this particular case, where the version of APK is not the same as the version of Extension.

As I said in the comments, need to put tags <meta-data> to inform 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 the APK must place the mainVersion and the patchVersion you wanted to use (the one you uploaded). Otherwise it will take over mainVersion and the patchVersion being the versionCode of your apk.

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

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

The excerpt from the code 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 the meta-data, he does the else what arrow mainFileVersion = patchFileVersion = appVersionCode. That creates the problem.

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

Source: https://stackoverflow.com/questions/10051213/accessing-apk-expansion-file-with-uri-with-google-zip-expansion-library-causes

  • Perfect !!! If you ever need to change the OBB it will go to "main.4.br.com.myapp.obb" independent of Versioncode. From what I understand, it is not necessary to declare the patchVersion metadata (if I don’t use it), correct? Thank you very much for your help !

  • That, the patchVersion do not need if you do not use. In your case, update only the mainVersion to match the value you put in the first obb. So you don’t need to upload again.

  • Okay, thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.