I'm trying to add Realm to an Android project, I've added the project level classpath dependency, but putting the
apply plugin: 'realm-android'
line in my module's build.gradle file results in the following build error:
Error:Execution failed for task ':data:compileDebugAndroidTestJavaWithJavac'.
java.lang.NoClassDefFoundError:
org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper
Without that line, the application builds and runs fine, there is no Realm code in it yet.
Project level build.gradle:
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:2.3.0"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module build.gradle:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'realm-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test {
java.srcDirs = ['src/test/kotlin']
}
}
}
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
kapt {
generateStubs = true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':domain')
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.6'
compile 'io.reactivex:rxjava:1.1.6'
compile 'io.reactivex:rxkotlin:0.60.0'
compile 'javax.inject:javax.inject:1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.6.3'
testCompile 'com.nhaarman:mockito-kotlin:1.1.0'
}
To close this question:
The comment #zaki50 wrote worked for me which is:
Adding apply plugin: 'kotlin-kapt' to app/build.gradle.
I added it right after apply plugin: 'kotlin-android'.
This issue is tracked by https://github.com/realm/realm-java/issues/4087
Related
started today with Firebase - it seems pretty easy, but currently I'm doing something completely wrong.
My build error:
Error:Execution failed for task ':app:preDebugBuild'. Android dependency
'com.google.firebase:firebase-core' has different version for the compile
(9.0.0) and runtime (11.2.0) classpath. You should manually set the same version via DependencyResolution```
with apply plugin: 'com.google.gms.google-services' in the base feature's build.gradle
Without this line there are no build errors, but, Firebase stops working (that was pretty predictable :D)
base feature's build.gradle:
apply plugin: 'com.android.feature'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
android {
baseFeature = true
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 26
versionCode 35
versionName "1.1.1"
}
buildTypes {
release {
minifyEnabled false
}
}
}
repositories {
flatDir {
dirs 'libs'
}
mavenCentral()
}
dependencies {
androidTestCompile('com.android.support.test.espresso:espresso- core:2.2.2', {
exclude group: 'com.android.support', module: 'support- annotations'
})
testCompile 'junit:junit:4.12'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:support-v13:$support_version"
compile "com.android.support:recyclerview-v7:$support_version"
compile "com.android.support:design:$support_version"
compile "com.android.support:customtabs:$support_version"
compile "com.android.support:support-vector-drawable:$support_version"
implementation "com.google.firebase:firebase-messaging:$firebase_version"
implementation "com.google.firebase:firebase-database:$firebase_version"
implementation "com.google.firebase:firebase-appindexing:$firebase_version"
implementation "com.google.firebase:firebase-core:$firebase_version"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
and the project's one:
buildscript {
ext.kotlin_version = '1.1.4-3'
ext.firebase_version = '11.2.0'
ext.support_version = '26.0.2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta4'
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
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any help? Thanks a lot!
You should put apply plugin: 'com.google.gms.google-services' at the BOTTOM of your gradle file not the top.
https://developers.google.com/android/guides/google-services-plugin
For Instant Apps should be:
**implementation 'com.google.firebase:firebase-messaging:11.8.0'**
instead of
implementation 'com.google.firebase:firebase-messaging:11.8.0'
I started a new app in Kotlin, but when Android Studio finished to build the new project, etc.. is says that cand download the correct version of Kotlin:
Here is the build gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.4-eap-77'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
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 {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
and the app gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.xxxxxx.xxxxxx"
minSdkVersion 20
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:26.0.1'
implementation 'com.android.support:design:26.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.0'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.0'
}
How can I fix it to allow download the correct version?
To use a EAP version of the kotlin plugin you have to add the repo in the buildscript block
maven {
url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1'
}
Something like:
buildscript {
ext.kotlin_version = '1.1.4-eap-77'
repositories {
google()
jcenter()
maven {
url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1'
}
}
//...
}
Also you should add the same maven repo to repository block to download the kotlin dependencies.
Something like:
repositories {
google()
jcenter()
maven {
url 'https://dl.bintray.com/kotlin/kotlin-eap-1.1'
}
}
You can find more info here.
I'm trying to use Kotlin in a library module without using it in the app module. The app module only uses Java and does not use any Kotlin classes from the library. Gradle won't compile hoever:
Error:(2, 1) A problem occurred evaluating project ':<Library>'.
> Plugin with id 'kotlin-android' not found.
Changes I made to include Kotlin:
{library root} / build.gradle
buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
...
}
allprojects {
repositories {
jcenter()
}
}
{library root} / {library module} / build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
...
dependencies{
...
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
When I add the same to the app module, the project compiles without issue, but I'd like to avoid adding it in the app module because I'd like to use this library in multiple apps without making code changes to those apps
Gradle version used : 3.3
android gradle plugin version: 2.3.3
Edit: #Jushua's answer works, but it still requires to update the project root build.gradle. I was hoping for a solution where only the dependency on the library would have to be added to make the whole thing work.
I am able to do that without any problem.
build.gradle (Project)
buildscript {
ext.kotlin_version = "1.1.4"
repositories {
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:2.3.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
build.gradle (app)
apply plugin: "com.android.application"
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
applicationId "com.example.app"
minSdkVersion 21
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.2", {
exclude group: "com.android.support", module: "support-annotations"
})
compile "com.android.support:appcompat-v7:26.0.1"
testCompile "junit:junit:4.12"
compile project(path: ":library")
}
build.gradle (library)
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
android {
compileSdkVersion 26
buildToolsVersion "26.0.1"
defaultConfig {
minSdkVersion 17
targetSdkVersion 26
versionCode 13
versionName "1.1.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
}
dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
androidTestCompile("com.android.support.test.espresso:espresso-core:2.2.2", {
exclude group: "com.android.support", module: "support-annotations"
})
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "com.android.support:appcompat-v7:26.0.1"
testCompile "junit:junit:4.12"
}
You just need to add in your module build:
buildscript {
// (Optional) ext.kotlin_version = '1.1.4-3'
repositories {
google()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
and you could either declare the kotlin_version variable in that specific build, or declaring it in the project root build file, since the kotlin version could be updated from other modules:
buildscript {
ext.kotlin_version = '1.1.4-3'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta3'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
You can add buildscript section with kotlin plugins only in your library:
buildscript {
ext.kotlin_version = '1.1.4-2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: "kotlin-android"
apply plugin: "kotlin-android-extensions"
And now you can include library to application, without modification of root build.gradle
compile project(path: ":library")
First of all, I've read all other solution posts and So far, none has worked.
and I'm using Android Studio 2.0
Error:
Error:(27, 0) Gradle DSL method not found: 'classpath()'
Possible causes:The project 'Sailu'sFood' may be using a version of Gradle that does not contain the method.
Open Gradle wrapper fileThe build file may be missing a Gradle plugin.
Apply Gradle plugin
here is build.gradle(app) :
apply plugin: 'com.android.application'
android
{
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.kandarp.food"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
apply plugin: 'com.google.gms.google-services'
here is build.gradle(top level) :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
apply plugin: 'project-report'
apply plugin: 'application'
It'd really great if someone could point out what's the mistake
Remove this line from app/build.gradle from the dependencies block.
classpath 'com.google.gms:google-services:2.0.0-alpha6'
Then you have to move the line in the buildscript block (in the top-level file or in the module file):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.google.gms:google-services:2.0.0-alpha6'
}
}
I have a working Android project using Kotlin version 1.0.0-beta-1038 in Android Studio.
I can run it using Kotlin in different parts, it compiles and works in the emulator but when I tried to use ReadWriteProperty it gives this error message:
Unresolved reference: ReadWriteProperty
Class called PreferenceUtils.kt:
build.grade (Module: app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.droidcba.oculto"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'com.squareup.retrofit:retrofit:2.0.0-beta1'
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta1'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'io.reactivex:rxjava:1.0.14'
}
buildscript {
ext.kotlin_version = '1.0.0-beta-1038'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"
}
}
repositories {
mavenCentral()
}
build.grade (Module: myProject)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.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
}
Please let me know if you need more info. Thanks!
Solved! I have to upgrade the Kotlin Plugin
from Android Studio. It started to recognise "ReadWriteProperty".