Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAIN_VERSION can be more than 1 #3

Open
psyon opened this issue Jul 25, 2014 · 65 comments
Open

MAIN_VERSION can be more than 1 #3

psyon opened this issue Jul 25, 2014 · 65 comments

Comments

@psyon
Copy link

psyon commented Jul 25, 2014

Simply setting MAIN_VERSION to 1 and the PATCH_VERSION to my version code (20140723) worked to make the app download the expansion file, but it did not work to access the file. I had to set MAIN_VERSION to the same version as PATCH_VERSION for it to work.

@moust
Copy link
Owner

moust commented Jul 25, 2014

According to the getExpansionAPKFileName method of com.google.android.vending.expansion.downloader.Helpers class, MAIN_VERSION should be a boolean and defined to true for main file or false for patch file.

I'm not sure of the solution because I have rarely used it, but I think you have to set MAIN_VERSION to 0.

@psyon
Copy link
Author

psyon commented Jul 25, 2014

https://code.google.com/p/dnd-aac/source/browse/trunk/Google+Play+Zip+Library/src/com/android/vending/expansion/zipfile/APKExpansionSupport.java?r=41

That doesn't seem to match up with their code in APKExpansionSupport.getAPKExpansionFiles which uses mainVersion directly to create the file name.

And actually, I think where you use

String fileName = Helpers.getExpansionAPKFileName(ctx, true, patchVersion);

I am not sure if that is even needed. Everything I have seen for documentation for getAssetFileDescriptor says to just pass a filename relative to the root of the zip, so just this

AssetFileDescriptor fileDescriptor = expansionFile.getAssetFileDescriptor(filename);

Maybe thing's have changed from when thish was updated from Android Market to Google Play?

@psyon
Copy link
Author

psyon commented Jul 25, 2014

Looking closer at Helper.getExpansionAPKFileName, it looks like you are simply supposed to pass a boolean variable to it to say whether or not you want the main file, or the patch file, but that is unrelated to MAIN_VERSION in your code.

@moust
Copy link
Owner

moust commented Jul 28, 2014

I never took a deeper look at this api so maybe it's not the right way to do.
For the moment I haven't the time to dig up this problem. Can you try to fix it with your suggestion and to create a pull request if you find the solution ?

@psyon
Copy link
Author

psyon commented Jul 28, 2014

Yes, I will try to get a pull request done soon. Also, It's probably worth including a class to extend the APEZProvider class, so that the contents of a zip file can be accessed with URLs. Using XAPReader.get() was slow for many images, but using the provider class, I was able to set images to content://com.my.app.expansion/photos/photo.jpg and have them load fine.

@psyon
Copy link
Author

psyon commented Aug 14, 2014

Sorry for the delay on this. I have a fork done, with all the code changes, but want to make sure it's well tested first, and I had a large project come up for work.

@adys123
Copy link

adys123 commented Aug 19, 2014

Hi psyon.
I saw that you have managed to make this plugin to work.
I want to ask you: how you managed to display the images, because I don't understand. I tried everything, but nothing works. I see in tutorial this step:

XAPKReader.get(
'image.jpg',
function (url) {
var img = new Image();
img.src = url;
document.body.appendChild(img);
},
function (error) {
console.error(error);
},
'image/jpeg'
);

Where exactly I must write this?

Thanks.

@psyon
Copy link
Author

psyon commented Aug 19, 2014

I used the APEZProvider class.

https://github.com/psyon/phonegap-xapkreader/blob/psyon-fixes/src/android/XAPKProvider.java

I will have a pull request soon to make sure this gets into Mousts code, but for now you can drop that file into the plugin directory. With that file in place, you would have to add this to AndroidManifest.xml

<provider android:authorities="org.apache.cordova.xapkreader.expansion" android:exported="false" android:multiprocess="true" android:name="org.apache.xapkreader.XAPKProvider">
    <meta-data android:name="mainVersion" android:value="$MAIN_VERSION" />
    <meta-data android:name="patchVersion" android:value="$PATCH_VERSION" />
</provider>

Replace the $MAIN_VERSION and $PATCH_VERSION

From there, you would be able to simply read the file like this

<img src="content://org.apache.xapkreader.expansion/image.jpg">

@adys123
Copy link

adys123 commented Aug 20, 2014

Thanks for your quick response.
Unfortunately I'm not able to make the application work.
It seems that when I write the code in AndroidManifest.xml, the application no longer works.

