Starting External Stacks on Android

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Starting External Stacks on Android

Post by dcpbarrington » Mon Jul 29, 2013 10:19 pm

Forum

I'm in the process of porting a LiveCode app to Android and I'm having a problem getting the library stacks that are not sub-stack to start.

I have a main stack, two sub-stacks and 5 libary stacks for the application.
The library stacks are located in a folder called /lib, so multiple apps can access a commen set
I have listed the stack to be included with the package in Standalone Application Settings

in the preOpenStack I have the following code

Code: Select all

on preOpenStack
   global gLibraryStackName
   
   if the environment = "mobile" then
      set the defaultFolder to specialFolderPath("engine")
      set the rect of this stack to the screenrect
      resizeStack
      mobileSetAllowedOrientations("Portrait", "landscape left", "landscape right")
   else
      set the itemDelimiter to "/"
      get the fileName of this stack
      set the defaultFolder to item 1 to -2 of it
   end if
  
   -- Start the libraries
    if "MobileLocalization" is not among the lines of the StacksInUse then
      start using stack "MobileLocalization"
   end if
   if "MobileConnect" is not among the lines of the StacksInUse then
      start using stack "MobileConnect"
   end if
   if "DataValidation" is not among the lines of the StacksInUse then
      if the environment = "development" then
         start using stack "../lib/saverDataValidation.livecode"
      else if the environment = "mobile" then
         put defaultFolder & "saverDataValidation.livecode" into gLibraryStackName
         start using stack gLibraryStackName
      else
         start using stack "saverDataValidation.livecode"
      end if
   end if
   if "ErrorHandlers" is not among the lines of the StacksInUse then
      if the environment = "development" then
         start using stack "../lib/saverErrorHandlers.livecode"
      else if the environment = "mobile" then
         put defaultFolder & "saverErrorHandlers.livecode" into gLibraryStackName
         start using stack gLibraryStackName
      else
         start using stack "saverErrorHandlers.livecode"
      end if
   end if
end preOpenStack
The application is hanging when it tries to start the external stacks that are included in the APK package.

On my main card I have a function to display the StacksInUse as well as the global variable that is set to show the location of where the software is looking for the stack to start.
Only the Sub-Stacks are started, the other stacks are not started when the StacksInUse are listed.

Location of the stacks is defined to be /data/app/com.XAC.saver-01.apk/saverDataValiation.livecode
Indicating that the software hangs when it first tries to start the first external stack => saverDataValidation.livecode

From the documentation, I understand that a read-only package is created in the "engine" location, so I expect that I should be able to open the stacks from there.

I must be doing something wrong in accessing the stacks or are external stacks a problem in Android?
Thanks for the help

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Starting External Stacks on Android

Post by Simon » Tue Jul 30, 2013 1:44 am

Hi,
I'm seeing a missing "/"

Code: Select all

put defaultFolder & "/" & "saverDataValidation.livecode" into gLibraryStackName
"set the defaultFolder to item 1 to -2 of it" removes the slash.

Might not be all but it's a start.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Starting External Stacks on Android

Post by dcpbarrington » Tue Jul 30, 2013 4:12 pm

Simon,

Thanks for your reply.

I'm using the global variable to identify what the path is set to and I actually needed to remove the "/" because the specialFolderPath("engine") included the slash.

I used the global variable to view what the path was set to in the application it is defined as: /data/app/com.XAC.saver-01.apk/saverDataValidation.livecode
If I include the "/" it gives a double slash before the file name which also fails, because that is how I had it originally.

The documentation says that all the included Stacks and Files are bundled into the com.XAC.saver-01.apk package and are read only.

I initially though that if I set the default folder to specialFolderPath("engine") I should be able to just use the code to access the stack:

Code: Select all

   if "DataValidation" is not among the lines of the StacksInUse then
          start using stack "saverDataValidation.livecode"
   end if
I also tried to just identify the name of the stack and not the file name, but that didn't work either;

Code: Select all

   if "DataValidation" is not among the lines of the StacksInUse then
          start using stack "DataValidation"
   end if
There must be something special that you need to do because the Stack is part of the APK file on the Android system. Let me know if anyone has some thoughts.

Thanks

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Starting External Stacks on Android

Post by Klaus » Tue Jul 30, 2013 4:18 pm

Does it work if your AVOID to set the defaultfolder and use the absolute pathname?
...
start using stack (specialfolderpath("engine") & "/saverDataValidation.livecode")
...
?

Hint:
ALL specialfolderpath() return a folder WITHOUT a trailing slash!
So if your specialfolderpath("engine") HAS in fact a trailing slash, I would consider this a bug! 8-)

dcpbarrington
Posts: 87
Joined: Tue Nov 13, 2007 6:40 pm

Re: Starting External Stacks on Android

Post by dcpbarrington » Tue Jul 30, 2013 4:46 pm

FOUND THE ISSUE IN THE SMALL PRINT

In the Android guide it has the following statement:
Note: The Inclusions, Copy Referenced Files, Bug Reports and Stacks features are not available
when building for Android. If you wish to include multiple stackfiles in your application, use the
Copy Files feature instead.
I was including the STACK in the INCLUDE STACK tab in the Standalone Application Setting and needed to include the stack files in the FILES tab.

Then the stacks are opened with the code:

Code: Select all

  if "DataValidation" is not among the lines of the StacksInUse then
          start using stack "saverDataValidation.livecode"
   end if
Thanks for everyone comments. Including STACKs is different in Android and the Standalone Application Settings don't give a warning and can easily take you down the wrong path.

Post Reply