following functions can be called with the arguments supplied. navigateUp - navigation-drawer

I am developing android using android navigation components but I am getting following warning None of the following functions can be called with the arguments supplied.
navigateUp(NavController, DrawerLayout?) defined in androidx.navigation.ui.NavigationUI
navigateUp(NavController, AppBarConfiguration) defined in androidx.navigation.ui.Navigation
below my MainActivity.kt
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.Navigation
import androidx.navigation.ui.NavigationUI
import androidx.navigation.ui.setupWithNavController
import com.example.forecastmvvm.R
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
private lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
navController = Navigation.findNavController(this,R.id.nav_host_fragment)
bottom_nav.setupWithNavController(navController)
NavigationUI.setupActionBarWithNavController(this, navController)
}
override fun onSupportNavigateUp(): Boolean {
return NavigationUI.navigateUp( null, navController)
}
}
below app.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: "kotlin-kapt"
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.forecastmvvm"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.0.0"
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation "android.arch.navigation:navigation-fragment:1.0.0"
implementation "android.arch.navigation:navigation-ui:1.0.0"
implementation "android.arch.navigation:navigation-fragment-ktx:1.0.0"
implementation "android.arch.navigation:navigation-ui-ktx:1.0.0"
implementation "androidx.core:core-ktx:1.0.0"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
// Room
implementation "androidx.room:room-runtime:2.1.0"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0'
kapt "androidx.room:room-compiler:2.1.0"
// Gson
implementation "com.google.code.gson:gson:2.8.5"
// Kotlin Android Coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0"
// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.0.0"
implementation "com.squareup.retrofit2:converter-gson:2.0.0"
implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'
// ViewModel
implementation "androidx.lifecycle:lifecycle-extensions:2.0.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0"
kapt "androidx.lifecycle:lifecycle-compiler:2.0.0"
// Kodein
implementation "org.kodein.di:kodein-di-generic-jvm:6.3.3"
implementation "org.kodein.di:kodein-di-framework-android-x:6.3.3"
// Better dateTime-time support even on older Android versions
implementation "com.jakewharton.threetenabp:threetenabp:1.1.0"
// Glide
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'
// Groupie RecyclerView
implementation 'com.xwray:groupie:2.1.0'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.1.0'
// Preference
implementation "androidx.preference:preference:1.0.0"
// WeatherLocation
implementation "com.google.android.gms:play-services-location:16.0.0"
// New Material Design
implementation "com.google.android.material:material:1.0.0"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
}
below gradle
buildscript {
ext.kotlin_version = '1.3.41'
ext.room_version = '2.1.0'
ext.navigation_version = '1.0.0'
ext.kodein_version = '6.3.3'
ext.lifecycle_version = '2.0.0'
ext.retrofit_version = '2.0.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

As far as i know, the first parameter should be your NavigationController (non nullable), and your second parameter is DrawerLayout (nullable)
you should flip your parameter
override fun onSupportNavigateUp(): Boolean {
return NavigationUI.navigateUp( navController, null )
}
Parameter Arguments Screenshot

Related

Kotlin MPP - build problems with Gradle on IntelliJ

I'm trying to build a multi module Gradle project with some Koltin MPP modules.
I have a very strange problem while trying to build a Kotlin MPP module. All of the specified dependencies are resolved, they can be seen from the Gradle configuration, but when I try to use some of the classes in the mobile targets (Android and iOS), I can't do it. The classes can't be resolved at all.
This is my gradle build file for the module in question:
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.multiplatform'
id 'org.jetbrains.kotlin.plugin.serialization'
}
group 'bg.dalexiev'
version '0.0.1'
def ktor_version = '1.3.1'
def serialization_version = '0.14.0'
def coroutines_version = '1.3.3'
def timber_version = '4.7.1'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
versionName '0.0.1'
versionCode 1
}
sourceSets {
main {
manifest.srcFile 'src/androidMain/AndroidManifest.xml'
java.srcDirs = ['src/androidMain/kotlin']
res.srcDirs = ['src/androidMain/res']
}
test {
java.srcDirs = ['src/androidTest/kotlin']
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
google()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation "com.jakewharton.timber:timber:$timber_version"
testImplementation("junit:junit:4.12")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
kotlin {
android("android")
def sdkName = System.getenv('SDK_NAME')
def iosTarget = sdkName?.startsWith('iphoneos') ? presets.iosArm64 : presets.iosX64
targetFromPreset(iosTarget, "ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "io.ktor:ktor-client-logging:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
iosMain {
dependencies {
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-json-native:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
implementation "io.ktor:ktor-client-logging-native:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
}
}
iosTest {
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
configurations {
compileClasspath
}
I was able to build a standalone gradle project with the same configuration without any problems. Any help and advice would be appreciated.
Your android dependencies are in the wrong block. Refactor your build.gradle to
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.multiplatform'
id 'org.jetbrains.kotlin.plugin.serialization'
}
group 'bg.dalexiev'
version '0.0.1'
def ktor_version = '1.3.1'
def serialization_version = '0.14.0'
def coroutines_version = '1.3.3'
def timber_version = '4.7.1'
android {
compileSdkVersion 29
defaultConfig {
minSdkVersion 21
versionName '0.0.1'
versionCode 1
}
sourceSets {
main {
manifest.srcFile 'src/androidMain/AndroidManifest.xml'
java.srcDirs = ['src/androidMain/kotlin']
res.srcDirs = ['src/androidMain/res']
}
test {
java.srcDirs = ['src/androidTest/kotlin']
}
}
buildTypes {
release {
minifyEnabled true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
repositories {
google()
}
kotlin {
android("android")
def sdkName = System.getenv('SDK_NAME')
def iosTarget = sdkName?.startsWith('iphoneos') ? presets.iosArm64 : presets.iosX64
targetFromPreset(iosTarget, "ios") {
binaries {
framework()
}
}
sourceSets {
commonMain {
dependencies {
implementation kotlin('stdlib-common')
implementation "io.ktor:ktor-client-core:$ktor_version"
implementation "io.ktor:ktor-client-json:$ktor_version"
implementation "io.ktor:ktor-client-serialization:$ktor_version"
implementation "io.ktor:ktor-client-logging:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
}
}
commonTest {
dependencies {
implementation kotlin('test-common')
implementation kotlin('test-annotations-common')
}
}
androidMain.dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation "io.ktor:ktor-client-okhttp:$ktor_version"
implementation "io.ktor:ktor-client-json-jvm:$ktor_version"
implementation "io.ktor:ktor-client-serialization-jvm:$ktor_version"
implementation "io.ktor:ktor-client-logging-jvm:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation "com.jakewharton.timber:timber:$timber_version"
}
androidTest.dependencies {
implementation("junit:junit:4.12")
implementation("org.jetbrains.kotlin:kotlin-test")
implementation("org.jetbrains.kotlin:kotlin-test-junit")
}
iosMain {
dependencies {
implementation "io.ktor:ktor-client-ios:$ktor_version"
implementation "io.ktor:ktor-client-json-native:$ktor_version"
implementation "io.ktor:ktor-client-serialization-native:$ktor_version"
implementation "io.ktor:ktor-client-logging-native:$ktor_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
}
}
iosTest {
}
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
configurations {
compileClasspath
}

Gradle multiple project gradle build fail with lombok 1.8.10 but compile well

I'm developing a gradle-multiple-project java application, code works well with lombok in intellij (getter, setter method is visible), but when I run gradle build then fail, get the message:
~/EventStormingWorkShop/sources/coffeeshop/coffee-domain/src/main/java/solid/humank/port/adapter/OrderReceiverAdapter.java:41: error: cannot find symbol
String orderString= mapper.writeValueAsString(orderCreatedEvent.getDetail());
^
symbol: method getDetail()
location: variable orderCreatedEvent of type OrderCreatedEvent
Current environment:
Intellij : 2019.2.3
Gradle : 5.6.2
JDK : GraalVM 19.2.0 (compatible with JDK 1.8_0222)
lombok : 1.8.10
I had checked the lombok dependencies declaration in build.gradle.
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
at compile time everything wen well.
Here is the build.gradle from my rootProject
buildscript {
ext {
quarkusJunitVersion = '0.22.0'
restAssuredVersion = '3.3.0'
cucumberVersion = '4.7.1'
lombokVersion = '1.18.10'
quarkusVersion = '0.23.1'
awsJavaVersion = '1.11.631'
awsVersion = '2.5.29'
}
}
apply from: file("${rootDir}/gradle/project.gradle")
List testCompilePackage = ["io.quarkus:quarkus-junit5:${quarkusJunitVersion}", "io.rest-assured:rest-assured:${restAssuredVersion}"]
List testImplementPackage = ["io.cucumber:cucumber-java8:${cucumberVersion}", "io.cucumber:cucumber-junit:${cucumberVersion}"]
List implementationPackage = ["io.quarkus:quarkus-resteasy",
"com.amazonaws:aws-java-sdk-lambda",
"com.amazonaws:aws-java-sdk-dynamodb",
"com.amazonaws:aws-lambda-java-core",
"com.amazonaws:aws-lambda-java-events",
"com.amazonaws:aws-java-sdk-events"]
subprojects { dir ->
repositories {
mavenCentral()
}
dependencies {
// Lombok Support
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
testCompileOnly "org.projectlombok:lombok:${lombokVersion}"
testAnnotationProcessor "org.projectlombok:lombok:${lombokVersion}"
// quarkus test
testCompile testCompilePackage
// cucumber test
testImplementation testImplementPackage
// quarkus
compile group: 'io.quarkus', name: 'quarkus-gradle-plugin', version: "${quarkusVersion}", ext: 'pom'
implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}")
implementation platform("com.amazonaws:aws-java-sdk-bom:${awsJavaVersion}")
implementation platform("software.amazon.awssdk:bom:${awsVersion}")
implementation implementationPackage
}
if (dir.name.endsWith("-domain")) {
dependencies {
implementation project(":ddd-commons")
}
}
if (dir.name.endsWith("-application")) {
String modName = dir.name.substring(0, dir.name.lastIndexOf("-application"))
dependencies {
implementation project(":ddd-commons"), project(":${modName}-domain")
}
}
if (dir.name.endsWith("-web")) {
String modName = dir.name.substring(0, dir.name.lastIndexOf("-web"))
dependencies {
implementation project(":ddd-commons"), project(":${modName}-domain"), project(":${modName}-application")
}
}
}
The build.gradle will apply a project.gradle file
project.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'io.quarkus:quarkus-gradle-plugin:0.23.1'
}
}
defaultTasks 'clean', 'build'
apply plugin: 'idea'
subprojects {
apply plugin: 'java'
apply plugin: io.quarkus.gradle.QuarkusPlugin
group 'solid.humank.coffeeshop'
version '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
idea.module.inheritOutputDirs = true
dependencies{
compileOnly "org.projectlombok:lombok:1.18.10"
annotationProcessor "org.projectlombok:lombok:1.18.10"
testCompileOnly "org.projectlombok:lombok:1.18.10"
testAnnotationProcessor "org.projectlombok:lombok:1.18.10"
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
options.deprecation = true
options.compilerArgs += ['-Xlint:none', '-proc:none', '-nowarn']
}
repositories {
mavenCentral()
mavenLocal()
}
buildDir = "${rootDir}/build/${rootDir.relativePath(projectDir)}"
tasks.named('test') {
useJUnitPlatform()
failFast = true
testLogging.showStandardStreams = true
testLogging.exceptionFormat 'full'
}
tasks.named('jar') {
// put parent name in final jar name, to resolve collision of child projects with same name under different parents
if (parent.depth > 0) {
archiveBaseName = "${parent.name}-${archiveBaseName.get()}"
}
}
afterEvaluate {
def buildTime = new Date()
tasks.withType(Jar) {
String ClassPathString = ''
configurations.runtime.each { ClassPathString += " lib\\" + it.name }
manifest {
attributes 'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Created-By': "${System.getProperty('java.version')} (${System.getProperty('java.vendor')})",
'Built-With': "gradle-${project.gradle.gradleVersion}, groovy-${GroovySystem.version}",
'Built-By': System.getProperty('user.name'),
'Built-On': "${InetAddress.localHost.hostName}/${InetAddress.localHost.hostAddress}",
'Build-Time': buildTime.format('yyyy/MM/dd HH:mm:ss'),
'Class-Path': ClassPathString
}
}
}
}
Besides, there is the settings.gradle to include sub projects
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
resolutionStrategy {
eachPlugin {
if (requested.id.id == 'io.quarkus') {
useModule("io.quarkus:quarkus-gradle-plugin:0.23.1")
}
}
}
}
rootProject.name = 'coffeeshop'
include 'ddd-commons'
include 'inventory-domain'
include 'inventory-application'
include 'inventory-web'
include 'coffee-application'
include 'coffee-domain'
include 'coffee-web'
include 'orders-application'
include 'orders-domain'
include 'orders-web'
I expect these settings could run gradle build well, but faced seems lombok annotation processer not worked issue in gradle runtime.
Because your project.gradle has '-proc:none'

Gradle multi-project does not generate Lombok's goodness

I have a multi-project in Gradle. The build.gradle script looks like:
buildscript {
repositories {
jcenter()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:2.0.4"
classpath "io.franzbecker:gradle-lombok:1.14"
}
}
allprojects {
//apply plugin: "base"
}
subprojects {
apply plugin: "com.github.johnrengelman.plugin-shadow"
apply plugin: "idea"
apply plugin: "java"
apply plugin: "io.franzbecker.gradle-lombok"
group = "io.shido"
version = "0.1.0-SNAPSHOT"
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
repositories {
jcenter()
mavenCentral()
}
dependencies {
// [start] Research
//compileOnly "org.projectlombok:lombok:1.18.2"
// [end] Research
testCompile "nl.jqno.equalsverifier:equalsverifier:2.4.5"
testCompile "org.junit.jupiter:junit-jupiter-api:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
}
//=================================================================================================
// P L U G I N S
//=================================================================================================
lombok {
version = "1.18.2"
}
//=================================================================================================
// T A S K S
//=================================================================================================
// shadowJar { ... }
test {
useJUnitPlatform()
}
}
I have a messages project then with this build.script:
plugins {
id "java-library"
}
repositories {
jcenter()
mavenCentral()
}
...and a core project with this build.script:
plugins {
id "io.spring.dependency-management" version "1.0.6.RELEASE"
}
dependencies {
compile project(":messages")
}
All of that should be OK.
If I write a simple class in messages:
package io.shido.event;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
#Getter
#Builder
#ToString
#EqualsAndHashCode(of = "name")
class Prototype {
private String id;
private String name;
}
...and then a unit test for the same:
package io.shido.event;
import org.junit.jupiter.api.Test;
final class PrototypeTest {
#Test
void instantiate() {
final Prototype event = Prototype.???
}
}
I'm expecting I can use a builder for that class right there, but there is nothing generated.
Am I missing something in the setup? Everything compiles, but I can't see anything being generated for Lombok. Not sure what else to try.
If you are using IDEA and recent version of Gradle (I think >= 4.7) you could use the following setup which is working fine in my different projects:
install Lombok plugin for IDEA , from Settings->Plugins configuration panel.
In your Gradle build script you can get rid of the lombok plugin declaration and lombok block : you just need to add the following dependencies on your project(s).
ext{
lombokVersion = '1.16.20'
junitVersion = '4.12'
}
dependencies {
compileOnly "org.projectlombok:lombok:${lombokVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
// other libs ...
// test dependencies
testCompile group: 'junit', name: 'junit', version: "${junitVersion}"
}
After project re-import, make sure to enable Annotation Processing in IDEA, from Settings -> Build,Execution,Deployment -> Compiler-> AnnotationProcessors menu : there is a checkbox "Enable annotation processing" which is disabled by default.
This should work fine, and you'll be able to use Lombok features in your main code and in unit test as well.

Gradle can't resolve references from another module

I have a project with the following modules:
App
Device
App depends on device. Device contains a NetworkComponent class that app references. More specifically:
package com.some.package.ui.login;
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.some.package.R
import com.some.package.device.network.NetworkComponent
import com.some.package.ui.terms.TermsActivity
class LoginActivity : AppCompatActivity(),
LoginViewModel.Navigator {
val loginViewModel by lazy { LoginViewModel(this, NetworkComponent()) }
Everything resolves fine in Android Studio. Yet when I attempt to build the project, I encounter a build error:
e: /Users/android/some-app-android/app/src/main/kotlin/com/some/package/ui/login/LoginActivity.kt: (7, 27): Unresolved reference: network
e: /Users/android/some-app-android/app/src/main/kotlin/com/some/package/ui/login/LoginActivity.kt: (13, 55): Unresolved reference: NetworkComponent
[KOTLIN] deleting /Users/android/some-app-android/app/build/tmp/kotlin-classes/debug on error
[KOTLIN] deleting /Users/android/some-app-android/app/build/tmp/kotlin-classes/debug on error
:app:compileDebugKotlin FAILED
This is what NetworkComponent looks like:
package com.some.package.device.network
import com.some.package.domain.datasources.CodeValidator
import retrofit2.Retrofit
class NetworkComponent : CodeValidator {
val codeValidator: CodeValidatorApi
init {
val retrofit = Retrofit.Builder()
.baseUrl("www.test.com")
.build()
codeValidator = retrofit.create(CodeValidatorApi::class.java)
}
override fun validate(code: String) = codeValidator.validate(code)
}
Here are the build files:
Top:
buildscript {
ext.kotlin_version = '1.1.51'
ext.android_tools = '3.0.0'
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:$android_tools"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
App:
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
//apply plugin: 'io.fabric'
// Manifest version information
def versionMajor = 0
def versionMinor = 0
def versionPatch = 1
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.some.package"
minSdkVersion 21
targetSdkVersion 27
versionCode versionMajor * 10000 + versionMinor * 100 + versionPatch
versionName "${versionMajor}.${versionMinor}.${versionPatch}"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
// applicationIdSuffix '.debug'
resValue "string", "application_name", "TEST APP Debug"
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
resValue "string", "application_name", "TEST APP"
}
}
dataBinding {
enabled = true
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
debug.java.srcDirs += 'src/debug/kotlin'
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/services/javax.annotation.processing.Processor' // butterknife
}
}
repositories {
maven { url 'https://github.com/uPhyca/stetho-realm/raw/master/maven-repo' }
}
dependencies {
implementation project(':device')
implementation project(':data')
implementation project(':domain')
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:support-v4:27.0.0'
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support:support-annotations:27.0.0'
kapt "com.android.databinding:compiler:$android_tools"
// Logging
implementation 'com.jakewharton.timber:timber:4.5.1'
// Unit tests
testImplementation 'junit:junit:4.12'
// testImplementation 'org.robolectric:robolectric:3.0'
testImplementation 'org.mockito:mockito-core:2.11.0'
// testImplementation 'joda-time:joda-time:2.9.4'
// debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.1'
// releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
// testImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
implementation 'io.reactivex.rxjava2:rxkotlin:2.1.0'
debugImplementation 'com.facebook.stetho:stetho:1.4.1'
debugImplementation 'com.uphyca:stetho_realm:2.0.0'
// implementation('com.crashlytics.sdk.android:crashlytics:2.6.8#aar') {
// transitive = true;
// }
}
Device:
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':domain')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'io.reactivex.rxjava2:rxkotlin:2.1.0'
implementation "com.squareup.retrofit2:retrofit:2.3.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.3.0"
testImplementation 'junit:junit:4.12'
}
I'm not quite sure how this can happen. I tried downgrading the gradle plugin to 2.3.3, but no luck.
Any ideas?
Turns out I was missing this key line in my device module build file:
apply plugin: 'kotlin-android'
Thanks to this answer for the clue https://stackoverflow.com/a/31671696/918585

getVersion() in custom Gradle plugin is always unspecified

Related to
How to Get $project.version in Custom Gradle Plugin?
Executive summary: getVersion() inside of custom gradle plugin returns "unspecified"
I have created a custom gradle plugin that applies some business logic to our Android Studio / Gradle builds. This plugin is run every time we do a CI build.
I want the plugin to be able to print out its version, which is an entirely different version number from that of the Android application being built, during builds. (useful debugging information during CI builds)
The build.gradle for the plugin (that gets deployed to a maven repo as a jar):
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'groovy'
apply plugin: 'maven'
group = 'com.example.foo.gradle'
version = "0.0.12"
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
dependencies {
repositories {
mavenCentral()
}
compile gradleApi()
compile localGroovy()
}
configurations {
includeInJar
}
dependencies {
//testCompile 'junit:junit:4.11'
}
jar {
}
uploadArchives {
repositories.mavenDeployer {
def deployPath = file(getProperty('aar.deployPath'))
repository(url: "file://${deployPath.absolutePath}")
pom.project {
groupId project.group
artifactId 'foo-gradle-jenkins'
version project.version
}
}
}
... and the plugin is applied to an Android app like this (sensitive parts omitted):
buildscript {
repositories {
mavenCentral()
maven { url "../../../plugin_builds" }
}
dependencies {
classpath 'com.example.foo.gradle:foo-gradle-jenkins:0.0.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'foo'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.example.android.examplegradleapplication3"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
In the plugin I attempt to print its version like this:
#Override
void apply(Project project) {
project.configure(project) {
if (it.hasProperty("android")) {
if (isJenkinsBuild()) {
log("Plugin version: " + getVersion())
// ...
}
// ...
}
}
}
.. but whenever I perform gradle build of the Android app it thinks getVersion() is unspecified.
What should I be doing instead to track the plugin version at the time of another gradle build using it as a plugin?
AppExtension android = (AppExtension) project.extensions.findByName("android")
String versionName = android.defaultConfig.versionName
String versionCode = android.defaultConfig.versionCode
project.configure(project) { println getVersion() } is the same as println project.version. If this prints unspecified, the build script didn't set (project.)version.
As of Gradle 2.2, there isn't a built-in way for a plugin to declare or query its own version, but you could implement this yourself (for your own plugins).

Resources