tools:title=”RemoteSampleData”

vladimirwrites

Vladimir Jovanović

Posted on March 25, 2019

tools:title=”RemoteSampleData”

What I’ve learned from my previous article is that the best way to gain new knowledge about a certain topic is to write about it. When I first wrote the article, I had no idea that you can create custom sampledata for your Android project. (If you don’t have a clue what sampledata is, please read tools:title=”LayoutPreview”) And then someone sent me this.

It sounded like a really cool feature, so I made the list of my favorite characters from Lord of the Rings, used it as sampledata, and got this glorious layout preview.

LotR

Later on, I wanted to include it in my other projects, but the only option that I had was to copy/paste the sampledata from one project to another, and that didn’t make any sense. Then I did what every (lazy) developer would do, asked a question on StackOverflow.

After 10 views and no answer in sight, I’ve decided to sacrifice a bit of my reputation and start a bounty. And it worked. I got my answer, which I will share with you.

To use sampledata between multiple projects you first have to host it and then have a Gradle script which will download it into your project’s sampledata folder. This is the code which does that:

The first script will delete sampledata once you do a clean build, and the second one will create sampledata folder in case it doesn’t exist, and then download sample files into it. It works like a charm and from now on you can go crazy with your layout previews. I know that from now on I will never again use @tools:sample/lorem/random.

Developers developers

This code can be found in GitHub repo.

I’ve also added some sample data and will keep adding more. If you notice that something is missing or could be improved, feel free to contribute. This could be a great opportunity for novice developers to make their first contribution 😉.

Thanks for reading! If you enjoyed this story, please click the ❤️ button and share to help others find it! Feel free to leave a comment 💬 below.
Have feedback? Let’s be friends on Twitter.

💖 💪 🙅 🚩
vladimirwrites
Vladimir Jovanović

Posted on March 25, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

tools:title=”RemoteSampleData”
android tools:title=”RemoteSampleData”

March 25, 2019

tools:title=”LayoutPreview”
android tools:title=”LayoutPreview”

March 21, 2019