good day
I use Kotlin in Android Studio. I can not compile the project with the moshi library connected. https://github.com/square/moshi

Tell me, what am I doing wrong ?? In the console I see:

 :app:packageInstantRunResourcesDebug UP-TO-DATE :app:checkManifestChangesDebug :app:transformClassesWithAndroidGradleClassShrinkerForDebug com/squareup/moshi/JsonReader references unknown class: javax/annotation/Nullable com/squareup/moshi/CollectionJsonAdapter$1 references unknown class: javax/annotation/Nullable com/squareup/moshi/JsonAdapter$5 references unknown class: javax/annotation/Nullable com/squareup/moshi/package-info references unknown class: javax/annotation/ParametersAreNonnullByDefault com/squareup/moshi/ArrayJsonAdapter$1 references unknown class: javax/annotation/Nullable com/squareup/moshi/AdapterMethodsFactory$1 references unknown class: javax/annotation/Nullable okio/package-info references unknown class: javax/annotation/ParametersAreNonnullByDefault com/squareup/moshi/Types references unknown class: javax/annotation/Nullable com/squareup/moshi/JsonAdapter references unknown class: javax/annotation/Nullable okio/ByteString references unknown class: javax/annotation/Nullable 

top-level build.gradle

 buildscript { ext.kotlin_version = '1.2.10' repositories { jcenter() google() } dependencies { classpath 'com.android.tools.build:gradle:3.0.1' 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 { repositories { jcenter() google() } } task clean(type: Delete) { delete rootProject.buildDir } 

app \ build.gradle

 apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { compileSdkVersion 26 buildToolsVersion "26.0.2" defaultConfig { applicationId "com.lfom.modbuster" minSdkVersion 21 targetSdkVersion 24 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable true minifyEnabled true } } productFlavors { } } dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) testImplementation 'junit:junit:4.12' implementation 'com.android.support:appcompat-v7:26.+' implementation 'com.android.support:design:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect" implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.google.android.gms:play-services-vision:11.0.4' implementation 'com.squareup.moshi:moshi:1.5.0' implementation 'com.squareup.moshi:moshi-kotlin:1.5.0' implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0' implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1' } repositories { mavenCentral() maven { url "https://repo.eclipse.org/content/repositories/paho-snapshots/" } } 

https://github.com/LevWi/modbuster-blt/blob/Signals/app/build.gradle


proguard-rules.pro

 -dontwarn okio.** -dontwarn javax.annotation.** -keepclasseswithmembers class * { @com.squareup.moshi.* <methods>; } -keep @com.squareup.moshi.JsonQualifier interface * -keepclassmembers class kotlin.Metadata { public <methods>; } 

    1 answer 1

    You got messed up here:

      release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { debuggable true minifyEnabled true } 

    ProGuard enabled for debug , hence the build issue.
    The moshi library and Kotlin have nothing to do with it.

    • And when will I try to make a release, will it all fall down again? - levWi
    • Something tells me that it is too early to talk about the release :) In order not to fall down during the release, there is proguard-rules.pro . - Eugene Krivenja
    • :) It's early. And yes, you are right - disabled ProGuard - it worked. And if I plan to leave the application as an open source form, is there any reason to include ProGuard? - levWi
    • ProGuard is recommended to enable to reduce the size of the APK on the output. - Eugene Krivenja