Expansion file downloaded but not there

喜夏-厌秋 提交于 2019-12-03 07:14:08

I know this answer doesn't address the underlying problem, but I thought this explanation might help others like me who have been confused by the responses from the downloader library:

The downloader service will (somewhat un-intuitively) pass STATE_COMPLETED to onDownloadStateChanged() when the Google Licensing server informs it that there are no expansion files associated with the app. Since it has to make an async call to the server to find this out, it can't just return NO_DOWNLOAD_REQUIRED directly from startDownloadServiceIfRequired(). It has to start the service to consult the server.

But it seems it will only do this the first time you call the download service after your app is installed - after that, it caches the response from the licensing server in a local database, and future calls to startDownloadServiceIfRequired() will immediately return NO_DOWNLOAD_REQUIRED.

Response code 256 corresponds to Policy.LICENSED, meaning the package name and public key are valid, but the lack of any FILE_URL suggests that Google Play thinks there is no expansion file for the app.

In my case, my expansion file worked when the app was in draft, but once published, it effectively disappeared from the store. I have not been able to determine why.

It's probably because the file was found to be "incomplete" when doing checks after completion, and was then deleted.

One possibility is the downloaded file's length is different than the one you provided to android.vending/expansion/downloader.Helpers.deosFileExist(Context, String, long, boolean), so first check to see the provided value matches the actual value.

If this doesn't resolve the issue, then consider adding breakpoint to all File delete calls and see if any of them are triggered.

Ruben Flores

After few days searching by a solution, I found the error for my case.

Using LicenseChecker, I saw the listener callback an applicationError with code 3. Here code:

        aep = new APKExpansionPolicy(this,
            new AESObfuscator(ContentDownloaderService.SALT, getPackageName(), deviceId));

        aep.resetPolicy();    

        checker = new LicenseChecker(this, aep,
            BASE64_PUBLIC_KEY // Your public licensing key.
        );

        checker.checkAccess(new LicenseCheckerCallback() {
        @Override
        public void allow(int reason) {
            System.out.println("Allow Reason "+reason);
        }

        @Override
        public void dontAllow(int reason) {
            System.out.println("Don't Allow Reason "+reason);
            try {
                switch (reason) {
                    case Policy.NOT_LICENSED:
                        System.out.println("Not licensed");
                        break;
                    case Policy.RETRY:
                        System.out.println("Retry");
                        break;
                }
            } finally {
            }

        }

        @Override
        public void applicationError(int errorCode) {
            System.out.println("aplication error "+errorCode);
        }

    });

Error Code 3 is ERROR_NOT_MARKET_MANAGED, you can see complete list of error here https://developer.android.com/google/play/licensing/licensing-reference.html#server-response-codes, and here I can get information about that error mean How do you deal with LicenseCheckerCallback.ERROR_NOT_MARKET_MANAGED error code?

Summary, that happened because my local version is not the same version on google console, and happened to me because my versionCode is generated by a script like this:

def getBuildVersionCode() {
   def date = new Date()
   def formattedDate = date.format('yyMMddHHmm')

   return (formattedDate as int) + 221066279;    
}

def getBuildVersionName() {
return getBuildVersionCode().toString();
}

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
    applicationId "com.test.testing"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode getBuildVersionCode()
    versionName getBuildVersionName()
}

So every time than I compile I'm getting a new version and obviously that version it isn't on google console.

I changed my gradle script to:

    android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
    applicationId "com.test.testing"
    minSdkVersion 15
    targetSdkVersion 21
    versionCode 1731227595 // My actual version number of apk in google developer console.
    versionName 1731227595 
}

And that saved my life, I hope this answer can be usefulness to anyone more..

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