https://kotlinlang.org logo
#android
Title
# android
a

Aleksey Kornienko

12/17/2018, 12:33 PM
Hello! When I try to implement kotlin-written aar library in java only project I get an error “Error: Program type already present: com.mylibrary.internal.event.EventKeys$Alive$Companion” So, this means that I can’t use kotlin jars/aars in non-kotlin projects?
n

nestserau

12/17/2018, 12:36 PM
It is possible.
I guess the issue is with how you declare dependencies.
a

Aleksey Kornienko

12/17/2018, 12:40 PM
thanks, I try to find an error in this way 🙂
just I don’t use nothing special, only add a local repo
Copy code
allprojects {
    repositories {
        flatDir {
            dirs 'libs'
        }
    }
}
and app my aar as dependency
Copy code
dependencies {
    implementation(name:'mylibrary-release', ext:'aar')
}
n

nestserau

12/17/2018, 12:44 PM
Can you show you build.gradle in its entirety?
I personally use Archiva (a Maven repo), works like a charm. You can run it locally too, it’s a couple of lines in the Terminal to set everything up. Then you’re not bound to the error-prone flat dir stuff.
a

Aleksey Kornienko

12/17/2018, 12:46 PM
yes, of course. It’s a new empty java project just with my kotlin library MyApplication.gradle
Copy code
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
build.gradle
Copy code
apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.unownedself.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), '<http://proguard-rules.pro|proguard-rules.pro>'
        }
    }
}

dependencies {
    implementation(name:'mylibrary-release', ext:'aar')

    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-vector-drawable:28.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
thanks, I will try Archiva soon
or I can use bintray
n

nestserau

12/17/2018, 12:51 PM
I cannot spot an error in your Gradle script right off the bat.
a

Aleksey Kornienko

12/17/2018, 1:20 PM
I try to create jar file, and put it in project 🙂 It’s crash with classnotfound
Copy code
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/jvm/internal/Intrinsics;
So, nevetheless, I think I need a kotlin-stdlib dependency 🙂
n

nestserau

12/17/2018, 2:09 PM
Okay, let us know the solution once you’re there.
8 Views