I have placed XAPKProvider.java in plugins folder, in org.apache.cordova.xapkreader\src\android, and even in platforms\android\src\org\apache\cordova\xapkreader. Nothing seems to work.

That is all I have done so far:
-I update the cordova to version 3.5.0
-I installed the plugin from git using this line:

cordova plugin add https://github.com/psyon/phonegap-xapkreader.git --variable MAIN_VERSION=1 --variable PATCH_VERSION=1 --variable FILE_SIZE=1095520 (with the file size that I needed).

Here I must mention that I installed the plugin from your git page and not from moust because I noticed that you have made ​​some changes.

-Then I added the necessary libraries.
-And now, I'm stuck...

Thanks for your time, psyon.

@psyon
Copy link
Author

psyon commented Aug 20, 2014

If you installed from my repo, then the file should have already been there, and the stuff for the manifest should have been added automatically. the code changes in my repo were done on a live app, and I copied the changes to the repo, but I have not tested it yet. Once my repo is tested, I will send a pull request to merge it into moust's

@adys123
Copy link

adys123 commented Aug 20, 2014

well.. that's interesting because I reinstalled it 2 times and everytime I have the same folder structure with the same files (XAPKAlarmReceiver, XAPKDownloaderActivity, XAPKDownloaderService, XAPKDownloaderService).
And AndroidManifest is unchanged.

@psyon
Copy link
Author

psyon commented Aug 20, 2014

You are probably using the master branch of my repo, and not the psyon-fixes branch. Im not even sure if you can install from my changes. Ill merge to the master branch, and you can give it a try then.

@adys123
Copy link

adys123 commented Aug 20, 2014

that explains everything.
you are right.. I used the master branch.
Then, I'll wait until you merge it.

thank you

@psyon
Copy link
Author

psyon commented Aug 20, 2014

It should be merged into the master branch on my repo now.

@adys123
Copy link

adys123 commented Aug 20, 2014

everything installs fine now.

But I have the same problem with AndroidManifest. Those code lines make my app to stop working before starts.

In XAPKProvider this line package org.android.cordova.xapkreader; give me an error. To get rid of it, I changed to package org.apache.cordova.xapkreader;

@psyon
Copy link
Author

psyon commented Aug 20, 2014

Told you I hadn't tested it yet :P

I changed the package names in the repo.

@adys123
Copy link

adys123 commented Aug 20, 2014

then I'll wait until you will test it :)

anyway, thanks for your time

@psyon
Copy link
Author

psyon commented Aug 20, 2014

That may very well be the only issue. The code itself I have tested in a separate project, but I put the code in manually, and not via the plugin. The only issue should be if the plugin installs properly.

@adys123
Copy link

adys123 commented Aug 20, 2014

Tomorrow I will start a project from 0 and I'll add everything manually to see what happens.
Maybe there are some conflicts...

@psyon
Copy link
Author

psyon commented Aug 20, 2014

I just had the package names wrong when I typed them in. I've updated the repo now, and it should have the correct names. I won't have a chance until Monday next week to sit down and play with it directly. If you get a chance, and see anything wrong, please give some feed back. Hopefully we can get this merged into Mousts repo soon and save some other people some headaches.

@adys123
Copy link

adys123 commented Aug 21, 2014

today I tried again..unfortunately unsuccessfully

I created a new, clean phonegap app where I have installed manually and automatically your plugin. When I try to install the app on phone or on an emulator it just stop working ("Unfortunately, APP has stopped"). As far as I can see, the problem is from AndroidManifest.xml.
If I remove this

<provider android:authorities="org.apache.cordova.xapkreader.expansion" android:exported="false" android:multiprocess="true" android:name="org.apache.xapkreader.XAPKProvider">
    <meta-data android:name="mainVersion" android:value="$MAIN_VERSION" />
    <meta-data android:name="patchVersion" android:value="$PATCH_VERSION" />
</provider>

the app starts and is trying to download the expansion file, but I can't acces the files inside expansion.
Is there something that I have to change/edit in the code above to make this work?

thanks

@llKoull
Copy link

llKoull commented Aug 26, 2014

Hi adys123!

You can fix this bug changing the

android:name="org.apache.xapkreader.XAPKProvider"

Of the line that you copied by:

android:name="org.apache.cordova.xapkreader.XAPKProvider"

