DiceRoller is a sample app using the Kotlin Multiplatform DataStore library to store and observe preferences.
The app can roll a given number of dice with the given number of sides and display the results. You can also choose to roll numbers until each die produces a unique value.
You can change the settings for the rolls on the bottom half of the screen. Saving the settings writes them to DataStore, which the top of the screen then observes, using the new settings for subsequent rolls.
The shared
module is the data layer implementation which includes the code accessing Preferences DataStore as well as the dice rolling logic. The androidApp
and iosApp
modules both depend on the shared
module, and they contain an Android app with Jetpack Compose UI and an iOS app with SwiftUI, respectively.
- Open the
DiceRoller
Gradle project in Android Studio - Run the app in the
androidApp
module
The iOS application can only be built and run on macOS. You also need to have CocoaPods installed, which can generally be done by running brew install cocoapods
or sudo gem install cocoapods
.
See CocoaPods Overview and Setup and Check your environment for more details.
- Install the Kotlin Multiplatform Mobile plugin
- Open the
DiceRoller
Gradle project in Android Studio - Choose the
iosApp
run configuration and run it
- Run
./gradlew shared:podInstall
in theDiceRoller
folder to initialize the project- You can skip this step if you've already opened the project in Android Studio and performed a Gradle sync
- Open
iosApp.xcworkspace
(and NOTiosApp.xcodeproj
!) in Xcode and start the active scheme
Copyright 2022 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.