Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle 7.0.3 + Kotlin 1.5.31 + RxJava 2.2.21 + AndroidX migration #2

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'

kotlin {
experimental {
coroutines 'enable'
}
}

android {
compileSdkVersion 27
compileSdk 31

defaultConfig {
applicationId "andreabresolin.kotlincoroutinestests"
minSdkVersion 24
targetSdkVersion 27
minSdk 24
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildFeatures {
viewBinding true
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}

ext {
support_library_version = '27.1.0'
constraint_layout_version = '1.0.2'
kotlin_coroutines_version = '0.22.5'
rxjava_version = '2.1.11'
rxandroid_version = '2.0.2'
kotlin_coroutines_version = '1.5.1'
rxjava_version = '2.2.21'
rxandroid_version = '2.1.1'
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation "com.android.support:appcompat-v7:$support_library_version"
implementation "com.android.support.constraint:constraint-layout:$constraint_layout_version"
testImplementation "junit:junit:4.12"
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

// Kotlin coroutines
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"

// RxJava
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@

package andreabresolin.kotlincoroutinestests

import andreabresolin.kotlincoroutinestests.databinding.ActivityMainBinding
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.*
import java.util.concurrent.atomic.AtomicInteger

class MainActivity : AppCompatActivity() {
Expand All @@ -40,27 +37,32 @@ class MainActivity : AppCompatActivity() {
private var testStartTime: Long = 0
private val testArray = IntArray(TEST_ITERATIONS_COUNT)

private lateinit var viewBinding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

viewBinding = ActivityMainBinding.inflate(layoutInflater)
setContentView(viewBinding.root)
setupListeners()
}

private fun setupListeners() {
testCoroutinesButton.setOnClickListener { onTestCoroutinesButtonClick() }
testAsyncsInCoroutineButton.setOnClickListener { onTestAsyncsInCoroutineButtonClick() }
testRxJavaButton.setOnClickListener { onTestRxJavaButtonClick() }
with(viewBinding) {
testCoroutinesButton.setOnClickListener { onTestCoroutinesButtonClick() }
testAsyncsInCoroutineButton.setOnClickListener { onTestAsyncsInCoroutineButtonClick() }
testRxJavaButton.setOnClickListener { onTestRxJavaButtonClick() }
}
}

private fun onTestCoroutinesButtonClick() {
val testName = "Coroutines test"

startTest(testName)

val scope = CoroutineScope(Job() + Dispatchers.Default)
for (i in 1..TEST_ITERATIONS_COUNT) {
launch(UI) {
async(CommonPool) { stubAsyncFunc() }.await()
scope.launch {
val result = async { stubAsyncFunc() }.await()
checkTestEnd(testName)
}
}
Expand All @@ -70,14 +72,14 @@ class MainActivity : AppCompatActivity() {
val testName = "Asyncs in coroutine test"

startTest(testName)

launch(UI) {
val scope = CoroutineScope(Job() + Dispatchers.Default)
scope.launch {
testArray
.map { async(CommonPool) { stubAsyncFunc() } }
.map {
it.await()
checkTestEnd(testName)
}
.map { async { stubAsyncFunc() } }
.map {
it.await()
checkTestEnd(testName)
}
}
}

Expand All @@ -90,10 +92,10 @@ class MainActivity : AppCompatActivity() {
val observeScheduler = AndroidSchedulers.mainThread()

for (i in 1..TEST_ITERATIONS_COUNT) {
Observable.fromCallable { stubAsyncFunc() }
.subscribeOn(subscribeScheduler)
.observeOn(observeScheduler)
.subscribe { checkTestEnd(testName) }
val disposable = Observable.fromCallable { stubAsyncFunc() }
.subscribeOn(subscribeScheduler)
.observeOn(observeScheduler)
.subscribe { checkTestEnd(testName) }
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
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"
Expand Down Expand Up @@ -43,4 +43,4 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_weight="1"/>

</android.support.constraint.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.31'
ext.kotlin_version = '1.5.31'
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath "com.android.tools.build:gradle:7.0.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -18,7 +18,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
14 changes: 9 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +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=-Xmx1536m

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
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Mar 20 19:18:56 GMT 2018
#Wed Nov 24 14:24:16 ICT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
zipStoreBase=GRADLE_USER_HOME