Added android sample app

This commit is contained in:
Ugljesa Jovanovic 2020-10-17 11:41:38 +02:00
parent 1e4c56e58a
commit 14cf103ac7
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
26 changed files with 534 additions and 3 deletions

View File

@ -30,6 +30,13 @@ object Versions {
val kotlinPoet = "1.6.0"
val sharedModule = "0.1.0-SNAPSHOT"
val ktor = "1.3.2"
val timber = "4.7.1"
}
@ -52,6 +59,8 @@ object Deps {
val kotlinBigNum = "com.ionspin.kotlin:bignum:${Versions.kotlinBigNumVersion}"
val apiProject = ":multiplatform-crypto-api"
val sharedModule = "com.ionspin.kotlin.crypto.sample:shared:${Versions.sharedModule}"
}
object Js {
@ -100,6 +109,15 @@ object Deps {
}
object Android {
val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.kotlinCoroutines}"
val ktorClientOkHttp = "io.ktor:ktor-client-okhttp:${Versions.ktor}"
val ktorClient = "io.ktor:ktor-client-android:${Versions.ktor}"
val ktorClientSerialization = "io.ktor:ktor-client-serialization-jvm:${Versions.ktor}"
val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-runtime:${Versions.kotlinSerialization}"
val timber = "com.jakewharton.timber:timber:${Versions.timber}"
}
}
@ -113,5 +131,8 @@ object PluginsDeps {
val taskTree = "com.dorongold.task-tree"
val androidLibrary = "com.android.library"
val kotlinAndroidExtensions = "kotlin-android-extensions"
val androidApplication = "com.android.application"
val kotlinAndroid = "kotlin-android"
val kapt = "kotlin-kapt"
}

View File

