Skip to content

Commit 1c8b618

Browse files
Merge pull request #35 from Kotlin/update-to-1.4
Update to 1.4
2 parents cee27f4 + 4bd948f commit 1c8b618

File tree

54 files changed

+803
-761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+803
-761
lines changed

README.md

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,22 @@
1-
# Multiplatform sample
2-
This example shows you how to use Kotlin Multiplatform in an monorepo.
3-
The MPP code can be found inside the [greeting/](greeting/) directory while
4-
the "UI" implementations can be found inside the [androidApp/](androidApp/) resp. [iosApp/](iosApp/) dir.
1+
# Kotlin Multiplatform Mobile Sample
52

6-
This sample based on the [multiplatform documentation](http://kotlinlang.org/docs/reference/building-mpp-with-gradle.html).
7-
If you have questions about the structure or how it works take a look at the documentation there.
3+
This is a **Kotlin Multiplatform Mobile (KMM) Project**. It includes iOS and Android applications with a native UI and a module with code shared on iOS and Android.
84

9-
## iOS
5+
## Features
106

11-
To compile the project from Xcode just open `iosApp/iosApp.xcodeproj` and run the application.
12-
The [swift tests](iosApp/iosAppTests/iosAppTests.swift) also can be executed from Xcode.
7+
This sample demonstrates basic KMM features:
8+
* Using platform-specific APIs with the expect/actual mechanism (see `Platform.kt`)
9+
* Tests for Shared Module (see `CalculatorTest.kt`, `iosTest.kt`, `androidTest.kt`)
1310

14-
To compile a framework for ios simulator from the command line execute:
11+
## How to use
1512

16-
```
17-
> ./gradlew :greeting:build
18-
```
13+
With the [KMM plugin for Android Studio](https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile) you can run, test, and debug shared code on both platforms without switching IDEs. Run and debug the application by selecting the corresponding configuration in the **Run configuration** menu. Run and debug shared module tests by pressing the gutter icon on a test class or method.
1914

20-
To compile the framework for a device use the `device` project property:
15+
## Related links
2116

22-
```
23-
> ./gradlew :greeting:build -Pdevice=true
24-
```
17+
* Visit [Kotlin Multiplatform Mobile Developer Portal](https://kotlinlang.org/lp/mobile/) to learn more about the technology
18+
* Check out the [Networking and data storage with KMM hands-on](https://play.kotlinlang.org/hands-on/Networking%20and%20Data%20Storage%20with%20Kotlin%20Multiplatfrom%20Mobile/) lab to learn how to create a mobile application for Android and iOS with a shared codebase with Ktor and SQLDelight.
2519

26-
To run kotlin tests (including the [common ones](greeting/src/commonTest/kotlin/CalculatorTest.kt))
27-
on an iOS simulator execute:
2820

29-
```
30-
> ./gradlew :greeting:iosTest
31-
```
3221

33-
By default the `iPhone 8` simulator is used. One can change this setting using the `iosDevice` project property:
3422

35-
```
36-
> ./gradlew :greeting:iosTest -PiosDevice='iPhone 7'
37-
```
38-
39-
40-
## Android
41-
42-
The application can be built and executed on a device or emulator using Android Studio 3.2 or higher.
43-
One can also compile the application and run tests from the command line:
44-
45-
```
46-
> ./gradlew :androidApp:build
47-
```

androidApp/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

androidApp/build.gradle.kts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
plugins {
22
id("com.android.application")
3-
id("org.jetbrains.kotlin.multiplatform")
3+
kotlin("android")
4+
id("kotlin-android-extensions")
45
}
6+
group = "com.jetbrains"
7+
version = "1.0-SNAPSHOT"
58

9+
repositories {
10+
gradlePluginPortal()
11+
google()
12+
jcenter()
13+
mavenCentral()
14+
}
15+
dependencies {
16+
implementation(project(":shared"))
17+
implementation("com.google.android.material:material:1.2.0")
18+
implementation("androidx.appcompat:appcompat:1.2.0")
19+
implementation("androidx.constraintlayout:constraintlayout:1.1.3")
20+
}
621
android {
722
compileSdkVersion(29)
823
defaultConfig {
9-
applicationId = "org.konan.multiplatform"
10-
minSdkVersion(15)
24+
applicationId = "com.jetbrains.androidApp"
25+
minSdkVersion(24)
1126
targetSdkVersion(29)
1227
versionCode = 1
1328
versionName = "1.0"
1429
}
1530
buildTypes {
1631
getByName("release") {
17-
isMinifyEnabled = true
18-
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
32+
isMinifyEnabled = false
1933
}
2034
}
21-
packagingOptions {
22-
exclude("META-INF/main.kotlin_module")
23-
}
24-
}
25-
26-
kotlin {
27-
android()
28-
}
29-
30-
dependencies {
31-
implementation("org.jetbrains.kotlin:kotlin-stdlib")
32-
implementation(project(":greeting"))
33-
34-
implementation("androidx.appcompat:appcompat:1.1.0")
35-
36-
testImplementation("junit:junit:4.12")
3735
}

androidApp/proguard-rules.pro

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="org.konan.multiplatform">
3-
<application
4-
android:name=".MyApplication"
5-
android:allowBackup="true"
6-
android:supportsRtl="true"
7-
android:theme="@style/AppTheme">
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.jetbrains.androidApp">
83

9-
<activity
10-
android:name=".MainActivity"
11-
android:theme="@style/AppTheme">
12-
<intent-filter>
13-
<action android:name="android.intent.action.MAIN" />
14-
<category android:name="android.intent.category.LAUNCHER" />
15-
</intent-filter>
16-
</activity>
4+
<application
5+
android:allowBackup="false"
6+
android:supportsRtl="true"
7+
android:theme="@style/AppTheme">
8+
<activity android:name="com.jetbrains.kmm.androidApp.MainActivity">
9+
<intent-filter>
10+
<action android:name="android.intent.action.MAIN"/>
1711

12+
<category android:name="android.intent.category.LAUNCHER"/>
13+
</intent-filter>
14+
</activity>
1815
</application>
1916

20-
</manifest>
17+
</manifest>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.jetbrains.kmm.androidApp
2+
3+
import androidx.appcompat.app.AppCompatActivity
4+
import android.os.Bundle
5+
import android.text.Editable
6+
import android.text.TextWatcher
7+
import android.widget.EditText
8+
import com.jetbrains.kmm.shared.Greeting
9+
import com.jetbrains.kmm.shared.Calculator
10+
import android.widget.TextView
11+
import com.jetbrains.androidApp.R
12+
13+
fun greet(): String {
14+
return Greeting().greeting()
15+
}
16+
17+
class MainActivity : AppCompatActivity() {
18+
override fun onCreate(savedInstanceState: Bundle?) {
19+
super.onCreate(savedInstanceState)
20+
setContentView(R.layout.activity_main)
21+
22+
val tv: TextView = findViewById(R.id.textView)
23+
tv.text = greet()
24+
25+
val numATV: EditText = findViewById(R.id.editTextNumberDecimalA)
26+
val numBTV: EditText = findViewById(R.id.editTextNumberDecimalB)
27+
28+
val sumTV: TextView = findViewById(R.id.textViewSum)
29+
30+
val textWatcher = object: TextWatcher {
31+
override fun afterTextChanged(s: Editable?) {
32+
try {
33+
val numA = Integer.parseInt(numATV.text.toString())
34+
val numB = Integer.parseInt(numBTV.text.toString())
35+
sumTV.text = "= " + Calculator.sum(numA, numB).toString()
36+
} catch(e: NumberFormatException) {
37+
sumTV.text = "= 🤔"
38+
}
39+
}
40+
41+
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
42+
43+
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
44+
}
45+
46+
numATV.addTextChangedListener(textWatcher)
47+
numBTV.addTextChangedListener(textWatcher)
48+
49+
}
50+
}

androidApp/src/main/kotlin/ui.kt

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout
2+
<androidx.constraintlayout.widget.ConstraintLayout
33
xmlns:android="http://schemas.android.com/apk/res/android"
4-
android:id="@+id/main_view"
5-
android:scrollbars="vertical"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
xmlns:app="http://schemas.android.com/apk/res-auto"
66
android:layout_width="match_parent"
77
android:layout_height="match_parent"
8-
android:orientation="vertical"/>
8+
android:id="@+id/main_view"
9+
tools:context="com.jetbrains.kmm.androidApp.MainActivity">
10+
11+
<LinearLayout
12+
android:layout_width="wrap_content"
13+
android:layout_height="wrap_content"
14+
android:orientation="vertical"
15+
app:layout_constraintBottom_toBottomOf="parent"
16+
app:layout_constraintLeft_toLeftOf="parent"
17+
app:layout_constraintRight_toRightOf="parent"
18+
app:layout_constraintTop_toTopOf="parent">
19+
<TextView
20+
android:layout_width="wrap_content"
21+
android:layout_height="wrap_content"
22+
android:text="Hello World!"
23+
android:id="@+id/textView"
24+
/>
25+
<LinearLayout
26+
android:layout_width="wrap_content"
27+
android:layout_height="match_parent"
28+
android:orientation="horizontal">
29+
30+
<EditText
31+
android:id="@+id/editTextNumberDecimalA"
32+
android:layout_width="30dp"
33+
android:layout_height="wrap_content"
34+
android:ems="10"
35+
android:inputType="number"
36+
android:autofillHints="" />
37+
<TextView
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:text="+"
41+
/>
42+
<EditText
43+
android:id="@+id/editTextNumberDecimalB"
44+
android:layout_width="30dp"
45+
android:layout_height="wrap_content"
46+
android:ems="10"
47+
android:inputType="number"
48+
android:autofillHints="" />
49+
<TextView
50+
android:layout_width="wrap_content"
51+
android:layout_height="wrap_content"
52+
android:id="@+id/textViewSum"
53+
android:text="= 🤔"
54+
/>
55+
</LinearLayout>
56+
</LinearLayout>
57+
58+
59+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
3-
<color name="colorPrimary">#3F51B5</color>
4-
<color name="colorPrimaryDark">#303F9F</color>
5-
<color name="colorAccent">#FF4081</color>
6-
</resources>
3+
<color name="colorPrimary">#6200EE</color>
4+
<color name="colorPrimaryDark">#3700B3</color>
5+
<color name="colorAccent">#03DAC5</color>
6+
</resources>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<resources>
2-
32
<!-- Base application theme. -->
43
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
54
<!-- Customize your theme here. -->
@@ -8,4 +7,4 @@
87
<item name="colorAccent">@color/colorAccent</item>
98
</style>
109

11-
</resources>
10+
</resources>

0 commit comments

Comments
 (0)