Skip to content

Commit

Permalink
KMP sample update
Browse files Browse the repository at this point in the history
 - android sdk 35 & ios 18
 - kotlin 2.1.0
 - gradle 8.10
 - AGP 8.7
  • Loading branch information
vsima committed Dec 5, 2024
1 parent 60ef068 commit 4610ba4
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 63 deletions.
3 changes: 2 additions & 1 deletion samples/kmp/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ captures
.externalNativeBuild
.cxx
local.properties
xcuserdata
xcuserdata
.kotlin
28 changes: 13 additions & 15 deletions samples/kmp/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
plugins {
id("com.android.application")
kotlin("android")
kotlin("plugin.compose")
}

android {
namespace = "com.example.kmpsample.android"
compileSdk = 33
compileSdk = 35
defaultConfig {
applicationId = "com.example.kmpsample.android"
minSdk = 24
targetSdk = 33
targetSdk = 35
versionCode = 1
versionName = "1.0"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.12"
}
packagingOptions {
packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
}
Expand All @@ -30,20 +28,20 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
}

dependencies {
implementation(project(":shared"))
implementation("androidx.compose.ui:ui:1.3.1")
implementation("androidx.compose.ui:ui-tooling:1.3.1")
implementation("androidx.compose.ui:ui-tooling-preview:1.3.1")
implementation("androidx.compose.foundation:foundation:1.3.1")
implementation("androidx.compose.material:material:1.3.1")
implementation("androidx.activity:activity-compose:1.6.1")
implementation("androidx.compose.ui:ui:1.7.5")
implementation("androidx.compose.ui:ui-tooling:1.7.5")
implementation("androidx.compose.ui:ui-tooling-preview:1.7.5")
implementation("androidx.compose.foundation:foundation:1.7.5")
implementation("androidx.compose.material:material:1.7.5")
implementation("androidx.activity:activity-compose:1.9.3")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ package com.example.kmpsample.android
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.*
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.kmpsample.Sample

class MainActivity : ComponentActivity() {
Expand All @@ -28,7 +34,14 @@ class MainActivity : ComponentActivity() {

@Composable
fun GreetingView(text: String) {
Text(text = text)
Column(
modifier = Modifier.padding(16.dp),
verticalArrangement = Arrangement.Center
) {
Text(
text = text
)
}
}

@Preview
Expand Down
12 changes: 6 additions & 6 deletions samples/kmp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
//trick: for the same plugin versions in all sub-modules
id("com.android.application").version("7.4.1").apply(false)
id("com.android.library").version("7.4.1").apply(false)
kotlin("android").version("1.9.23").apply(false)
kotlin("multiplatform").version("1.9.23").apply(false)
id("com.android.application").version("8.7.3").apply(false)
id("com.android.library").version("8.7.3").apply(false)
kotlin("android").version("2.1.0").apply(false)
kotlin("plugin.compose").version("2.1.0").apply(false)
kotlin("multiplatform").version("2.1.0").apply(false)
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
delete(rootProject.layout.buildDirectory)
}
Binary file modified samples/kmp/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion samples/kmp/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
38 changes: 25 additions & 13 deletions samples/kmp/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +82,12 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +134,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
23 changes: 13 additions & 10 deletions samples/kmp/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand All @@ -26,6 +28,7 @@ if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -42,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -56,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
2 changes: 1 addition & 1 deletion samples/kmp/iosApp/Podfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
target 'iosApp' do
use_frameworks!
platform :ios, '14.1'
platform :ios, '18'
pod 'shared', :path => '../shared'
end
6 changes: 3 additions & 3 deletions samples/kmp/iosApp/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ EXTERNAL SOURCES:
:path: "../shared"

SPEC CHECKSUMS:
shared: 973e5c894781ebff8382176ea25326e62f08b171
shared: b2f1e46b5dd33f47e8467e5b4aab48df66e69197
SwiftProtobuf: 59d9ea2eb5f84b509f32d170a65f3348ae758f1e
TrustWalletCore: 53f09313edb1c010de78314d023c67d2d4654864

PODFILE CHECKSUM: f282da88f39e69507b0a255187c8a6b644477756
PODFILE CHECKSUM: 81dfb0baa6aaca56ab433de92eef03723c36f7f9

COCOAPODS: 1.11.3
COCOAPODS: 1.15.2
16 changes: 10 additions & 6 deletions samples/kmp/shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

plugins {
kotlin("multiplatform")
Expand All @@ -7,10 +8,14 @@ plugins {
}

kotlin {
android {
jvmToolchain(17)

androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
compileTaskProvider.configure {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_17)
}
}
}
}
Expand All @@ -22,7 +27,7 @@ kotlin {
summary = "Some description for the Shared Module"
homepage = "Link to the Shared Module homepage"
version = "1.0"
ios.deploymentTarget = "14.1"
ios.deploymentTarget = "18"
dependencies {
pod("TrustWalletCore", moduleName = "WalletCore")
}
Expand Down Expand Up @@ -87,9 +92,8 @@ kotlin {

android {
namespace = "com.example.kmpsample"
compileSdk = 33
compileSdk = 35
defaultConfig {
minSdk = 24
targetSdk = 33
}
}
17 changes: 16 additions & 1 deletion samples/kmp/shared/shared.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@ Pod::Spec.new do |spec|
spec.summary = 'Some description for the Shared Module'
spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '14.1'
spec.ios.deployment_target = '18'
spec.dependency 'TrustWalletCore'

if !Dir.exist?('build/cocoapods/framework/shared.framework') || Dir.empty?('build/cocoapods/framework/shared.framework')
raise "
Kotlin framework 'shared' doesn't exist yet, so a proper Xcode project can't be generated.
'pod install' should be executed after running ':generateDummyFramework' Gradle task:
./gradlew :shared:generateDummyFramework
Alternatively, proper pod installation is performed during Gradle sync in the IDE (if Podfile location is set)"
end

spec.xcconfig = {
'ENABLE_USER_SCRIPT_SANDBOXING' => 'NO',
}

spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':shared',
'PRODUCT_MODULE_NAME' => 'shared',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package com.example.kmpsample
import com.trustwallet.core.*

import com.trustwallet.core.CoinType
import com.trustwallet.core.HDWallet

class Sample {
private val platform: Platform = getPlatform()

fun greet(): String {
var log = "Wallet Core KMP on platform: ${platform.name}!\n\n"
val wallet = HDWallet(256, "")
log += "Created mnemonic: ${wallet.mnemonic}\n"
log += "Created mnemonic: ${wallet.mnemonic}\n\n"
val btcAddress = wallet.getAddressForCoin(CoinType.Bitcoin)
log += "Bitcoin address: ${btcAddress}\n\n"
val ethAddress = wallet.getAddressForCoin(CoinType.Ethereum)
log += "Bitcoin address: ${btcAddress}\n"
log += "Ethereum address: ${ethAddress}\n"
log += "Ethereum address: ${ethAddress}\n\n"
return log
}
}

0 comments on commit 4610ba4

Please sign in to comment.