@ -60,7 +60,7 @@ println("Idea active: $ideaActive")
android {
compileSdkVersion(29)
defaultConfig {
minSdkVersion(24)
minSdkVersion(21)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"

View File

@ -22,9 +22,11 @@ import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
plugins {
kotlin(PluginsDeps.multiplatform)
id(PluginsDeps.kapt)
id(PluginsDeps.androidApplication)
id(PluginsDeps.kotlinAndroidExtensions)
id (PluginsDeps.mavenPublish)
id (PluginsDeps.signing)
id (PluginsDeps.node) version Versions.nodePlugin
}
val sonatypeStaging = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
@ -40,10 +42,11 @@ val sonatypeUsernameEnv : String? = System.getenv()["SONATYPE_USERNAME"]
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/terl/lazysodium-maven")
}
group = "com.ionspin.kotlin"
version = "0.0.4-SNAPSHOT"
version = "0.1.0-SNAPSHOT"
val ideaActive = System.getProperty("idea.active") == "true"
@ -69,6 +72,9 @@ kotlin {
}
}
android()
linuxX64("linux") {
binaries {
@ -125,6 +131,23 @@ kotlin {
}
}
}
// select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.() -> Unit) -> org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "LibsodiumBindingsSampleApplication"
export(Deps.Common.sharedModule)
freeCompilerArgs += ("-Xobjc-generics")
}
}
}
}
runningOnWindows {
@ -154,6 +177,34 @@ kotlin {
}
}
val androidMain by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:${Versions.kotlin}")
implementation("androidx.appcompat:appcompat:1.2.0")
implementation("androidx.core:core-ktx:1.3.2")
implementation("androidx.constraintlayout:constraintlayout:2.0.2")
implementation("com.google.android.material:material:1.3.0-alpha03")
// implementation("androidx.ui:ui-tooling:$composeDevVersion")
// implementation("androidx.ui:ui-layout:$composeDevVersion")
// implementation("androidx.ui:ui-material:$composeDevVersion")
// implementation("androidx.ui:ui-foundation:$composeDevVersion")
// implementation("androidx.ui:ui-framework:$composeDevVersion")
implementation(Deps.Android.coroutines)
implementation(Deps.Android.timber)
// implementation("androidx.compose:compose-runtime:$composeDevVersion")
}
}
val androidTest by getting {
dependencies {
implementation(kotlin(Deps.Jvm.test))
implementation(kotlin(Deps.Jvm.testJUnit))
implementation(Deps.Jvm.coroutinesTest)
implementation(kotlin(Deps.Jvm.reflection))
implementation(Deps.Jvm.coroutinesCore)
}
}
val nativeMain by creating {
dependsOn(commonMain)
@ -265,6 +316,82 @@ kotlin {
}
android {
compileSdkVersion(29)
defaultConfig {
applicationId = "com.ionspin.kotlin.crypto.sample"
minSdkVersion(21)
targetSdkVersion(29)
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
}
}
sourceSets {
val main by getting
main.manifest.srcFile("src/androidMain/AndroidManifest.xml")
main.java.srcDirs("src/androidMain/kotlin")
main.res.srcDirs("src/androidMain/res")
}
packagingOptions {
exclude("META-INF/library_release.kotlin_module")
exclude("META-INF/kotlinx-serialization-runtime.kotlin_module")
exclude("META-INF/ktor-http.kotlin_module")
exclude("META-INF/ktor-utils.kotlin_module")
exclude("META-INF/ktor-io.kotlin_module")
exclude("META-INF/ktor-*")
}
compileOptions {
setSourceCompatibility(JavaVersion.VERSION_1_8)
setTargetCompatibility(JavaVersion.VERSION_1_8)
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
// buildFeatures {
// // Enables Jetpack Compose for this module
// this.compose = true
// }
// composeOptions {
// kotlinCompilerExtensionVersion = "0.1.0-dev05"
// }
// Magic for compose dev08, but it doesn't work with serialization plugin because of IR. Leave here for future reference.
// project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java)
// .configureEach {
// println("Task: $this")
// if (this.name.contains("Android")) {
// println("Setting plugins: $this")
// this.kotlinOptions.freeCompilerArgs += listOf(
// "-P",
// "plugin:androidx.compose.plugins.idea:enabled=true"
// )
// this.kotlinOptions.freeCompilerArgs += "-Xplugin=${project.rootDir}/compose-compiler-0.1.0-dev08.jar"
// this.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
// }
// }
// project.tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile::class.java)
// .forEach { compile ->
// compile.kotlinOptions.freeCompilerArgs += listOf(
// "-P",
// "plugin:androidx.compose.plugins.idea:enabled=true"
// )
// compile.kotlinOptions.freeCompilerArgs += "-Xplugin=${project.rootDir}/compose-compiler-0.1.0-dev08.jar"
// compile.kotlinOptions.freeCompilerArgs += "-Xuse-ir"
// println("Compile: $compile")
// println("Compiler free args ${compile.kotlinOptions.freeCompilerArgs}")
// }
}
tasks {

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ionspin.kotlin.crypto.sample">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".LibsodiumBindingsSampleApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"> <!-- Just for development -->
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustPan|adjustResize"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -0,0 +1,31 @@
/*
* Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
*/
package com.ionspin.kotlin.crypto.sample
import android.app.Application
import com.ionspin.kotlin.crypto.LibsodiumInitializer
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import timber.log.Timber
/**
* @author [Ugljesa Jovanovic](ugi@mobilabsolutions.com)
*/
class LibsodiumBindingsSampleApp : Application() {
override fun onCreate() {
super.onCreate()
Timber.plant(Timber.DebugTree())
val initialization = GlobalScope.async {
LibsodiumInitializer.initialize()
}
runBlocking {
initialization.await()
}
}
}

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
*/
package com.ionspin.kotlin.crypto.sample
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.ionspin.kotlin.crypto.hash.Hash
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
import com.ionspin.kotlin.crypto.util.toHexString
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val hash = Hash.sha512("123".encodeToUByteArray())
helloWorldTextView.setText("Hash (SHA512) of 123: ${hash.toHexString()}")
}
}

View File

@ -0,0 +1,34 @@
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<vector xmlns:aapt="http://schemas.android.com/aapt"
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
<aapt:attr name="android:fillColor">
<gradient
android:endX="85.84757"
android:endY="92.4963"
android:startX="42.9492"
android:startY="49.59793"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</vector>

View File

@ -0,0 +1,174 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillColor="#3DDC84"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
</vector>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/helloWorldTextView"
tools:text="Hello world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<resources>
<color name="colorPrimary">#0069A1</color>
<color name="colorPrimaryDark">#004970</color>
<color name="colorAccent">#FF5722</color>
<color name="lighterBackground">#FF656565</color>
</resources>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<resources>
<dimen name="omnipresentDimension">16dp</dimen>
</resources>

View File

@ -0,0 +1,7 @@
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<resources>
<string name="app_name">Lbsodium Bindings Sample</string>
</resources>

View File

@ -0,0 +1,26 @@
<!--
~ Copyright (c) 2020 Ugljesa Jovanovic (ugljesa.jovanovic@ionspin.com)
-->
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="buttonStyle">@style/MyCustomButton</item>
</style>
<style name="MyCustomButton" parent="Widget.AppCompat.Button">
<item name="android:textColor">@android:color/primary_text_dark</item>
<item name="android:backgroundTint">@color/colorPrimary</item>
<!-- <item name="android:textStyle">bold</item>-->
<!-- <item name="android:paddingLeft">16dp</item>-->
<!-- <item name="android:paddingRight">16dp</item>-->
</style>
</resources>