i use android studio 3.0 and some old java class Convert Java to Kotlin. after that Kotlin class cant import in java class! in below you can see my gradle and a picture of my error.
module build.grade
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
in app level build.gradle in normally i use gradle code and in android 3.0 i think we need any thing
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.idehnavazan.beautifierclient"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}
repositories {
mavenCentral()
jcenter()
maven { url 'https://maven.google.com' }
maven { url 'https://jitpack.io' }
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.github.rey5137:material:1.2.2'
compile 'com.android.support:cardview-v7:25.3.1'
}
apply plugin: 'com.google.gms.google-services'
Kotlin code can be easily called from Java. For example, instances of a Kotlin class can be seamlessly created and operated in Java methods. However, there are certain differences between Java and Kotlin that require attention when integrating Kotlin code into Java.
Adding Java source code to an existing Kotlin projectIf you already have the Java classes, you can just copy them to the project directories. You can now consume the Java class from Kotlin or vice versa without any further actions. lets you call it from Kotlin like any other type in Kotlin.
To work with Kotlin files you need to add Kotlin to your project.
buildscript {
ext.kotlinVersion = '1.1.51'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}
Since you're using support library 25.3.1 and Android plugin 3.0.0 your next question will probably be this: style attribute '@android:attr/windowEnterAnimation' not found.
I have added all kotlin classes in separate folder and it work for me! Keep your java classes separate from kotlin. I was having
app:compileDebugJavaWithJavac Kotlin class calling from java: error: cannot find symbol
compile time error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With