JetBrains / kotlin-native

Kotlin/Native infrastructure
Apache License 2.0
7.02k stars 566 forks source link

K/N android/ios kapt at intellij generated project #2324

Closed MitsuraIvan closed 5 years ago

MitsuraIvan commented 6 years ago

Hi, at intellij generated project there is 1 build.gradle file for all platforms and because of kotlin-multiplatform plugin we cant use plugin kotlin-android and because of that kotlin-kapt plugin dont do anything. with kotlin-android plugin we got error Cannot add extension with name 'kotlin', as there is an extension already registered with that name. without kotlin-android plugin we got error Could not find method kapt() for arguments [android.arch.persistence.room:compiler:1.1.1] on object of type org.jetbrains.kotlin.gradle.plugin.mpp.DefaultKotlinDependencyHandler. it makes dagger/room and other stuff on android impossible to use which kinda kills the point of development. Any suggestions? is this a bug or bad gradle file?

project level build.gradle

buildscript { ext.kotlin_version = '1.3.0' repositories { google() jcenter() maven { url 'https://maven.google.com' } maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:3.2.1' } } repositories { google() jcenter() }

app build.gradle

buildscript { repositories { google() jcenter() maven { url 'https://maven.google.com' } maven { url "https://plugins.gradle.org/m2/" } repositories { maven { url 'https://maven.fabric.io/public' } } }

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.0"
    classpath 'io.fabric.tools:gradle:1.+'
    classpath 'com.android.tools.build:gradle:3.2.1'
}

} plugins { id 'kotlin-multiplatform' version('1.3.0') }

apply plugin: 'com.android.application' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt'

repositories { maven { url 'https://maven.fabric.io/public' } } android { compileSdkVersion 28 buildToolsVersion '28.0.3' defaultConfig { applicationId "com.pam.pam" minSdkVersion 17 targetSdkVersion 28 versionCode 1 versionName "1" signingConfig signingConfigs.config multiDexEnabled true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } testOptions { unitTests.returnDefaultValues = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } compileOptions { targetCompatibility 1.8 sourceCompatibility 1.8 } }

repositories { google() jcenter() mavenCentral() maven { url "https://maven.google.com" } maven { url 'https://jitpack.io' } maven { url 'https://maven.fabric.io/public' } }

dependencies {

annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
kapt 'android.arch.persistence.room:compiler:1.1.1'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.19.0'
testImplementation 'org.hamcrest:hamcrest-junit:2.0.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

kotlin { targets { fromPreset(presets.android, 'android') // This preset is for iPhone emulator // Switch here to presets.iosArm64 (or iosArm32) to build library for iPhone device fromPreset(presets.iosX64, 'ios') { compilations.main.outputKinds('FRAMEWORK') } } sourceSets { commonMain { dependencies { implementation 'org.jetbrains.kotlin:kotlin-stdlib-common' } } androidMain { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" } } iosMain {} } }

// This task attaches native framework built from ios module to Xcode project // (see iosApp directory). Don't run this task directly, // Xcode runs this task itself during its build process. // Before opening the project from iosApp directory in Xcode, // make sure all Gradle infrastructure exists (gradle.wrapper, gradlew). task copyFramework { def buildType = project.findProperty("kotlin.build.type") ?: "DEBUG" def target = project.findProperty("kotlin.target") ?: "ios" dependsOn "link${buildType.toLowerCase().capitalize()}Framework${target.capitalize()}"

doLast {
    def srcFile = kotlin.targets."$target".compilations.main.getBinary("FRAMEWORK", buildType)
    def targetDir = getProperty("configuration.build.dir")
    copy {
        from srcFile.parent
        into targetDir
        include 'app.framework/**'
        include 'app.framework.dSYM'
    }
}

}

fardavide commented 5 years ago

@MitsuraIvan any solution found? I'm having the same issue :(

MitsuraIvan commented 5 years ago

@4face-studi0 no from my side, sadly. You can try kotlin/native channel at slack, this thread got ignored, seems like it will not be possible with new project structure that using combined gradle for all platforms

h0tk3y commented 5 years ago

@MitsuraIvan @4face-studi0 Kapt should work in multiplatform projects where an Android target is declared. First, note that kapt dependencies should be added after the Android target is declared in the kotlin { ... } block. You can move those dependency declarations below the kotlin { ... } block.

You don't need to apply the kotlin-android plugin in a project where kotlin-mulatiplatform is applied, the Android target that is declared in the kotlin { ... } scope should be enough.

If you face any further issues once you fix the kapt dependency declaration, feel free to comment here so I can look into it.