I'm stucked downloading the expansion pack 😢 i'm always getting a error telling me that the expansion pack doesn't exist or has a wrong size and It's uploaded to the store 😟 I don't know what to do. Any ideas?

I also tried to load bob file locally (I copied it into Android/obb//) and the app loads correctly, but i'm not able to use content://org.apache.cordova.xapkreader.expansion/... to load anything, the app crashes 😟 May I change any package name or something?

Thanks!

@adys123
Copy link

adys123 commented Aug 26, 2014

Thanks a lot llKoull.
Everything is working properly now.

@llKoull .. this may be a stupid question, but have you placed obb file into Android/obb or into Android/obb/com.bla.bla ?

For anyone that can't make their content to show up in application you need to change this
<img src="content://org.apache.xapkreader.expansion/image.jpg">
to this
<img src="content://org.apache.cordova.xapkreader.expansion/image.jpg">

@llKoull
Copy link

llKoull commented Aug 26, 2014

Hi adys123!

I placed It into Android/obb/"Package ID"/ then my App loads but i can't see any image 😟

Using img src="content://org.apache.cordova.xapkreader.expansion/image.jpg" is working for you?
If I try to use that src I'm getting this error:

"Unable to open content URL: content://org.apache.cordova.xapkreader.expansion/img/logo.png"

How did you make the obb file? I just take the ing and video folders and zipped them. Then I just renamed the .zip file to .obb I seems to work but I couldn't load anything 😟

Thanks!

@adys123
Copy link

adys123 commented Aug 26, 2014

For me it works well
I'm using <img src="content://org.apache.cordova.xapkreader.expansion/image.jpg"> to display my images.

To create the obb file I zipped them then I changed .zip to .obb, just like you did. But when you zipped them, have you selected the store compression method?

@llKoull
Copy link

llKoull commented Aug 26, 2014

No, I just compress the Zip file from my Mac using Right-click -> Compress. Should I use WinRar?

@adys123
Copy link

adys123 commented Aug 26, 2014

give it a try..
I know that when you make the zip/obb you need to select the store method.

@moust
Copy link
Owner

moust commented Aug 26, 2014

Right.

You must create the zip file with no compression. You can do it with the following command :
zip -0vr main.1.xx.xxxx.xxx.obb main.1.xx.xxxx.xxx/

@llKoull
Copy link

llKoull commented Aug 26, 2014

😳 I don't know how to do It hehehehe.

I've got 2 folders "video" and "img" and I want to put them together on the same bob file. I just selected them, right-click -> "Compress" and then I renamed the file to main.1.xx.xxxx.xxxx.zip and main.1.xx.xxxx.xxxx.obb.

Can you tell me how can i do that with the command zip?

Thanks!

@llKoull
Copy link

llKoull commented Aug 26, 2014

I tried with WinRar but It doesn't work 😟 I don't know what to do. It tell me "Unable to open content URL: ..."

  • I've got this in my manifest:

<provider android:authorities="org.apache.cordova.xapkreader.expansion" android:exported="false" android:multiprocess="true" android:name="org.apache.cordova.xapkreader.XAPKProvider"> <meta-data android:name="mainVersion" android:value="1" /> <meta-data android:name="patchVersion" android:value="2" /> </provider>

  • Then I've got the XAPKProvider:

package org.apache.cordova.xapkreader; import com.android.vending.expansion.zipfile.APEZProvider; public class XAPKProvider extends APEZProvider { @Override public String getAuthority() { return "org.apache.cordova.xapkreader.expansion"; } }

  • I've got my obb file in Android/obb/com.xxxx.xxxx/. And the app is detecting It (because It launches the main view).

But the It crashes and tells me that It's unable to open the content url 😟 when I try to load:

<img src="content://org.apache.cordova.xapkreader.expansion/logo.png"/>

Any ideas?

Thanks for all your answers!

@llKoull
Copy link

llKoull commented Aug 26, 2014

Which android version are you using to do the tests?

I'm using Android 4.4.4 and I don't know if It could be a problem 😟

@adys123
Copy link

adys123 commented Aug 26, 2014

4.4.2
tonight I will have more time to look more closely at the code and maybe to discover the problem

@llKoull
Copy link

llKoull commented Aug 26, 2014

I tried with 4.4.4 and App crashes, same code on 4.3 doesn't crash but doesn't show any image (maybe the path is wrong 😟).

@moust
Copy link
Owner

moust commented Aug 26, 2014

The <img src="content://org.apache.xapkreader.expansion/image.jpg"> syntaxe is a feature which only work with the @psyon 's fork. This fork is actually unstable and should be merge to this repo in future.

So you can try this fork if you want, or use the javascript method described in the README file for this repository.

@psyon
Copy link
Author

psyon commented Aug 26, 2014

The code isn't unstable, just the plugin install files :P I will try to make it a point to get it all tested and worked out this week. My kids are back in school as of Today, so that should allow for more time.

@llKoull
Copy link

llKoull commented Aug 26, 2014

Hi! psyon!

I installed this plugin from your repo and I think that the installation was nice. I only had to change one package name from the manifest.xml.

The problem is that I can't use <src="content://org.apache.xapkreader.expansion/image.jpg">to load my images. Do you know if there is some kind of problem on Android 4.4.4?
I tried on 4.3 and the App doesn't crash but It also does' load any image 😟

Thanks!

@psyon
Copy link
Author

psyon commented Aug 26, 2014

have you verified that the expansion file has a compression level of 0?

@llKoull
Copy link

llKoull commented Aug 26, 2014

I think so, I tried to use the command that Moust told me zip -0vr main.1.xx.xxxx.xxx.obb main.1.xx.xxxx.xxx/and I also tried to do It using WinRar (with the Store option).

I made a folder called main.2.xxxx.xxxx.xxxx, inside that folder I added 2 folders "img" and "video", and finally I compressed (with the command I said before) the folder main.2.xxxx.xxxx.xxxx. Doing all this process I think that I've got:

|-> main.2.xxx.xxxx.xxxx.obb
|---> main.2.xxx.xxxx.xxxx/
|------> img/
|------> videos/

Then, If I want to access a file called, for example, logo.png that is into img folder, I should do something like that:

Is that correct?

Thanks!

@psyon
Copy link
Author

psyon commented Aug 26, 2014

You don't want to compress the main.2.xxx.xxxx.xxxx folder, just the contents of it. Your img and videos folder should be in the root of the zip file.

@llKoull
Copy link

llKoull commented Aug 26, 2014

Ok, I'm going to try 😉

@llKoull
Copy link

llKoull commented Aug 26, 2014

I did the Zip again, renamed It to .obb and then I copied It to the tablet and tried to load the img:

<img src="content://org.apache.cordova.xapkreader.expansion/img/logo.png"/>

  • This is the output on 4.4.4:

The app crashes and just after an error that tells me Unable to open content URL: content://org.apache.cordova.xapkreader.expansion/img/logo.png I've got this lines:

errors

  • This is the output on 4.3:

The app doesn't crash it only says Exception: content://org.apache.cordova.xapkreader.expansion/img/logo.png but I couldn't see any image 😟

screenshot_2014-08-26-16-44-51

Thanks!

@psyon
Copy link
Author

psyon commented Aug 26, 2014

I got the null pointer exception when compression level wasn't 0 in my tests... but, I did fine one other issue with the plugin.xml that I just pushed a change for, and I am testing right now. Stay tuned... and I will let you know when I make sure thats working, then we can troubleshoot without worrying about whether or not its my code.

@llKoull
Copy link

llKoull commented Aug 26, 2014

Great! Thanks psyon!!!

@psyon
Copy link
Author

psyon commented Aug 26, 2014

Ok, my repo should be updated, and I made a test project, and installed the plugin, and everything worked fine. Give it a shot. The only XAPKDownloaderActivity.java tries to import io.cordova.helloworld, and my package name was different, so I had to change that. I had the same issue with Mousts repo though. Do you know if there is a way to have that source file be changed to match the package name automatically Moust?

@llKoull
Copy link

llKoull commented Aug 26, 2014

I'm having the same issues on both devices 😢

@moust
Copy link
Owner

moust commented Aug 26, 2014

Yes it's an other problem.

import io.cordova.hellocordova.R; is used to be able to use translated strings stored in the xml ressources file and accessed by the method getResources().getString(R.string.stranslated_string).

But I haven't any idea of how to do it differently without this reference to the application package. :/

@psyon
Copy link
Author

psyon commented Sep 2, 2014

I worked with IIKoull outside this discussion to get things working. My repo should be all good to go. I can send a pull request when ever, but I would probably prefer you did a test since it is being merged into your code. Would you be able to do that, or do you just want me to send a pull request?

@llKoull
Copy link

llKoull commented Sep 3, 2014

Yeah! It works like a charm!

Thanks again for your help psyon!!

@moust
Copy link
Owner

moust commented Sep 4, 2014

It sounds good!
I'm not sure to have the time to test it before 1 or 2 weeks, but you say it's working well I'm sure it's ok. So you can do a pull request now and I'll test it as soon as possible.

@agamemnus
Copy link

Um....

Neither moust's nor psyon's public versions actually has the mainVersion working correctly...

psyon... did you update your version to one that can handle a mainVersion other than 1?...

@psyon
Copy link
Author

psyon commented Sep 11, 2014

Yes, mine uses other versions just fine. What issue are you having?

@agamemnus
Copy link

I am testing with a file that starts with "main.4.com."...
expansionFilesDelivered () will not work, since it tries to get "main.1.com"...
psyon, the last significant update to your public version was months ago... is your current version public?..

@psyon
Copy link
Author

psyon commented Sep 11, 2014

The main version in my app is 20140812, and it's working fine to check and download the file. OH! I set PATCH_VERSION to the same version as my MAIN_VERSION, that may be why. Give that a try to see if that is the issue.

@agamemnus
Copy link

Well.. it isn't, correct.

if (!expansionFilesDelivered(mainVersion, patchVersion, fileSize)) {

mainVersion isn't a version here, it's a boolean. And it's 1.

expansionFilesDelivered is:

boolean expansionFilesDelivered(boolean mainVersion, int patchVersion, long fileSize) {
String fileName = Helpers.getExpansionAPKFileName(this, mainVersion, patchVersion);
...

getExpansionAPKFileName is like this:

    public static String getExpansionAPKFileName(Context c, boolean mainFile, int versionCode) {
        return (mainFile ? "main." : "patch.") + versionCode + "." + c.getPackageName() + ".obb";
    }

So yes... it uses the patch version... in any case, the code only checks and processes one file...

@psyon
Copy link
Author

psyon commented Sep 11, 2014

Yes, I know what code you were talking about.

boolean mainVersion = this.getIntent().getIntExtra("mainVersion", 1) > 0 ? true : false;

That line will make mainVersion be true if MAIN_VERSION is any value 1 or greater. That boolean value is then passed along with the PATCH_VERSION to the expansionFilesDelivered() function, which passes them along to Helpers.getExpansionAPKFileName(). As long as MAIN_VERSION is one or greater, and PATCH_VERSION is set to what ever your main version is, the code will work.

That code is different than the code used in XPAKReader.java, which calls

ZipResourceFile expansionFile = APKExpansionSupport.getAPKExpansionZipFile(ctx, mainVersion, patchVersion);

which passes both integer values for versions to getAPKExpansionZipFile() which then determines if it should use the patch file or not.

So, to make it work for now, set MAIN_VERSION and PATCH_VERSION to the same thing. What needs to be done still though, is that the downloader needs to check to see if the patch and main version both exist, since a patch shouldn't exist without a main expansion file, and download either file that is missing if needed.

@agamemnus
Copy link

All right.

@agamemnus
Copy link

Question:

Why not use android-sdk\extras\google\play_apk_expansion\downloader_sample\src\com\example\expansion\downloader\SampleDownloaderActivity.java?

(I have some code that doesn't crash using that, but it won't load any files either...)

@moust
Copy link
Owner

moust commented Jan 15, 2015

The downloader activity class of this plugin is in part based on the SampleDownloaderActivity class but adapted to some requirements for a Cordova project.. Further I did it with my limited Java/Android skills, so it can certainly be improve.


Otherwise I solved the io.cordova.hellocordova.R import issue with the following code which does not require to import this package:
getString(getResources().getIdentifier("my_string", "string", getPackageName())

I also reuse the psyon's work to integrate the provider's functionality and improved some part of the code.

@agamemnus
Copy link

Way ahead of you --
https://github.com/agamemnus/cordova-plugin-xapkreader

No need to get the package name when you can just get the individual xml strings. For example, in XAPKDownloaderActivity (IDownloaderClient):

 @Override public void onCreate (Bundle savedInstanceState) {
  super.onCreate (savedInstanceState);
  xmlData = savedInstanceState;
....
  alert.setMessage (xmlData.getString("xapk_text_download_failed", ""))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants