Android Studio 3.1 Canary 4 Build #AI-171.4444016, built on November 10, 2017 JRE: 1.8.0_152-release-1012-b01 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Linux 4.13.16-302.fc27.x86_64
Hello,
I have the following project structure. However, as I have some kotlin files I want to create a new folder called kotlin
under test
and create a new package and store all my kotlin files there.
Currently I have one called Java, but I want to create the kotlin, but can't seem to be able to find out how to do it.
I would like to do the same for androidTest
as well, so I can separate all my java and kotlin files.
2 Answers
Answers 1
Would like to give credit to rafid059 who posted the link to the proandoriddev.com article which solved my problem.
In my build.gradle file I have the following which worked for both the test and androidTest folders. However, I needed to create the folders first.
sourceSets { main { java.srcDirs = ['src/main/java', 'src/main/kotlin'] } test.java.srcDirs += 'src/test/kotlin' androidTest.java.srcDirs += 'src/androidTest/kotlin' }
If anyone need any help on this you can reply back to this solution.
Answers 2
Basically, the idea is to showcase how we can test our android applications using Kotlin, so as a first step we need to setup and prepare our environment by adding Kotlin dependencies in our build.gradle file:
buildscript { repositories { mavenCentral() jcenter() } dependencies { classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.0.5-2' } } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' ... dependencies { ... compile "org.jetbrains.kotlin:kotlin-stdlib:1.0.6" ... testCompile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.6' testCompile 'org.jetbrains.kotlin:kotlin-test-junit:1.0.6' testCompile "com.nhaarman:mockito-kotlin:1.1.0" testCompile 'org.amshove.kluent:kluent:1.14' }
Now we need to set the dedicated directories for tests written in Kotlin, this is done in our sourceSets
section:
android { ... sourceSets { test.java.srcDirs += 'src/test/kotlin' androidTest.java.srcDirs += 'src/androidTest/kotlin' } ... }
- This tutorials walks us through the process of using Java and Kotlin in a single IDEA project.
0 comments:
Post a Comment