android - so many problems with the expansion library

感情迁移 提交于 2019-12-03 07:06:32

问题


i need to use the new google-play (or market) expansion library , and i have hard time with it . i wonder if anyone else is using it and notice the same problems i can see , so i would be very happy if you could help be to fix them:

1.sometimes i don't get important events (errors, for example) back to the downloader activity .

2.it doesn't work at all on some devices , like xoom . i think i've fixed it: Download expansion files on tablet

3.even for identical devices , one can download the file and the other can always get a connection error. for some devices , it will never never be able to download (even non-rooted devices which have the google-play app) .

4.after the download is complete , the file can be corrupted , so i need to use CRC check and re-download everything again .

5.notification sometimes opens multiple instances of the downloader activity upon pressing it. also , i don't get why they let the notification stay in case the activity is still shown .

6.when an error occurs and later handled , it doesn't wait for the user to tell it to resume . i'm not sure in which cases it occur , but it's really weird and unpredictable.

7.upon leaving the downloader activity , i get an exception of a leaking service .

8.upon obfuscating of the app , it crashes because of SQL operations done via the library . how and why is that? EDIT: this is because google decided to make some reflections operations on the SQL part (in the file "DownloadsDB.java") . in order to fix it , i've tried to set proguard to ignore the entire library (it's open source anyway) , but it didn't work , so what i did is to give the classes it wants by myself , so i've replaced "DownloadsDB.class.getDeclaredClasses()" with "new Class[] {MetadataColumns.class, DownloadColumns.class};" .

i just don't get why couldn't google just publish a simple API to send an intent to the market to download the file and check if it's ok , or provide a much less complex library . because of the complexity , it's very hard to find and fix their bugs .

my question is: has anyone else tried this library , and has someone else been successfull in using it without any problems? if so, please publish the solution...


EDIT: it seems google has updated its library (to version 2) .

they claim the next changes:

  • List item
  • Patch file now gets downloaded.
  • Honeycomb devices now supported with ICS-like notifications
  • CRC check (from sample) now supports compressed Zip files
  • Use of reflection removed to allow easy obfuscation
  • Service leak fixed
  • Unprintable character removed from ZipResourceFile
  • Minor formatting changes
  • Additional comments and edits to this file

i've tested it now , and it seems that they are almost there .

the only bug i've found is that if i update the expansion file (and the APK&filesize&CRC) , the download starts but it didn't remove the older expansion file.

also , the notification shows the current time instead of , well , anything else that could be related to the download.

for now , since i have only one expansion , i do the next check each time i get the STATE_COMPLETED state from the service . i hope it doesn't have any other problems :

private void deleteOldExpansionFile()
{
  int fileVersion = 0;
  final int versionCode = App.getAppVersionCode(DownloaderActivity.this);
  fileVersion = versionCode;
  final String fileName = Helpers.getExpansionAPKFileName(this, true, fileVersion); //get the expansion file name based on the build version of the app.
  final File newFile = new File(Helpers.generateSaveFileName(this, fileName));
  final File[] listFiles = newFile.getParentFile().listFiles();
  for (final File file:listFiles)
  {
    final String name = file.getName();
    if (name.startsWith(fileName))
      continue;
    file.delete();
  }
}

回答1:


. hello ! For the CRC Check Fail, I have experienced the issue too. The thing that resolved it for me was to make the archive of my expansion file with 7zip, in zip format with no compression at all (store).

like this: http://floy.fr/perso/floy/expfiles/crc.PNG

Now the CRC is working like a charm for me !

I agree with you .. this library is very painful to use ..




回答2:


The code doesn't support validation of Zip files that contain compressed files. Replace the doInBackground loop from the validation function in order to make it validate CRC's in Zip files correctly. Note that you cannot stream video/audio playback from files stored compressed in Zip files.

        @Override
        protected Boolean doInBackground(Object... params) {
            for (XAPKFile xf : xAPKS) {
                String fileName = Helpers.getExpansionAPKFileName(SampleDownloaderActivity.this,
                        xf.mIsMain, xf.mFileVersion);
                if (!Helpers.doesFileExist(SampleDownloaderActivity.this, fileName,
                        xf.mFileSize, false))
                    return false;
                fileName = Helpers
                        .generateSaveFileName(SampleDownloaderActivity.this, fileName);
                ZipResourceFile zrf;
                byte[] buf = new byte[1024 * 256];
                try {
                    zrf = new ZipResourceFile(fileName);
                    ZipEntryRO[] entries = zrf.getAllEntries();
                    /**
                     * First calculate the total compressed length
                     */
                    long totalCompressedLength = 0;
                    for (ZipEntryRO entry : entries) {
                        totalCompressedLength += entry.mCompressedLength;
                    }
                    float averageVerifySpeed = 0;
                    long totalBytesRemaining = totalCompressedLength;
                    long timeRemaining;
                    /**
                     * Then calculate a CRC for every file in the
                     * Zip file, comparing it to what is stored in
                     * the Zip directory. Note that for compressed
                     * Zip files we must extract the contents to do
                     * this comparison.
                     */
                    for (ZipEntryRO entry : entries) {
                        if (-1 != entry.mCRC32) {
                            long length = entry.mUncompressedLength;
                            CRC32 crc = new CRC32();
                            DataInputStream dis = null;
                            try {
                                dis = new DataInputStream(
                                        zrf.getInputStream(entry.mFileName));

                                long startTime = SystemClock.uptimeMillis();
                                while (length > 0) {
                                    int seek = (int) (length > buf.length ? buf.length
                                            : length);
                                    dis.readFully(buf, 0, seek);
                                    crc.update(buf, 0, seek);
                                    length -= seek;
                                    long currentTime = SystemClock.uptimeMillis();
                                    long timePassed = currentTime - startTime;
                                    if (timePassed > 0) {
                                        float currentSpeedSample = (float) seek
                                                / (float) timePassed;
                                        if (0 != averageVerifySpeed) {
                                            averageVerifySpeed = SMOOTHING_FACTOR
                                                    * currentSpeedSample
                                                    + (1 - SMOOTHING_FACTOR)
                                                    * averageVerifySpeed;
                                        } else {
                                            averageVerifySpeed = currentSpeedSample;
                                        }
                                        totalBytesRemaining -= seek;
                                        timeRemaining = (long) (totalBytesRemaining / averageVerifySpeed);
                                        this.publishProgress(
                                                new DownloadProgressInfo(
                                                        totalCompressedLength,
                                                        totalCompressedLength
                                                                - totalBytesRemaining,
                                                        timeRemaining,
                                                        averageVerifySpeed)
                                                );
                                    }
                                    startTime = currentTime;
                                    if (mCancelValidation)
                                        return true;
                                }
                                if (crc.getValue() != entry.mCRC32) {
                                    Log.e(Constants.TAG,
                                            "CRC does not match for entry: "
                                                    + entry.mFileName);
                                    Log.e(Constants.TAG,
                                            "In file: " + entry.getZipFileName());
                                    return false;
                                }
                            } finally {
                                if (null != dis) {
                                    dis.close();
                                }
                            }
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    return false;
                }
            }
            return true;
        }


来源:https://stackoverflow.com/questions/9874536/android-so-many-problems-with-the-expansion-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!