Cannot get property 'kotlinOutputDir' on null object - Kotlin and Spock - android

I am trying to test Kotlin classes with Spock Framework.
When I had only Java classes in my project, everything was working fine. But after adding kotlin in version 1.1.51 to my project, tests stoped working and now I am receiving such error:
Error:Execution failed for task ':app:compileDebugUnitTestGroovyWithGroovyc'.
> Cannot get property 'kotlinOutputDir' on null object
I am using Android Studio 3.0 Beta 7
Here is my project and module build.gradle files:
Project build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta7'
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.2.0'
// 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'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'groovyx.android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.redione.debtscalc"
minSdkVersion 15
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 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:11.4.2'
implementation 'com.google.firebase:firebase-database:11.4.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
testImplementation 'org.mockito:mockito-core:2.10.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'org.codehaus.groovy:groovy:2.4.11:grooid'
testImplementation('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
exclude group: 'junit'
}
}
apply plugin: 'com.google.gms.google-services'
repositories {
mavenCentral()
}

Update
The Groovy Android Gradle Plugin has released v2.0.0, which is compatible with Android Gradle Plugin 3.0.0. Edit your root build.gradle:
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:2.0.0'
The original answer (which should not be used!), I leave for historical purposes.
Original answer
The short answer is that this should be fixed soon, with the Groovy Android Gradle Plugin v2.0.0, which is currently in progress.
The longer answer (with immediate payoff), is that you can workaround this as follows. See my comment on the issue on Github.
The following should be added to app/build.gradle:
// Ugly workaround for incompatibility between Groovy Android Gradle Plugin 1.2.0 and Android Gradle Plugin 3.0.0
// Should be fixed with Groovy Android Gradle Plugin 1.3.0. https://github.com/groovy/groovy-android-gradle-plugin/pull/155
task copyFlavorDebugUnitTestKotlinClasses(type: CopyKotlinClasses)
class CopyKotlinClasses extends DefaultTask {
def kotlinOutputDir = ["$project.rootDir/app/build/tmp/kotlin-classes/flavorDebugUnitTest"]
#TaskAction
def doNothing() {
}
}
Please note, you must replace "flavor" with your project's actual flavor(s), or remove that if you don't use product flavors.

Related

Could not find method implementation() for arguments [com.google.android:support-v4:r7]

I'm a total Android / Java newbie, and came across a project I want to compile below:
https://github.com/maxamillion32/Android-Firebase-mapping
It is a bit old and maybe that's why it's causing me issues.
First error I got about Build Tools 24.0.1, which I downloaded. Now I get the following error which I cannot resolve:
Caused by: org.gradle.internal.metaobject.AbstractDynamicObject$CustomMessageMissingMethodException: Could not find method implementation() for arguments [com.google.android:support-v4:r7] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
I've checked my Dependencies in File>Project Structure and com.google.android:support-v4:r7 is there.
build.gradle (Project)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.3'
classpath 'com.google.gms:google-services:4.3.3'
// 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
}
build.gradle (app)
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.mimming.hacks.starter"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
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:23.4.0'
implementation 'com.google.android.gms:play-services:9.6.1'
testImplementation 'junit:junit:4.12'
// compile 'com.firebase:firebase-client-android:2.5.2+'
apply plugin: 'com.google.gms.google-services'
implementation 'com.google.firebase:firebase-database:9.6.1'
}
Any ideas?
Thank you!
The gradle version used seems to be of lower version, in-order to use implementation gradle version should be above 3
You should replace your dependencies in build.gradle to latest version.
classpath 'com.android.tools.build:gradle:3.6.3'
Also you will have to upgrade the distributionUrl also
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
As you already mentioned you have updated the buildToolsVersion, this should work fine and also make sure all the dependencies are using implementation and not compileas compile is deprecated.

Could not find the AndroidManifest.xml file, using generation folder after Android Annotations

I can't run my project after adding the #EActivity Annotation to my class.
This is my Gradle Project:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// 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
}
This is my Gradle Module:app
apply plugin: 'com.android.application'
def AAVersion = '4.2.0'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.tasks"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:support-annotations:28.0.0'
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation "org.androidannotations:androidannotations-api:$AAVersion"
}
After I added the Android Annotations in my Gradle I noticed that my AndroidMannifest didn't get automatically modified (Missing the _ in the activity), and when I add that manually it gets highlighted in red.
If I run the project normally (Without modifying the AndroidMannifest or changing the class to Annotations) it will run normally.
If I add the annotations and modify the Manifest I'll receive the error:
error: Could not find the AndroidManifest.xml file, using generation
folder
[C:\Users\Asusc\AndroidStudioProjects\Tasks\app\build\generated\source\apt\debug])
Any idea what I might be doing wrong?
In my case, adding this to build.gradle fixed it:
android {
...
defaultConfig {
...
javaCompileOptions {
annotationProcessorOptions {
arguments = ["androidManifestFile": "$projectDir/src/main/AndroidManifest.xml".toString()]
}
}
}
}
You should update to AndroidAnnotations 4.6.0 . This version has Android Gradle Plugin 3.3.+ support.
If you are using AndroidAnnotations 4.6.0 with Android Gradle Plugin 3.5.+, you can downgrade the Android Gradle Plugin version to 3.4.1 to fix.
classpath 'com.android.tools.build:gradle:3.4.1'

