Skip to content

Commit 494d2cc

Browse files
committed
add hashing example app that uses swift-java jni mode
1 parent d24aaef commit 494d2cc

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

+1844
-0
lines changed

hashing-example/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.DS_STORE
2+
3+
# Swift
4+
.build/
5+
.swiftpm/
6+
Package.resolved
7+
8+
# Gradle files
9+
.gradle/
10+
build/
11+
12+
# Local configuration file (sdk path, etc)
13+
local.properties
14+
15+
# Log/OS Files
16+
*.log
17+
18+
# Android Studio generated files and folders
19+
captures/
20+
.externalNativeBuild/
21+
.cxx/
22+
*.aab
23+
*.apk
24+
output-metadata.json
25+
26+
# IntelliJ
27+
*.iml
28+
.idea/
29+
misc.xml
30+
deploymentTargetDropDown.xml
31+
render.experimental.xml
32+
33+
# Keystore files
34+
*.jks
35+
*.keystore
36+
37+
# Google Services (e.g. APIs or Firebase)
38+
google-services.json
39+
40+
# Android Profiling
41+
*.hprof
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
5+
}
6+
7+
android {
8+
namespace = "com.example.hashingapp"
9+
compileSdk = 36
10+
11+
defaultConfig {
12+
applicationId = "com.example.hashingapp"
13+
minSdk = 28
14+
targetSdk = 36
15+
versionCode = 1
16+
versionName = "1.0"
17+
18+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
21+
buildTypes {
22+
release {
23+
isMinifyEnabled = false
24+
proguardFiles(
25+
getDefaultProguardFile("proguard-android-optimize.txt"),
26+
"proguard-rules.pro"
27+
)
28+
}
29+
}
30+
compileOptions {
31+
sourceCompatibility = JavaVersion.VERSION_11
32+
targetCompatibility = JavaVersion.VERSION_11
33+
}
34+
kotlinOptions {
35+
jvmTarget = "11"
36+
}
37+
buildFeatures {
38+
compose = true
39+
}
40+
}
41+
42+
dependencies {
43+
44+
implementation(libs.androidx.core.ktx)
45+
implementation(libs.androidx.lifecycle.runtime.ktx)
46+
implementation(libs.androidx.activity.compose)
47+
implementation(platform(libs.androidx.compose.bom))
48+
implementation(libs.androidx.ui)
49+
implementation(libs.androidx.ui.graphics)
50+
implementation(libs.androidx.ui.tooling.preview)
51+
implementation(libs.androidx.material3)
52+
implementation(files("../../hashing-lib/build/outputs/aar/hashing-lib-release.aar"))
53+
testImplementation(libs.junit)
54+
androidTestImplementation(libs.androidx.junit)
55+
androidTestImplementation(libs.androidx.espresso.core)
56+
androidTestImplementation(platform(libs.androidx.compose.bom))
57+
androidTestImplementation(libs.androidx.ui.test.junit4)
58+
debugImplementation(libs.androidx.ui.tooling)
59+
debugImplementation(libs.androidx.ui.test.manifest)
60+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
package com.example.hashingapp
14+
15+
import androidx.test.platform.app.InstrumentationRegistry
16+
import androidx.test.ext.junit.runners.AndroidJUnit4
17+
18+
import org.junit.Test
19+
import org.junit.runner.RunWith
20+
21+
import org.junit.Assert.*
22+
23+
/**
24+
* Instrumented test, which will execute on an Android device.
25+
*
26+
* See [testing documentation](http://d.android.com/tools/testing).
27+
*/
28+
@RunWith(AndroidJUnit4::class)
29+
class ExampleInstrumentedTest {
30+
@Test
31+
fun useAppContext() {
32+
// Context of the app under test.
33+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
34+
assertEquals("com.example.hashingapp", appContext.packageName)
35+
}
36+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.HashingApp">
14+
<activity
15+
android:name=".MainActivity"
16+
android:exported="true"
17+
android:label="@string/app_name"
18+
android:theme="@style/Theme.HashingApp">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
package com.example.hashingapp
14+
15+
import android.os.Bundle
16+
import androidx.activity.ComponentActivity
17+
import androidx.activity.compose.setContent
18+
import androidx.activity.enableEdgeToEdge
19+
import androidx.compose.foundation.layout.Arrangement
20+
import androidx.compose.foundation.layout.Column
21+
import androidx.compose.foundation.layout.fillMaxSize
22+
import androidx.compose.foundation.layout.fillMaxWidth
23+
import androidx.compose.foundation.layout.padding
24+
import androidx.compose.material3.Button
25+
import androidx.compose.material3.MaterialTheme
26+
import androidx.compose.material3.Scaffold
27+
import androidx.compose.material3.Surface
28+
import androidx.compose.material3.Text
29+
import androidx.compose.material3.TextField
30+
import androidx.compose.runtime.Composable
31+
import androidx.compose.runtime.mutableStateOf
32+
import androidx.compose.runtime.remember
33+
import androidx.compose.ui.Modifier
34+
import androidx.compose.ui.tooling.preview.Preview
35+
import androidx.compose.ui.unit.dp
36+
import com.example.hashingapp.ui.theme.HashingAppTheme
37+
import com.example.swifthashing.SwiftHashing
38+
39+
class MainActivity : ComponentActivity() {
40+
override fun onCreate(savedInstanceState: Bundle?) {
41+
super.onCreate(savedInstanceState)
42+
enableEdgeToEdge()
43+
setContent {
44+
HashingAppTheme {
45+
Surface (
46+
modifier = Modifier.fillMaxSize().padding(top = 64.dp),
47+
color = MaterialTheme.colorScheme.background
48+
) {
49+
HashScreen()
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
@Composable
57+
fun HashScreen() {
58+
val input = remember { mutableStateOf("") }
59+
val hashResult = remember { mutableStateOf("") }
60+
61+
Column(
62+
modifier = Modifier
63+
.fillMaxSize()
64+
.padding(32.dp),
65+
verticalArrangement = Arrangement.spacedBy(12.dp)
66+
) {
67+
TextField(
68+
value = input.value,
69+
onValueChange = { input.value = it },
70+
label = { Text("Enter text to hash") },
71+
modifier = Modifier.fillMaxWidth()
72+
)
73+
74+
Button(
75+
onClick = {
76+
hashResult.value = SwiftHashing.hash(input.value)
77+
}
78+
) {
79+
Text("Hash")
80+
}
81+
82+
if (hashResult.value.isNotEmpty()) {
83+
Text(
84+
text = hashResult.value,
85+
style = MaterialTheme.typography.bodyMedium
86+
)
87+
}
88+
}
89+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
package com.example.hashingapp.ui.theme
14+
15+
import androidx.compose.ui.graphics.Color
16+
17+
val Purple80 = Color(0xFFD0BCFF)
18+
val PurpleGrey80 = Color(0xFFCCC2DC)
19+
val Pink80 = Color(0xFFEFB8C8)
20+
21+
val Purple40 = Color(0xFF6650a4)
22+
val PurpleGrey40 = Color(0xFF625b71)
23+
val Pink40 = Color(0xFF7D5260)

0 commit comments

Comments
 (0)