Build apk for Google Play and Activity Starter

237 views
Skip to first unread message
Assigned to ewpa...@gmail.com by steve....@gmail.com

John Lock

unread,
Aug 3, 2018, 12:53:13 PM8/3/18
to mitappinv...@googlegroups.com
I am making an app to download an apk file from my google drive and then install them on the user's device. I followed this tutorial https://puravidaapps.com/install.php by Taifun, and posted my question here, but I didn't get a response.

This happens when I use the original build apk (for older versions of Android)
On the Google Pixel 8.1.0, I get this error message:



However, the exact same code works on a different android device.


Here is the error message I get for the exact same app downloaded for Google Play:






















Code information:

The activity starter properties are exactly the same as in the tutorial, except the com.google.android.packageinstaller in the activity package. I get the 601 error without the .google.

Any help is greatly appreciated.

John

Evan Patton

unread,
Aug 3, 2018, 2:01:13 PM8/3/18
to MIT App Inventor Forum
Hi John,

This behavior was introduced in Android 7.0 to prevent sharing of file URIs outside of an application. We are working on updating the SDK 26 build to silently convert file URIs to content URIs so that one can continue to pass files between activities using the ActivityStarter.

Regards,
Evan

John Lock

unread,
Aug 4, 2018, 8:32:56 AM8/4/18
to MIT App Inventor Forum
Thank you for the help. It seems like android and google play keep making confusing changes that leave the App Inventor team scrambling to come out with a fix.

Do you have any idea why the activity doesn't work when I build the apk the old way? I think it might have to do with the install from unknown source permission, but the device doesn't ask for it, I just get the error.

Thanks

John

SteveJG

unread,
Aug 4, 2018, 8:42:05 AM8/4/18
to MIT App Inventor Forum
@John     I expect the same thing will happen when you build using the Legacy tool because the issue is App Inventor 2 compatibility with Android 7.

--Steve

John Lock

unread,
Aug 4, 2018, 1:28:35 PM8/4/18
to MIT App Inventor Forum
Steve,

That makes sense, but the device is running 8.1.0, and the error I am getting is completely different when the app is built with the old apk builder (the error messages are both in my first post on this thread).

Maybe since the old build targets a different SDK version, it is allowed by Android to use file URIs.

John

SteveJG

unread,
Aug 4, 2018, 3:23:47 PM8/4/18
to MIT App Inventor Forum
OK John.  I do not know.  I am guessing .I sent Evan a note; perhaps he will sort it out when he next reads this thread.

John Lock

unread,
Aug 9, 2018, 10:18:56 PM8/9/18
to MIT App Inventor Forum
Steve,

I know Evan must be very busy, especially with all the recent questions about building apk files for Google Play, but would you mind asking him when he could get back to me about this?

I would really appreciate the help, this problem is way beyond me.


Thank you,

John

SteveJG

unread,
Aug 10, 2018, 7:59:51 AM8/10/18
to mitappinv...@googlegroups.com
@John ... Evan is aware of the issue.  He said " we are working on updating the SDK 26 build to silently convert file URIs to content URIs so that one can continue to pass files between activities using the ActivityStarter."
Most likely, he will not get back to you personally. The fix, when he discovers one, will appear in the next release of App Inventor 2.  His team has lots of api26 issues and is small.  It does not make sense to release a single bug fix individually.  When will the next release be?  Whenever it is ready.  Be aware, the development team reads the post in the Forum and stays current.

Your alternatives are:  wait, use one of the third party clones instead of AI2,  use Android Studio etc.

Regards,
Steve

John Lock

unread,
Aug 10, 2018, 6:05:23 PM8/10/18
to MIT App Inventor Forum
Steve,

I am sorry, maybe I didn't explain correctly.

I don't need to build my app for google play, I was just hoping that building it that way might fix my issue with the legacy build.

My question now is not about the google play building, but about the problem I am having with the legacy build, which seems unrelated to the file/content URI problem.

I think the problem with legacy build would also happen with the google play build, only that the URI problem happens first and interrupts the other blocks before they can execute.

I am wondering if Evan might know why the app is giving me the error when I call the package installer form the activity installer.

Do you know if he can answer this question?

Thanks,

John

SteveJG

unread,
Aug 10, 2018, 6:33:09 PM8/10/18
to mitappinv...@googlegroups.com
@ John.    please read Evan's posts.  He says the issue is w.r.t. Android 7 and he is working on it.  That it is an Android 7 (and perhaps higher ) issue  implies the problem occurs with Legacy AND GooglePlay.

You said "I am wondering if Evan might know why the app is giving me the error when I call the package installer form the activity installer.  Do you know if he can answer this question?"   Evan says explicitly 
"This behavior was introduced in Android 7.0 to prevent sharing of file URIs outside of an application."   He will fix it when he will fix it.

Meanwhile, perhaps borrow an Android lower than 7.  

John Lock

unread,
Aug 10, 2018, 10:24:38 PM8/10/18
to MIT App Inventor Forum
OK Steve,

