How do I get OSMDroid sample code to show map tiles after clearing the app storage?
23:06 14 Aug 2024

I am following the osmdroid sample code: https://github.com/osmdroid/osmdroid/wiki/How-to-use-the-osmdroid-library-(Kotlin). I also attempted the solution from here: osmdroid map tiles showing blank

My permissions:

    
    
    
    

I also added android:requestLegacyExternalStorage="true" to the application in the manifest.

My xml:



    

My onCreate:

private lateinit var map : MapView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        getInstance().load(this, PreferenceManager.getDefaultSharedPreferences(this))
        setContentView(R.layout.main)

        map = findViewById(R.id.map)
        map.setTileSource(TileSourceFactory.MAPNIK)
    }

Results: The map loads at first. When I clear the app's storage, the map goes away and doesn't come back, only showing a blank grid with no tiles.

I assume it isn't invalidating the cache after I clear the app's storage?

update:

I tried checking for cache storage handling as this article suggests: https://github.com/osmdroid/osmdroid/wiki/Important-notes-on-using-osmdroid-in-your-app#handling-cache-storage. I checked the result of StorageUtils.isWritable(getInstance().osmdroidTileCache) and it threw (and caught) a null pointer error: Unable to create base path at null.

update 2: I noticed in the logs this warning/error: IOException downloading MapTile: /0/0/0 : javax.net.ssl.SSLHandshakeException: Chain validation failed. According to this article: OSM IO Exception downloading MapTile it's due to not having write permissions in your manifest. I do have write permissions, but my IDE is warning me, WRITE_EXTERNAL_STORAGE is deprecated (and is not granted) when targeting Android 13+. So I suspect that this is the real problem

android-jetpack-compose osmdroid