我最近决定将我们公司的android应用程序移植到kotlin中。它运作良好,但是,当我使用任何kotlin扩展时,我得到一个奇怪的行为。我注意到任何使用扩展的类(无论是anko还是自我声明的扩展)只是第一次构建,并且在每个后续构建中它不存在于其他类中。不使用扩展的Kotlin类始终正确构建。 每当我运行程序时,这会导致NoClassDefFoundError(在后续构建中,第一个运行没有问题)。 我已经尝试了一切,我开始有点绝望了...... 这是整个项目的build.gradle:
buildscript {
ext.kotlin_version = '1.0.1-2'
ext.support_version = '23.3.0'
ext.anko_version = '0.8.3'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
classpath 'org.codehaus.groovy:gradle-groovy-android-plugin:0.3.7'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
}
这是我试图在
中使用kotlin的模块的build.gradlebuildscript {
repositories {
jcenter()
mavenCentral()
maven {
url 'http://repo.spring.io/milestone'
}
maven {
url "http://repo.bodar.com/"
}
}
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
}
}
apply plugin: 'com.android.application'
apply plugin: 'com.jakewharton.hugo'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'groovyx.grooid.groovy-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
productFlavors {
dev {
minSdkVersion 21
}
prod {
minSdkVersion 19
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
lintOptions {
disable 'InvalidPackage'
}
packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude 'META-INF/services/org.codehaus.groovy.transform.ASTTransformation'
exclude 'LICENSE.txt'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
applicationId "com.example.name"
minSdkVersion 16
targetSdkVersion 23
multiDexEnabled true
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
resValue "string", "tray__authority", "${applicationId}.tray"
}
dexOptions {
javaMaxHeapSize "4g"
}
retrolambda {
jvmArgs '-noverify'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
testCoverageEnabled = true
}
}
}
kapt {
generateStubs = true
}
repositories {
jcenter()
mavenCentral()
maven {
url "http://repo.bodar.com/"
}
maven {
url "https://clojars.org/repo/"
}
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "org.jetbrains.anko:anko-common:$anko_version"
androidTestCompile 'org.codehaus.groovy:groovy:2.4.2:grooid'
androidTestCompile 'com.andrewreitz:spock-android:1.2.2'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
exclude group: 'junit'
}
// Optional, needed for mocking
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/guava-18.0.jar')
provided 'org.projectlombok:lombok:1.16.4'
compile files('libs/icepick-2.3.6.jar')
compile files('libs/icepick-processor-2.3.6.jar')
compile files('libs/FlurryAnalytics-5.5.0.jar')
compile project(':fliclib')
compile "com.android.support:support-annotations:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"
compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:design:$support_version"
compile "com.android.support:support-v4:$support_version"
compile 'com.android.support:multidex:1.0.1'
compile 'com.androidplot:androidplot-core:0.9.6'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0@aar'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0@aar'
compile 'com.nhaarman.listviewanimations:lib-core-slh:3.1.0@aar'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'org.springframework.android:spring-android-rest-template:2.0.0.M1'
compile 'com.google.code.gson:gson:2.4'
compile 'com.joooonho:selectableroundedimageview:1.0.1'
compile 'com.googlecode.totallylazy:totallylazy:1.73'
compile 'net.grandcentrix.tray:tray:0.9.2'
compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar'
compile 'jp.wasabeef:recyclerview-animators:2.1.0'
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
compile 'com.github.castorflex.verticalviewpager:library:19.0.1'
compile 'com.github.traex.expandablelayout:library:1.3'
}
apply plugin: 'com.google.gms.google-services'
以下是该模块的清单(或者更确切地说,它是代码为propietary的标题)
<manifest package="com.package.name"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="23"
android:versionName="0.9.1">
答案 0 :(得分:0)
好的,所以我设法弄清楚了,也许它会帮助别人。显然问题是java注释(@DebugLog, @NonNull, @Icicle
等),如果它们存在于任何kotlin类中,它将半随机编译。在移除它之后它可以完美地工作。