Firebase not working Android Studio 3.0.1 [com.android.support:support-core-utils:27.1.0]

I'm trying to sync with Firebase with my project I use the tool from Android Studio --> Firebase and then I do the steps (This is new Project) Image.
Android Studio version 3.0.1
The build.gradle in App folder is:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.eranp.fiberbase"
minSdkVersion 19
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 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-database:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
The build.gradle in Project folder
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
compile "com.android.support:support-core-utils:27.1.0"
// 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 {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
But when I sync the project I have this Error:
Error:(13, 0) Could not find method compile() for arguments
[com.android.support:support-core-utils:27.1.0] on object of type
org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
Please install the Android Support Repository from the Android SDK
Manager.
But this is installed: Image.
I tried for a week to work with Firebase but anything working to sync.
How can I fix this?
thank you for helping!
After you add this:
compile "com.android.support:support-core-utils:27.1.0"
under the dependencies in the app/build.gradle
then you need to change the:
compileSdkVersion 26
to this:
compileSdkVersion 27
also update the firebase version to this:
implementation 'com.google.firebase:firebase-database:11.8.0'
latest version
You're trying to add a compile dependency to your project buildscript, which is not valid. You are only supposed to add classpath dependencies to your buildscript, which effectively act as plugins for your Gradle build.
compile dependencies are to be using your app's build.gradle, which typically lives in the app folder. These are SDK components that you use to build your app.
If you want to use compile "com.android.support:support-core-utils:27.1.0" in your app, move it from the buildscript dependencies to the app dependencies.

Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app and test app differ

Today I started a new project in android studio. Everything went good and there was no error. After Adding the project, I connected the project with Firebase Real-time Database with the help of Firebase assistant tool in android studio.
Then I get this error:
Error:Execution failed for task ':app:preDebugAndroidTestBuild'.
> Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (23.0.0) and test app (25.4.0) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
I see that the error mainly comes from adding this line at the end of my app level build.gradle file. Because when I comment it out, it builds fine.
apply plugin: 'com.google.gms.google-services'
I don't know much about gradle building system. What could be wrong with only connecting to firebase and adding the firebase-database dependencies.
Resources that me need inspection
My app:build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.learning.insanes.chothavandar"
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
// implementation 'com.google.firebase:firebase-database:11.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'
My project:build.gradle :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// 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.1'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Try this:
androidTestCompile ("com.android.support.test.espresso:espresso-core:3.0.1") {
exclude group: 'com.android.support', module: 'support-annotations'
}
Look at this link for better understanding
In your app: build.gradle file in dependencies add the following lines or if already there change it as:
dependencies {
..
implementation 'com.android.support:appcompat-v7:25.4.0'
..
}

Firebase server SDK setup issuse

I am setting up an Android server project for pushing notification using this documentation from Firebase website. At first, I have set up the project at Firebase console and added the JSON file & Google services plugin.
But while syncing the project after adding
compile 'com.google.firebase:firebase-server-sdk:3.0.1', there is the error:
Version: 3.0.1 is lower than the minimum version (9.0.0) required for google-services plugin.
My app build.gradle is-
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "ton.com.serverandroid"
minSdkVersion 15
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'
}
}
}
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:24.2.1'
compile 'com.google.firebase:firebase-server-sdk:3.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
My project build.gradle is
// 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:2.2.0'
classpath 'com.google.gms:google-services:3.0.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
}
I have tried to use google-services version 2.1.0 but it wasn't working either with the error:
Conflict with dependency 'com.google.code.findbugs:jsr305'. Resolved versions for app (1.3.9) and test app (2.0.1) differ.
But I can't go farther in that case.
I answer a similar question today, you can see the correct dependences here enter link description here, this ones are most important to import other dependencies in android client. Then for server sdk you need to add this one in app.gradle:
compile 'com.google.firebase:firebase-server-sdk:[3.0.0,)'
For use FirebaseCloudMessaging you need other one in app.gradle:
compile 'com.google.firebase:firebase-messaging:9.0.0'
Tell us if you wan compile now, greetings!

Categories

Resources