Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24001] iOS: Local .png and .jpg images do not display in WebView when App-Thinning is enabled

GitHub Issuen/a
TypeBug
PriorityCritical
StatusReopened
ResolutionUnresolved
Affected Version/sRelease 5.4.0, Release 5.5.0
Fix Version/sn/a
ComponentsiOS
LabelsengSchedule, png, webview
ReporterSlim McKinsley
AssigneeChris Barber
Created2016-10-07T05:55:08.000+0000
Updated2019-08-12T18:01:00.000+0000

Description

PNG and JPG images that exist locally (in the Resources dir) render as broken images in Titanium.UI.WebView components. Images are broken when displayed via both tags and CSS. This is a regression in Ti SDK 5.5.x. Attached is a sample app.js to reproduce the issue. The console displays the following error: [ERROR] : Error loading /Users/slim/Library/Developer/CoreSimulator/Devices/F2DACFF8-2866-4B5A-8098-3D817716D753/data/Containers/Bundle/Application/58D9B4CD-13B4-4224-A694-8CD011FED83B/Test.app/KS_nav_ui.png Note that remote images (PNG, JPG) seem to render correctly. Also, local GIF images (not tested extensively) and other common assets such as JS and CSS render. Only local PNG and JPG images seem to be affected.

Attachments

FileDateSize
app.js2016-10-07T05:47:47.000+0000168
KS_nav_ui.png2016-10-07T05:48:02.000+0000748

Comments

  1. Hans Knöchel 2016-10-07

    Hey there! When was the last time it works? So from from version did it break? Thx!
  2. Hans Knöchel 2016-10-07

    I just tested with both master and 5.5.x, it does work for me, both on Simulator and device. If you navigate to the file in the logs, what is inside the .app file?
  3. Hans Knöchel 2016-10-07

    Resolving as Cannot Reproduce for now. I've done multiple tests across our SDK's and am able to see the demo-image in all test-cases.
  4. Hans Knöchel 2016-10-07

    I was able to reproduce the issue with our packaged SDK. The issue does occur when app-thinning is enabled (<use-app-thinning>true</use-app-thinning>). It works with setting it to false. But since it's true by default, we need to fix it asap. Technically, it happens because we hash the image-names internally for all SDK-related usages. So we need to come up with a solution for webviews. [~cbarber] thoughts? We have the same problem for local images in Hyperloop. Is there no chance to store the assets with their actual name? I know we had problems with the density-suffixes then, but hashing it has some bad side-effects as well. Thx!
  5. Slim McKinsley 2016-10-07

    Hans, good catch. I can confirm the issue is caused by
       <use-app-thinning>true</use-app-thinning>
       
    The workaround is to disable it.
  6. Chris Barber 2016-10-07

    We have to SHA the filenames of all asset catalog images because the filenames are not unique. If you have an image called foo.jpg in one asset catalog and foo.jpg in another, they will collide and only one of them will be resolved. Furthermore, there wasn't a way to hint as to which asset catalog to look for a given image. So, we must SHA the filenames. Since you cannot load an image from an asset catalog into the WebView, we have 3 options:

    Build a generic mechanism to classify and assign metadata to resources. The developer would manually classify which images should not be thinned.

    Rewrite all local image requests to a special URI that resolves a proxy run by the app itself that in turn fetches the image from the asset catalog.

    Do nothing!

    Option 1 will happen, just not in time for Titanium SDK 6.0. Option 2 is a hack. It probably won't take long to implement, but first we need to prove it's possible. I could see us possibly using this proxy mechanism to access other resources such as encrypted JS files. Option 3 is the path of least resistance. Just tell people to turn off app thinning, or at least until we finish option 1.
  7. Slim McKinsley 2016-10-08

    Chris, from my testing it seems that .gif images are not affected by app thinning. They remain in their original location within the Resources dir and are not moved and/or hashed into Assets.car. If this is the case, another workaround/hack would be to only use .gif images in WebViews. Is this safe to do? If app thinning only touches certain image types/extensions, can you clarify which? Much appreciated.
  8. Chris Barber 2016-10-08

    [~slim.mckins] Ah, yes. You can safely use .gif images. Titanium will only put .png and .jpg images into image sets: https://github.com/appcelerator/titanium_mobile/blob/master/iphone/cli/commands/_build.js#L4508-L4526. While image sets support .png, .jpg, and .pdf files (https://developer.apple.com/library/content/documentation/Xcode/Reference/xcode_ref-Asset_Catalog_Format/ImageSetType.html), we chose to not automatically put .pdf files in image sets. .png and .jpg are always images, but .pdf files may be documents. So using .gif files is another workaround.
  9. Francisco Carlos Artal Barba 2017-05-04

    hi, any update on this? thanks!
  10. Szymon Machajewski 2017-05-17

    I can confirm that the issue is present in 5.5.1GA. Changing the setting to false in tiapp.xml does fix it: false
  11. Hans Knöchel 2017-08-21

    This will be resolved in a future release as part of the general app-thinning changes being made. Until now, the workaround is to disable app-thinning for those use-cases.
  12. Motiur Rahman 2018-01-24

    [~hknoechel], I have tested with the Ti SDK 7.0.1.GA and iPhone 5s v11.2.2 but it does not work with this workaround. false This is my code
        <Alloy>
        	<Window id="win">
        		<WebView id="webview" backgroundImage="motiur.jpg" url="/html/motiur.html"></WebView>
        	</Window>
        </Alloy>
        
    And image file is in the assets folder. Thanks
  13. Hans Knöchel 2018-01-24

    [~morahman] Where exactly did you put the <use-app-thinning> flag?
  14. Motiur Rahman 2018-01-25

    [~hknoechel], I added it inside the tag
        <ios>
                <enable-launch-screen-storyboard>true</enable-launch-screen-storyboard>
                <use-app-thinning>false</use-app-thinning>
                <plist>
                    <dict>
                        <key>UISupportedInterfaceOrientations~iphone</key>
                        <array>
                            <string>UIInterfaceOrientationPortrait</string>
                        </array>
                        <key>UISupportedInterfaceOrientations~ipad</key>
                        <array>
                            <string>UIInterfaceOrientationPortrait</string>
                            <string>UIInterfaceOrientationPortraitUpsideDown</string>
                            <string>UIInterfaceOrientationLandscapeLeft</string>
                            <string>UIInterfaceOrientationLandscapeRight</string>
                        </array>
                        <key>UIRequiresPersistentWiFi</key>
                        <false/>
                        <key>UIPrerenderedIcon</key>
                        <false/>
                        <key>UIStatusBarHidden</key>
                        <false/>
                        <key>UIStatusBarStyle</key>
                        <string>UIStatusBarStyleDefault</string>
                    </dict>
                </plist>
            </ios>
        
    Thanks!
  15. Hans Knöchel 2018-05-18

    Update: We have discussed this internally and came to the conclusion that it is currently not possible to reference images from the asset catalog in local web views, which is an iOS limitation in general. There are plans to have whitelisted files and/or directories, but that has not been scoped so far. Any contributions to do so are welcome!

JSON Source