From 67ea8ceefa65869bde81364418716e91b5b7e5b4 Mon Sep 17 00:00:00 2001 From: Javonne Martin Date: Mon, 24 May 2021 10:59:43 +0200 Subject: [PATCH 1/5] Various improvements in navigating to the wallet, added sslip.io clear text configuration --- sample/app/src/main/AndroidManifest.xml | 3 ++- .../java/io/walletconnect/example/MainActivity.kt | 15 +++++++++++---- sample/app/src/main/res/xml/network_config.xml | 8 ++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 sample/app/src/main/res/xml/network_config.xml diff --git a/sample/app/src/main/AndroidManifest.xml b/sample/app/src/main/AndroidManifest.xml index f1cca81..a6f07c8 100644 --- a/sample/app/src/main/AndroidManifest.xml +++ b/sample/app/src/main/AndroidManifest.xml @@ -8,7 +8,8 @@ android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" - android:name=".ExampleApplication"> + android:name=".ExampleApplication" + android:networkSecurityConfig="@xml/network_config"> diff --git a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt index 7c373dd..8006388 100644 --- a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt +++ b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt @@ -22,7 +22,9 @@ class MainActivity : Activity(), Session.Callback { when(status) { Session.Status.Approved -> sessionApproved() Session.Status.Closed -> sessionClosed() - Session.Status.Connected, + Session.Status.Connected -> { + navigateToWallet() + } Session.Status.Disconnected, is Session.Status.Error -> { // Do Stuff @@ -32,6 +34,13 @@ class MainActivity : Activity(), Session.Callback { override fun onMethodCall(call: Session.MethodCall) { } + + private fun navigateToWallet() { + val i = Intent(Intent.ACTION_VIEW) + i.data = Uri.parse(ExampleApplication.config.toWCUri()) + startActivity(i) + } + private fun sessionApproved() { uiScope.launch { screen_main_status.text = "Connected: ${ExampleApplication.session.approvedAccounts()}" @@ -61,9 +70,6 @@ class MainActivity : Activity(), Session.Callback { screen_main_connect_button.setOnClickListener { ExampleApplication.resetSession() ExampleApplication.session.addCallback(this) - val i = Intent(Intent.ACTION_VIEW) - i.data = Uri.parse(ExampleApplication.config.toWCUri()) - startActivity(i) } screen_main_disconnect_button.setOnClickListener { ExampleApplication.session.kill() @@ -86,6 +92,7 @@ class MainActivity : Activity(), Session.Callback { ::handleResponse ) this.txRequest = txRequest + navigateToWallet() } } diff --git a/sample/app/src/main/res/xml/network_config.xml b/sample/app/src/main/res/xml/network_config.xml new file mode 100644 index 0000000..a8f0840 --- /dev/null +++ b/sample/app/src/main/res/xml/network_config.xml @@ -0,0 +1,8 @@ + + + + sslip.io + localhost + + + From 5bbaa971cb9ca254c62116e0df5a2ca5e4e212f6 Mon Sep 17 00:00:00 2001 From: Javonne Martin Date: Mon, 24 May 2021 13:50:21 +0200 Subject: [PATCH 2/5] Fixed bridge server parsing booleans, fixed routing on transaction --- .../main/java/io/walletconnect/example/MainActivity.kt | 10 ++++++++-- .../io/walletconnect/example/server/BridgeServer.kt | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt index 8006388..c160cf1 100644 --- a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt +++ b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt @@ -23,7 +23,7 @@ class MainActivity : Activity(), Session.Callback { Session.Status.Approved -> sessionApproved() Session.Status.Closed -> sessionClosed() Session.Status.Connected -> { - navigateToWallet() + requestConnectionToWallet() } Session.Status.Disconnected, is Session.Status.Error -> { @@ -35,12 +35,18 @@ class MainActivity : Activity(), Session.Callback { override fun onMethodCall(call: Session.MethodCall) { } - private fun navigateToWallet() { + private fun requestConnectionToWallet() { val i = Intent(Intent.ACTION_VIEW) i.data = Uri.parse(ExampleApplication.config.toWCUri()) startActivity(i) } + private fun navigateToWallet() { + val i = Intent(Intent.ACTION_VIEW) + i.data = Uri.parse("wc:") + startActivity(i) + } + private fun sessionApproved() { uiScope.launch { screen_main_status.text = "Connected: ${ExampleApplication.session.approvedAccounts()}" diff --git a/sample/app/src/main/java/io/walletconnect/example/server/BridgeServer.kt b/sample/app/src/main/java/io/walletconnect/example/server/BridgeServer.kt index 4c372fd..b6833cd 100644 --- a/sample/app/src/main/java/io/walletconnect/example/server/BridgeServer.kt +++ b/sample/app/src/main/java/io/walletconnect/example/server/BridgeServer.kt @@ -14,11 +14,11 @@ import java.util.concurrent.ConcurrentHashMap class BridgeServer(moshi: Moshi) : WebSocketServer(InetSocketAddress(PORT)) { - private val adapter = moshi.adapter>( + private val adapter = moshi.adapter>( Types.newParameterizedType( Map::class.java, String::class.java, - String::class.java + Any::class.java ) ) @@ -41,8 +41,8 @@ class BridgeServer(moshi: Moshi) : WebSocketServer(InetSocketAddress(PORT)) { conn ?: error("Unknown socket") message?.also { val msg = adapter.fromJson(it) ?: error("Invalid message") - val type: String = msg["type"] ?: error("Type not found") - val topic: String = msg["topic"] ?: error("Topic not found") + val type: String = msg["type"] as String? ?: error("Type not found") + val topic: String = msg["topic"] as String? ?: error("Topic not found") when (type) { "pub" -> { var sendMessage = false From 9f0ed4bd6d7882f2a27acc98120e796a433bc12c Mon Sep 17 00:00:00 2001 From: mobilekosmos Date: Fri, 24 Sep 2021 14:48:56 +0200 Subject: [PATCH 3/5] Updated all dependencies + overall improvements DSL element 'dexOptions' is obsolete and should be removed. It will be removed in version 8.0 of the Android Gradle plugin. Using it has no effect, and the AndroidGradle plugin optimizes dexing automatically. Updated gradle to version 7 Replaced maven with maven-publish Removed kotlin extensions as required and adapted mainActivity code to this Removed multidex lib as not needed anymore from API 21 WebSocket lib old version was full of security bugs. For Android projects consisting of an app with library dependencies, it is recommended to set checkDependencies to true https://developer.android.com/studio/releases/gradle-plugin#improved_lint_for_library_dependencies --- build.gradle | 72 +++++++++---------- gradle.properties | 21 ++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- lib/build.gradle | 47 ++++++++---- sample/app/build.gradle | 54 ++++++++------ sample/app/src/main/AndroidManifest.xml | 3 +- .../example/ExampleApplication.kt | 4 +- .../io/walletconnect/example/MainActivity.kt | 30 ++++---- .../app/src/main/res/layout/screen_main.xml | 2 +- settings.gradle | 11 ++- 10 files changed, 153 insertions(+), 93 deletions(-) create mode 100644 gradle.properties diff --git a/build.gradle b/build.gradle index f0eeb00..66cdd9f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,50 +1,48 @@ +/** + * The buildscript block is where you configure the repositories and + * dependencies for Gradle itself—meaning, you should not include dependencies + * for your modules here. For example, this block includes the Android plugin for + * Gradle as a dependency because it provides the additional instructions Gradle + * needs to build Android app modules. + */ buildscript { ext { versions = [ - kotlin : "1.4.31", - moshi : '1.8.0', - okhttp : '3.11.0', - jupiter : '5.7.0', + kotlin : "1.5.31", + moshi : '1.12.0', + okhttp : '4.9.1', + jupiter : '5.8.1', - 'minSdk' : 14, - 'compileSdk' : 28, - 'buildTools' : '28.0.3', - 'androidPlugin' : '4.0.0', + 'minSdk' : 28, + 'compileSdk' : 31, - androidx_app_compat : '1.0.2', - androidx_card_view : '1.0.0', - androidx_constraint_layout: '1.1.3', - androidx_lifecycle : '2.0.0', - androidx_test_ext : '1.1.0', - androidx_recycler_view : '1.0.0', - androidx_room : '2.0.0', - - multidex : '2.0.1', - ] - - ext.deps = [ - android: [ - 'runtime' : 'com.google.android:android:4.1.1.4', - 'gradlePlugin': "com.android.tools.build:gradle:${versions.androidPlugin}", - ] + androidx_app_compat : '1.3.1', + androidx_card_view : '1.0.0', + androidx_constraint_layout: '1.1.3', + androidx_lifecycle : '2.0.0', + androidx_test_ext : '1.1.0', + androidx_recycler_view : '1.0.0', + androidx_room : '2.0.0', ] - versions.kotlin = '1.3.72' - } - - repositories { - google() - jcenter() - gradlePluginPortal() - mavenCentral() } + /** + * The dependencies block configures the dependencies Gradle needs to use + * to build your project. The following line adds Android plugin for Gradle + * version 4.2.0 as a classpath dependency. + */ dependencies { - classpath 'com.android.tools.build:gradle:4.0.0' + classpath 'com.android.tools.build:gradle:7.0.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin" - classpath 'com.github.ben-manes:gradle-versions-plugin:0.38.0' - // How can we move this to the sample folder - //classpath deps.android.gradlePlugin + } + repositories { + google() } } -apply plugin: "com.github.ben-manes.versions" +// By default, the plugins {} DSL resolves plugins from the public Gradle Plugin Portal. Apply not +// needed when using this. +plugins { + // Checks for newer lib versions. + id "com.github.ben-manes.versions" version "0.39.0" +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..98bed16 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,21 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8cf6eb5..29e4134 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/lib/build.gradle b/lib/build.gradle index 95ea957..3a98daa 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -1,19 +1,15 @@ -apply plugin: "kotlin" -apply plugin: 'maven' - -repositories { - mavenCentral() - maven { url 'https://jitpack.io' } +plugins { + id 'java-library' + id 'kotlin' + id 'maven-publish' } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin" - - implementation "com.github.komputing:khex:1.1.0" + implementation "com.github.komputing:khex:1.1.2" - implementation "org.bouncycastle:bcprov-jdk15to18:1.68" + implementation "org.bouncycastle:bcprov-jdk15to18:1.69" - implementation 'com.squareup.moshi:moshi:1.8.0' + implementation "com.squareup.moshi:moshi:${versions.moshi}" // TODO: it would be better to use the generated adapter by moshi // but for that we should move the implementations in different modules //kapt "com.squareup.moshi:moshi-kotlin-codegen:$versions.moshi" @@ -21,10 +17,13 @@ dependencies { implementation "com.squareup.okhttp3:okhttp:$versions.okhttp" testImplementation 'org.assertj:assertj-core:3.19.0' + + // (Required) Writing and executing Unit Tests on the JUnit Platform testImplementation "org.junit.jupiter:junit-jupiter-api:${versions.jupiter}" - testImplementation "org.junit.jupiter:junit-jupiter-params:${versions.jupiter}" - testRuntime "org.junit.jupiter:junit-jupiter-engine:${versions.jupiter}" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${versions.jupiter}" + // (Optional) If you need "Parameterized Tests" + testImplementation "org.junit.jupiter:junit-jupiter-params:${versions.jupiter}" testImplementation "com.squareup.okhttp3:mockwebserver:$versions.okhttp" } @@ -32,3 +31,25 @@ dependencies { test { useJUnitPlatform() } + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +afterEvaluate { + publishing { + publications { + // Creates a Maven publication called “walletconnectPublication”. + walletconnectPublication(MavenPublication) { + // Applies the component for the debug build variant. + from components.java + + groupId = 'com.github.WalletConnect' + artifactId = 'kotlin-walletconnect-lib' + version = '0.9.7' + } + } + } +} + diff --git a/sample/app/build.gradle b/sample/app/build.gradle index 9a4acef..3109e1a 100644 --- a/sample/app/build.gradle +++ b/sample/app/build.gradle @@ -1,14 +1,12 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' android { compileSdkVersion versions.compileSdk - buildToolsVersion versions.buildTools compileOptions { - sourceCompatibility JavaVersion.VERSION_1_7 - targetCompatibility JavaVersion.VERSION_1_7 + sourceCompatibility JavaVersion.VERSION_11 + targetCompatibility JavaVersion.VERSION_11 } defaultConfig { @@ -19,49 +17,59 @@ android { versionName '1.0.0' } - dexOptions { - jumboMode = true - } - lintOptions { textReport true textOutput 'stdout' + checkDependencies true } + /** + * The buildTypes block is where you can configure multiple build types. + * By default, the build system defines two build types: debug and release. The + * debug build type is not explicitly shown in the default build configuration, + * but it includes debugging tools and is signed with the debug key. The release + * build type applies Proguard settings and is not signed by default. + */ buildTypes { + + /** + * By default, Android Studio configures the release build type to enable code + * shrinking, using minifyEnabled, and specifies the default Proguard rules file. + */ debug { applicationIdSuffix ".debug" versionNameSuffix "-debug" minifyEnabled false } + + release { + minifyEnabled true // Enables code shrinking for the release build type. + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } } -} -repositories { - repositories { - google() - jcenter() - mavenCentral() - maven { url 'https://www.jitpack.io' } + // The kotlinx-coroutines-core artifact contains a resource file that is not required for the coroutines to operate normally and is only used by the debugger. To exclude it at no loss of functionality, add the following snippet to the android block in your Gradle file for the application subproject: + // https://github.com/Kotlin/kotlinx.coroutines + packagingOptions { + resources.excludes += "DebugProbesKt.bin" } } dependencies { implementation project(":lib") + // Instead of adding ":lib" you could add the url below: + //implementation 'com.github.WalletConnect:kotlin-walletconnect-lib:0.9.6' - implementation "org.java-websocket:Java-WebSocket:1.4.0" - - implementation "com.github.komputing:khex:1.0.0-RC6" + implementation "org.java-websocket:Java-WebSocket:1.5.2" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}" + implementation "com.github.komputing:khex:$versions.k" implementation "androidx.appcompat:appcompat:$versions.androidx_app_compat" - implementation "androidx.multidex:multidex:$versions.multidex" - implementation 'com.squareup.moshi:moshi:1.8.0' + implementation 'com.squareup.moshi:moshi:1.12.0' implementation "com.squareup.okhttp3:okhttp:$versions.okhttp" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0' } diff --git a/sample/app/src/main/AndroidManifest.xml b/sample/app/src/main/AndroidManifest.xml index a6f07c8..0d3bf1f 100644 --- a/sample/app/src/main/AndroidManifest.xml +++ b/sample/app/src/main/AndroidManifest.xml @@ -10,7 +10,8 @@ android:supportsRtl="true" android:name=".ExampleApplication" android:networkSecurityConfig="@xml/network_config"> - + diff --git a/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt b/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt index 2e29037..3e4cef2 100644 --- a/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt +++ b/sample/app/src/main/java/io/walletconnect/example/ExampleApplication.kt @@ -1,6 +1,6 @@ package io.walletconnect.example -import androidx.multidex.MultiDexApplication +import android.app.Application import com.squareup.moshi.Moshi import io.walletconnect.example.server.BridgeServer import okhttp3.OkHttpClient @@ -11,7 +11,7 @@ import org.walletconnect.nullOnThrow import java.io.File import java.util.* -class ExampleApplication : MultiDexApplication() { +class ExampleApplication : Application() { override fun onCreate() { super.onCreate() initMoshi() diff --git a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt index c160cf1..0487abf 100644 --- a/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt +++ b/sample/app/src/main/java/io/walletconnect/example/MainActivity.kt @@ -2,10 +2,11 @@ package io.walletconnect.example import android.app.Activity import android.os.Bundle -import kotlinx.android.synthetic.main.screen_main.* import android.content.Intent import android.net.Uri import android.view.View +import android.widget.Button +import android.widget.TextView import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -49,19 +50,19 @@ class MainActivity : Activity(), Session.Callback { private fun sessionApproved() { uiScope.launch { - screen_main_status.text = "Connected: ${ExampleApplication.session.approvedAccounts()}" - screen_main_connect_button.visibility = View.GONE - screen_main_disconnect_button.visibility = View.VISIBLE - screen_main_tx_button.visibility = View.VISIBLE + findViewById(R.id.screen_main_status).text = "Connected: ${ExampleApplication.session.approvedAccounts()}" + findViewById