https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
s

Sam

12/18/2019, 5:05 PM
Is there a recommended way to create androidMain and androidTest modules?
k

Kris Wong

12/18/2019, 5:09 PM
there's a lot more to it than that. you also need to apply the android gradle plugin, add your android block, associate it with the kotlin source sets, and add an AndroidManifest.xml
s

Sam

12/18/2019, 5:18 PM
Yes i did that
It works as expected, i'm able to generate aar
but IDE doesn't highlight any errors for missing definitions
k

Kris Wong

12/18/2019, 5:20 PM
can you paste your sourceSets block?
s

Sam

12/18/2019, 5:21 PM
Copy code
android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName '1.0'
        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }
    buildTypes {
        debug {
        }
        release {
            minifyEnabled false
        }
    }
    sourceSets {
        main {
            manifest.srcFile 'src/androidMain/AndroidManifest.xml'// See notes #4
            java.srcDirs = ['src/androidMain/kotlin']
            res.srcDirs = ['src/androidMain/resources']
        }
        androidTest {
            java.srcDirs = ['src/androidTest/kotlin']
            res.srcDirs = ['src/androidTest/resources']
        }
    }

    dependencies {
        androidTestImplementation 'com.android.support.test:runner:1.0.2'
    }
}
If it helps, here it the link for the entire file https://github.com/Ethan1983/MultiplatformLib/blob/master/build.gradle
k

Kris Wong

12/18/2019, 5:24 PM
this all looks correct
did you rerun your gradle import?
s

Sam

12/18/2019, 5:25 PM
yeah
i was looking for the official way to create androidMain and androidTest
right now if i create, it is just a directory
k

Kris Wong

12/18/2019, 5:25 PM
if so, perhaps restart IDEA. it can get confused when you "migrate" a target like this
s

Sam

12/18/2019, 5:26 PM
I suspect that IDE doesn't highlight errors because its not seen as a module
Okay, let me try restarting too
k

Kris Wong

12/18/2019, 5:26 PM
that has actually fixed issues for me in the past when doing this
s

Sam

12/18/2019, 5:28 PM
no luck, that didn't help, it doesn't mark it as a module
k

Kris Wong

12/18/2019, 5:28 PM
huh
s

Sam

12/18/2019, 5:28 PM
module vs directory
Does your setup show it as a module? Are you using Android Studio or IntelliJ?
k

Kris Wong

12/18/2019, 5:29 PM
mine looks the same, but it works - IDEA
s

Sam

12/18/2019, 5:29 PM
same as in androidMain shows as a directory?
k

Kris Wong

12/18/2019, 5:30 PM
yes
and it doesn't show as a module on the module settings dialog
s

Sam

12/18/2019, 5:32 PM
Okay, do you remember how you created those?
@Kris Wong What version of JDK are you using?
k

Kris Wong

12/18/2019, 6:47 PM
8
s

Sam

12/18/2019, 8:50 PM
Thanks
🍻 1
2 Views