I thought the two error messages I was getting were different, but from what you're saying, they are both activity starter URI errors, they just look different. This would explain why Evan only had one explanation instead of two. I thought he was just answering my question about the Google Play error and had missed the other one, but I guess he was answering both.

Thank you for your help,

John

SteveJG

unread,
Aug 11, 2018, 8:21:31 AM8/11/18
to MIT App Inventor Forum
:)    You might load the apk on an Android device lower than 7 and test this yourself (only you have the code)   and call the package installer from the activity installer app and see if you get the same error .  If you still see th error,  post the relevant part of the code here (better still an example aia)  and someone might comment on its ability to do the intents you call with App Inventor.   ActivityStarter cannot process all intents.

John Lock

unread,
Aug 11, 2018, 11:09:58 AM8/11/18
to mitappinv...@googlegroups.com
Here is the code I am using:

Screenshot 2018-08-11 at 11.11.22 AM.png


I wanted the user to be able to edit the parameters in case they needed the .google, so I am using tinyDB so they can change it.



Here is what happens when I try to install an app on an LG running 7.0:


Legacy works exactly as it should, opening the package installer without any errors, which means that the code must be working.


Google Play build returns the error "the_apk's_file_location_here exposed beyond app through Intent.getData()"



However, I haven't built the legacy apk for the app for a while, because I haven't done any updates, so maybe the problem could be because of an update to app inventor.


Would changing the data type property help?


EDIT: I noticed that I had added the .google in the activity package value if not found. I removed it and updated the image because I don't want the .google in case the device doesn't need it.

SteveJG

unread,
Aug 11, 2018, 12:14:43 PM8/11/18
to MIT App Inventor Forum
OK

I wanted the user to be able to edit the parameters in case they needed the .google, so I am using tinyDB so they can change it.

What you do using the TinyDB directly feeding the ActivityStarter Blocks might be OK. I  prefer a global variable  populated at screen load from the TinyDB Gets .  This TinyDB  you call  TinyDB2.  Do you have several instance of TinyDB?


Here is what happens when I try to install an app on an LG running 7.0:


Legacy works exactly as it should, opening the package installer without any errors, which means that the code must be working.

But you state later  you did not try a Build using Legacy.  Does this mean your code worked prior to nb170 on your LG 7.0?


Google Play build returns the error "the_apk's_file_location_here exposed beyond app through Intent.getData()"


The DataUri block is what is spawning error message. That is what Evan says needs to be fixed..  He said " prevent sharing of file URIs outside of an application. We are working on updating the SDK 26 build to silently convert file URIs to content URIs .  When that is done, you code possibly will work with GooglePlay installed to Andrid 7.0 devices.


You get the file location of the APK you want to install from another Screen.  The need to capture data from another Screen might introduce a timing issue.  You might revise the order of assigning values to the ActivityStarter.  Consider placing the DataUril Block preceding the Action Block.  Sometimes, reordering helps.



However, I haven't built the legacy apk for the app for a while, because I haven't done any updates, so maybe the problem could be because of an update to app inventor.


Maybe, you should be using Companion 2.47 and nb170


Would changing the type property help?

 

It is not possible to see what Data Type you are using from your Blocks.  What data type are you using?  You can supposedly try any of these:



audio/mpeg4-generic
text/html
audio/mpeg
audio/aac
audio/wav
audio/ogg
audio/midi
audio/x-ms-wma
video/mp4
video/x-msvideo
video/x-ms-wmv
image/png
image/jpeg
image/gif
.xml ->text/xml
.txt -> text/plain
.cfg -> text/plain
.csv -> text/plain
.conf -> text/plain
.rc -> text/plain
.htm -> text/html
.html -> text/html
.pdf -> application/pdf
.apk -> application/vnd.android.package-archive


When capturing string blocks, what is inside them is truncated (as in your image).  Is this the string that links into the ActivityStarter.ActivityClass :    com.google.android.packageinstaller.PackageInstallerActivity  or do you something else?



You might Build this again using the Legacy Build, install the apk  and tells us whether your code does what you expect.. just to confirm that both  Legacy and GooglePlay builds fail on your 7.0 device.


Also, you might provide here in the an example aia without using the TinyDB  of the ActivityStarter code with the AS links  hard coded.  Only then can MIT or anyone else test this on their 7.0 and other operating systems.







John Lock

unread,
Aug 11, 2018, 4:08:47 PM8/11/18
to MIT App Inventor Forum
Thanks for the response,


Do you have several instance of TinyDB?

I am using TinyDB1 for storage of other stuff, TinyDB2 is just for settings. The namespaces are different so that the tags don't conflict.



Does this mean your code worked prior to nb170 on your LG 7.0?

I had thought that might be part of the problem, but I just tested with a new apk. There seems to be no difference between the old version and the new one. The legacy apk has and does work on the LG, but the Google Play apk does not.



The DataUri block is what is spawning error message.

