├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle.kts └── src │ └── main │ ├── AndroidManifest.xml │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ └── ic_launcher_background.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ └── styles.xml ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts └── src │ └── main │ └── kotlin │ ├── JdkVersion.kt │ └── const.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── lib-compose ├── build.gradle.kts └── src │ └── androidMain │ ├── AndroidManifest.xml │ └── kotlin │ └── lib │ └── compose │ ├── Mpp.kt │ └── UseComposeActivity.kt └── settings.gradle.kts /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | *.aab 5 | 6 | # Files for the ART/Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | out/ 16 | # Uncomment the following line in case you need and you don't have the release build type files in your app 17 | # release/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Android Studio Navigation editor temp files 33 | .navigation/ 34 | 35 | # Android Studio captures folder 36 | captures/ 37 | 38 | # IntelliJ 39 | *.iml 40 | .idea/ 41 | .idea/workspace.xml 42 | .idea/tasks.xml 43 | .idea/gradle.xml 44 | .idea/assetWizardSettings.xml 45 | .idea/dictionaries 46 | .idea/libraries 47 | # Android Studio 3 in .gitignore file. 48 | .idea/caches 49 | .idea/modules.xml 50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 51 | .idea/navEditor.xml 52 | 53 | # Keystore files 54 | # Uncomment the following lines if you do not want to check your keystore files in. 55 | #*.jks 56 | #*.keystore 57 | 58 | # External native build folder generated in Android Studio 2.2 and later 59 | .externalNativeBuild 60 | .cxx/ 61 | 62 | # Google Services (e.g. APIs or Firebase) 63 | # google-services.json 64 | 65 | # Freeline 66 | freeline.py 67 | freeline/ 68 | freeline_project_description.json 69 | 70 | # fastlane 71 | fastlane/report.xml 72 | fastlane/Preview.html 73 | fastlane/screenshots 74 | fastlane/test_output 75 | fastlane/readme.md 76 | 77 | # Version control 78 | vcs.xml 79 | 80 | # lint 81 | lint/intermediates/ 82 | lint/generated/ 83 | lint/outputs/ 84 | lint/tmp/ 85 | # lint/reports/ 86 | 87 | apikey.properties -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### On latest version's of JetPack Compose this problem solved. For code sample you may look at https://github.com/JetBrains/compose-jb 2 | 3 | # build JetPack Compose + Kotlin MPP on Kotlin 1.4.* 4 | ## Use workaround 5 | Look at lib-compose/build.gradle.kts: 6 | ```Kotlin 7 | plugins { 8 | id("com.android.library") 9 | kotlin("multiplatform") 10 | } 11 | //... 12 | //todo Workaround here: 13 | configurations { 14 | create("composeCompiler") { 15 | isCanBeConsumed = false 16 | } 17 | } 18 | dependencies { 19 | "composeCompiler"("androidx.compose:compose-compiler:$ANDROID_COMPOSE_VERSION") 20 | } 21 | android { 22 | afterEvaluate { 23 | val composeCompilerJar = 24 | configurations["composeCompiler"] 25 | .resolve() 26 | .singleOrNull() 27 | ?: error("Please add \"androidx.compose:compose-compiler\" (and only that) as a \"composeCompiler\" dependency") 28 | tasks.withType { 29 | kotlinOptions.freeCompilerArgs += listOf("-Xuse-ir", "-Xplugin=$composeCompilerJar") 30 | } 31 | } 32 | } 33 | ``` 34 | ## Build this sample .apk 35 | ```bash 36 | ./gradlew assembleDebug 37 | temporarily MPP works better on version Android Studio 4.2 Canary-6 38 | ``` 39 | Install apk from dir: ```app/build/outputs/apk/debug/app-debug.apk``` 40 | 41 | ## Additional info for JetBrains Kotlin Team and Google Android Team: 42 | Sorry for Russian language, later will translate to EN. 43 | Есть известный баг @Composable функции не работают с Kotlin Multiplatform ```id("org.jetbrains.kotlin.multiplatform")``` 44 | Баг заведён в JetBrains YouTrack: https://youtrack.jetbrains.com/issue/KT-38694 45 | И в Google IssueTracker: https://issuetracker.google.com/issues/155536223 46 | 47 | Ключевой момент что для починки нужно добавить аргумент компилятора "-Xplugin=$composeCompilerJar" 48 | В случае с модулями id("kotlin-android") аргумент -Xplugin уже добавляется 49 | В случае с kotlin("multiplatform") я добавил этот аргумент руками 50 | 51 | Как починить багу? 52 | Эта логика описана в репозитории AOSP: https://webcache.googleusercontent.com/search?q=cache:Wl-GOo5My08J:https://android.googlesource.com/platform/frameworks/support/%2B/androidx-master-dev/buildSrc/src/main/kotlin/androidx/build/AndroidXUiPlugin.kt+&cd=1&hl=en&ct=clnk&gl=ru#100 53 | Предположу что где-то там можно решить эту проблему удобным способом. 54 | Обратите внимание что добавление -Xplugin происходит до конфигурации project.configureForMultiplatform() 55 | Возможно стоит изменить порядок кода. 56 | Один из авторов этого кода - Nikolay Igotti. Возможно он сможет помочь с решением этой задачи. 57 | 58 | 59 | ### P.S. 60 | Thanks to Google and JetBrains for amazing JetPack Compose and Kotlin Multiplatform. 61 | Together we can make these tools even better. 62 | 63 | Thanks to https://github.com/r4zzz4k for help 64 | 65 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("kotlin-android") 4 | } 5 | 6 | android { 7 | compileSdkVersion(ANDROID_COMPILE_SDK) 8 | buildToolsVersion(ANDROID_BUILD_TOOLS_VERSION) 9 | 10 | defaultConfig { 11 | applicationId("com.sample.compose") 12 | minSdkVersion(ANDROID_MIN_SDK) 13 | targetSdkVersion(ANDROID_TARGET_SDK) 14 | versionCode(1) 15 | versionName("1.0") 16 | } 17 | 18 | buildTypes { 19 | getByName("release") { 20 | isMinifyEnabled = false 21 | } 22 | } 23 | compileOptions { 24 | sourceCompatibility = JavaVersion.VERSION_1_8 25 | targetCompatibility = JavaVersion.VERSION_1_8 26 | } 27 | } 28 | 29 | dependencies { 30 | implementation(project(":lib-compose")) 31 | implementation("androidx.appcompat:appcompat:$ANDROID_APP_COMPAT") 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avdim/compose_mpp_workaround/f6627383a32c495d4aa86a090944c589ebcebd2a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #6200EE 4 | #3700B3 5 | #03DAC5 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 15 | 16 |