Unable to use resources

Hi

I've built some apps using the connectIQ (command line), but I am unable to run any app that contains any type of resources.
Apparently the AppName string resource works fine but that's about it.

I have tried compiling the apps/watchfaces from the sample directory, and they do compile, but give errors at runtime, like:
"Invalid Value"
"Invalid Resource Specified"

I'm compiling using the command line, not Eclipse.
I've included all necessary resource files since when I remove a resource the monkeyc compiler throws errors saying it can't find the resource specified.
This means they are included in the build, but I can't seem to access them at runtime.

Anyone knows how I can solve this?
Thanks!
  • Show us the compile line you'd use for one of the example programs. Maybe someone can pick out the error.

    Travis
  • I haven't added the ConnectIQ bin to the PATH variable, and thus I call the command from the bat files itself:

    C:\Users\steen\Downloads\ConnectIQ\connectiq-sdk-win-2.1.2\bin\monkeyc.bat -o output.prg -m manifest.xml -z resources\resources.xml source\CompactDigitalApp.mc source\CompactDigitalGoalView.mc source\CompactDigitalView.mc

    C:\Users\steen\Downloads\ConnectIQ\connectiq-sdk-win-2.1.2\bin\monkeydo.bat output.prg

    These command are called in the respective folders with the manifest and output files.
    They do work, since the simulator starts to run the app after this, so nothing is wrong with finding the bat files or anything.

    The folder structure is this:
    manifest.xml
    .project
    output.prg
    resources\
    resources.xml
    fonts\
    fnt-png files
    images\
    icon.png
    source\
    CompactDigitalApp.mc
    CompactDigitalGoalView.mc
    CompactDigitalView.mc
  • Anyone?

    I tried again, and I can only load strings, no bitmaps or fonts.

    <resources>
    <string id="AppName">Analog</string>
    <string id="TestString">BlaBlaBla</string>
    <bitmap id="LauncherIcon" filename="images/icon.png" />
    </resources>


    From this for example, I can load AppName and TestString, but not LauncherIcon.
  • I'm having no such problem. Here is my file heirarchy

    C:\Users\Travis\workspace\Test
    &#9474; .project
    &#9474; developer.key
    &#9474; evil.bat
    &#9474; manifest.xml
    &#9474;
    &#9500;&#9472;&#9472;&#9472;resources
    &#9474; &#9474; resources.xml
    &#9474; &#9474;
    &#9474; &#9500;&#9472;&#9472;&#9472;fonts
    &#9474; &#9474; blackdiamond.fnt
    &#9474; &#9474; blackdiamond_0.png
    &#9474; &#9474;
    &#9474; &#9492;&#9472;&#9472;&#9472;images
    &#9474; launcher_icon.png
    &#9474;
    &#9492;&#9472;&#9472;&#9472;source
    TestApp.mc
    TestView.mc


    I use a batch file (evil.bat) to do my command-line builds, but here is the output...

    C:\Users\Travis\workspace\Test>evil build fenix3_hr
    Connect IQ compiler version 2.1.3
    monkeyc.bat -w -y developer.key -o bin\Test.prg -m manifest.xml -z resources\resources.xml -d fenix3_hr source\TestApp.mc source\TestView.mc
    WARNING: The launcher icon (30x30) is smaller than the specified launcher icon size of the device 'fenix3_hr' (40x40). Padding will be added to the image to center it.


    Here is the code that uses those resources...

    function onLayout(dc) {
    setLayout(Rez.Layouts.WatchFace(dc));

    var text = View.findDrawableById("TimeLabel");
    if (text) {
    text.setFont(Ui.loadResource(Rez.Fonts.WatchFont));
    }

    var bitmap = View.findDrawableById("TimeBitmap");
    if (bitmap) {
    bitmap.setBitmap(Rez.Drawables.WatchBitmap);
    }
    }


    Here is the content of resources.xml...

    <resources>

    <drawables>
    <bitmap id="LauncherIcon" filename="images/launcher_icon.png" />
    </drawables>

    <layouts>
    <layout id="WatchFace">
    <bitmap id="TimeBitmap" x="109" y="50" filename="fonts/blackdiamond_0.png" />
    <label id="TimeLabel" x="center" y="center" font="Gfx.FONT_LARGE" justification="Gfx.TEXT_JUSTIFY_CENTER" color="Gfx.COLOR_BLUE" />
    </layout>
    </layouts>

    <strings>
    <string id="AppName">Test</string>
    </strings>

    <bitmaps>
    <bitmap id="WatchBitmap" filename="images/launcher_icon.png" dithering="none">
    <palette disableTransparency="false">
    <color>000000</color>
    <color>FFFFFF</color>
    <color>0000FF</color>
    </palette>
    </bitmap>
    </bitmaps>

    <fonts>
    <font id="WatchFont" filename="fonts/blackdiamond.fnt" antialias="true" filter="0123456789:" />
    </fonts>

    </resources>


    Travis
  • Thanks, but if I try to compile that, it tells me it ran out of error.
    I tried this:

    45| function onLayout(dc)
    46| {
    47| //retreiveSunriseSunset();
    48| //icon = Ui.loadResource(Rez.Drawables.LauncherIcon);
    49| Sys.println(Lang.format("Rez.Fonts.id_font_black_diamond: $1$", [Rez.Fonts.id_font_black_diamond]));
    50| Sys.println(Lang.format("Ui.loadResource(Rez.Fonts.id_font_black_diamond): $1$", [Ui.loadResource(Rez.Fonts.id_font_black_diamond)]));
    51| symbols = Ui.loadResource(Rez.Fonts.id_font_black_diamond);
    52|
    53| restoreFields(dc);
    54| }


    And this was the output:

    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    Rez.Fonts.id_font_black_diamond: 57
    Failed invoking <symbol>
    Invalid Value
    in onLayout (source\CompactDigitalView.mc:50)
    Connection Finished
    Closing shell and port
  • You can't print the result of Ui.loadResource(), it crashes the simulator. If you remove line 50 you should be okay. Here is a link a .zip of the test project, including my build script (evil.bat). I have no problems loading my custom font (named WatchFont).

    I'm still not sure I understand why you're not just using Eclipse. You'd save yourself a lot of time if you just used the tools that exist for working with this stuff.

    Travis
  • It crashes the simulator, ok, but if I comment out that line the same errors arise, but only on line 51 instead of 50.
    Anyway, I don't like eclipse, I rather use Sublime to do all my programming. I have done this for years, and this is the first language that is unable to make me do so, which is a little disappointing.
    I tried building your project, which was successful, but it gave the "Ran out of Memory" error. Are admin right maybe needed for something?
  • There is something wrong with you environment then. You aren't really helping things by just saying that it doesn't work. Show us the command line that you execute. Show us the output of the build.

    Are you building with the provided batch file, or trying to use your own command line? Here is the sequence of commands that I run. I don't see any unusual output, and the program displays both the font and bitmap as expected.

    C:\Users\Travis>cd %userprofile%\desktop\Test
    C:\Users\Travis\Desktop\Test>evil build fenix3
    Connect IQ compiler version 2.1.3
    monkeyc.bat -w -y developer.key -o bin\Test.prg -m manifest.xml -z resources\resources.xml -d fenix3 source\TestApp.mc source\TestView.mc
    WARNING: The launcher icon (30x30) is smaller than the specified launcher icon size of the device 'fenix3' (40x40). Padding will be added to the image to center it.

    C:\Users\Travis\Desktop\Test>evil start
    connectiq.bat

    Waiting for 0 seconds, press CTRL+C to quit ...

    C:\Users\Travis\Desktop\Test>evil run fenix3
    monkeydo.bat bin\Test.prg fenix3
    Found Transport: tcp
    Connecting...
    Connecting to device...
    Device Version 0.1.0
    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    Copying file.... 1% complete
    Copying file.... 100% complete
    File pushed successfully
    Connection Finished
    Closing shell and port
    Found Transport: tcp
    Connecting...
    Connecting to device...
    Device Version 0.1.0
    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    Rez.Fonts.WatchFont: 33962
    Complete
    Connection Finished
    Closing shell and port

    C:\Users\Travis\Desktop\Test>
  • Sorry I thought I posted it previously.
    There you go, this is the input/output from your test project (the zip) on the square_watch:

    C:\Users\steen\Downloads\Test\Test>evil build square_watch
    Connect IQ compiler version 2.1.2
    monkeyc.bat -w -y developer.key -o bin\Test.prg -m manifest.xml -z resources\
    resources.xml -d square_watch source\TestApp.mc source\TestView.mc
    WARNING: The launcher icon (30x30) is smaller than the specified launcher icon s
    ize of the device 'square_watch' (61x43). Padding will be added to the image to
    center it.

    C:\Users\steen\Downloads\Test\Test>evil start
    connectiq.bat

    Waiting for 0 seconds, press CTRL+C to quit ...

    C:\Users\steen\Downloads\Test\Test>evil run square_watch
    monkeydo.bat bin\Test.prg square_watch
    Found Transport: tcp
    Connecting...
    Connecting to device...
    Device Version 0.1.0
    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    Copying file.... 1% complete
    ...
    Copying file.... 100% complete
    File pushed successfully
    Connection Finished
    Closing shell and port
    Found Transport: tcp
    Connecting...
    Connecting to device...
    Device Version 0.1.0
    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    Failed invoking <symbol>
    Out Of Memory Error
    in setBitmap (D:\dev\monkeybrains\toolchain\mbsimulator\submodules\technology\
    monkeybrains\virtual-machine\api\WatchUi.mb:1531)
    in initialize (D:\dev\monkeybrains\toolchain\mbsimulator\submodules\technology
    \monkeybrains\virtual-machine\api\WatchUi.mb:1452)
    in WatchFace (Rez:23)
    in onLayout (source\TestView.mc:15)
    Connection Finished
    Closing shell and port



    An this is on the fenix3:

    C:\Users\steen\Downloads\Test\Test>evil build fenix3
    Connect IQ compiler version 2.1.2
    monkeyc.bat -w -y developer.key -o bin\Test.prg -m manifest.xml -z resources\
    resources.xml -d fenix3 source\TestApp.mc source\TestView.mc
    WARNING: The launcher icon (30x30) is smaller than the specified launcher icon s
    ize of the device 'fenix3' (40x40). Padding will be added to the image to center
    it.

    C:\Users\steen\Downloads\Test\Test>evil run fenix3
    monkeydo.bat bin\Test.prg fenix3
    Found Transport: tcp
    Connecting...
    Connecting to device...
    Device Version 0.1.0
    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    Copying file.... 1% complete
    ...
    Copying file.... 100% complete
    File pushed successfully
    Connection Finished
    Closing shell and port
    Found Transport: tcp
    Connecting...
    Connecting to device...
    Device Version 0.1.0
    Device id 1 name "A garmin device"
    Shell Version 0.1.0
    Rez.Fonts.WatchFont: 33962


    Apparently this does make a difference somehow.

    On fr920xt and epix it gives these respective result:



    edit:
    Apparently changing from square_watch to vivoactive does the job.
    How come there's a difference in square watch vs vivoactive?
    Thank you very much for the bat script btw, it works perfectly nice!

    Just one question though, how can I package it to an .iq zip file?
    I have seen the --ship (or -e) argument, but it throws errors so I can't really use it and documentation is scarce (or maybe I'm looking over it).
  • I hadn't finished handling the ability to build a shipping package with evil.bat, but the command line should be something like...

    monkeyc.bat -e -r -w -y developer.key -o bin\Test.iq -m manifest.xml -z resources\resources.xml source\TestApp.mc source\TestView.mc


    You add -e (and optionally -r), change the extension on the output file from prg to iq, and remove the device specification (-d fenix3 in my previous snippets).

    Travis