But there is no way to fix that in my code, right? It's not like I can just remove it because it points to the actual file.



You get the file location of the APK you want to install from another Screen.

No I don't. I download the apk using the Web component. The response is saved to a path I specify, so I know exactly where it is. Also, the install happens as soon as the Web1.GotFile event is triggered (on the same screen). I don't need to worry about where the file is because I already know.



What data type are you using?

I left it blank because the tutorial didn't specify, but I am installing an apk, so it would be application/vnd.android.package-archive.



Is this the string that links into the ActivityStarter.ActivityClass: com.google.android.packageinstaller.PackageInstallerActivity

Yes



You might Build this again using the Legacy Build, install the apk and tells us whether your code does what you expect.. just to confirm that both  Legacy and GooglePlay builds fail on your 7.0 device.

7.0:

Legacy works fine, Google Play fails

8.1.0:

Both fail



Also, you might provide here in the an example aia

Attached is a modified version of Taifun's example.
install.aia

SteveJG

unread,
Aug 13, 2018, 8:55:34 AM8/13/18
to MIT App Inventor Forum
Thank you John.  You provided the information the developers will need to test a potential fix. Now wait until MIT deploys and update; it will probably provide a remedy.  Your code works on your 7.0 device using Legacy but not GooglePlay builds.    Are you able to test your code on a different Android operating system lower than 7; a test of that too would help the developers.


The DataUri block is what is spawning error message.

But there is no way to fix that in my code, right? It's not like I can just remove it because it points to the actual file.

Right, that block is required and hopefully is what MIT will fix to work with api26.


You get the file location of the APK you want to install from another Screen.

No I don't. I download the apk using the Web component. The response is saved to a path I specify, so I know exactly where it is. Also, the install happens as soon as the Web1.GotFile event is triggered (on the same screen). I don't need to worry about where the file is because I already know.

OK, you never mentioned that, the code looks like you are depending on information form elsewhere and if you get it using the Web component, that is a potential timing issue depending on how you handle it in your real app.

What data type are you using?

I left it blank because the tutorial didn't specify, but I am installing an apk, so it would be application/vnd.android.package-archive.
The data type certainly should be specified, not blank.


John Lock

unread,
Aug 13, 2018, 10:07:52 AM8/13/18
to MIT App Inventor Forum
Thanks Steve,

Sorry, I don't have a device running less than 7.0 to test with.


I changed the data type block so that the default is application/vnd.android.package-archive.


Now I guess I'll just wait for the next release of App Inventor.


Steve, thank you for all your help. If you hadn't explained that the two errors I got were the same, I would still think that the problem had to do with needing a permission in the manifest, not with the Activity Starter.

Thank you again,

John

Evan Patton

unread,
Aug 14, 2018, 9:42:21 AM8/14/18
to MIT App Inventor Forum
Hi John,

We deployed a new Google Play build server last night that should correctly handle file URIs in the ActivityStarter on newer versions of Android. Please recompile your app and let us know if it solves your issue.

Thanks,
Evan

John Lock

unread,
Aug 14, 2018, 5:31:58 PM8/14/18
to mitappinv...@googlegroups.com
Evan,

I tested the Google Play apk on both devices.

On the LG running 7.0, it works now, which is great news.

On the Pixel 8.1.0, I get this error instead of the URI error:

20180814_172216_HDR-1.jpg

That is the same error I get from using the legacy build on that device.


I am pretty sure this error is a permission problem because the first line of the error message is "Permission Denial".


Thank you for the fix, but the URI problem seems to be unrelated. What I think is that the URI error canceled the activity before the permission error could appear.



Thanks,


John

Evan Patton

unread,
Aug 16, 2018, 2:55:32 PM8/16/18
to MIT App Inventor Forum
Hi John,

Take a look at this post from zdnet. Starting with target SDK 26, apps will have to request the correct permissions to install apps. However, it should still work with the legacy version of the application (target SDK 7). We will look into how we might provide access to this permission since we do not currently include it in App Inventor.

Cheers,
Evan

John Locke

unread,
Aug 16, 2018, 3:56:08 PM8/16/18
to MIT App Inventor Forum
Evan,

Way ahead of you on that :)


However, it seems that more is needed than just that. I think the app also has to call this intent:

startActivity(new Intent(android.provider.Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES));

to request the permission, and only then can it install the app.

If I'm not mistaken, the Activity Starter cannot do this because it uses a certain type of intent (for starting activities).


Thanks,

John

Evan Patton

unread,
Aug 16, 2018, 7:35:04 PM8/16/18
to MIT App Inventor Forum
Correct, we need to extend the logic of ActivityStarter so that if the target is the package installer we request the permission prior to launching the activity. It should be a straightforward enough fix to implement.

Regards,
Evan

John Locke

unread,
Aug 16, 2018, 8:11:50 PM8/16/18
to MIT App Inventor Forum
Evan,

Sounds good. At least one of us knows what to do from here.

John

Reply all
Reply to author
Forward
0 new messages